Fixed and refactored profiler options handling

- extracted profiler options in a separate class
- switched from system property reading to command line arguments
- added profile based compilation options to CompilerOptions
- removed no longer used kProfile compilation filter
- optimize dex files only if the profiler is enabled
- clean up unused arguments

Bug: 12877748
Bug: 15275634
Change-Id: I37ff68e7694370950ce8db2360562e9058ecebb7
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 361070c..526d8f7 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -123,12 +123,7 @@
       abort_(nullptr),
       stats_enabled_(false),
       running_on_valgrind_(RUNNING_ON_VALGRIND > 0),
-      profile_(false),
-      profile_period_s_(0),
-      profile_duration_s_(0),
-      profile_interval_us_(0),
-      profile_backoff_coefficient_(0),
-      profile_start_immediately_(true),
+      profiler_started_(false),
       method_trace_(false),
       method_trace_file_size_(0),
       instrumentation_(),
@@ -165,7 +160,7 @@
     shutting_down_ = true;
   }
   // Shut down background profiler before the runtime exits.
-  if (profile_) {
+  if (profiler_started_) {
     BackgroundMethodSamplingProfiler::Shutdown();
   }
 
@@ -415,17 +410,16 @@
   }
 
   VLOG(startup) << "Runtime::Start exiting";
-
   finished_starting_ = true;
 
-  if (profile_) {
-    // User has asked for a profile using -Xprofile
+  if (profiler_options_.IsEnabled() && !profile_output_filename_.empty()) {
+    // User has asked for a profile using -Xenable-profiler.
     // Create the profile file if it doesn't exist.
     int fd = open(profile_output_filename_.c_str(), O_RDWR|O_CREAT|O_EXCL, 0660);
     if (fd >= 0) {
       close(fd);
     }
-    StartProfiler(profile_output_filename_.c_str(), "");
+    StartProfiler(profile_output_filename_.c_str());
   }
 
   return true;
@@ -663,15 +657,9 @@
   method_trace_file_ = options->method_trace_file_;
   method_trace_file_size_ = options->method_trace_file_size_;
 
-  // Extract the profile options.
-  // TODO: move into a Trace options struct?
-  profile_period_s_ = options->profile_period_s_;
-  profile_duration_s_ = options->profile_duration_s_;
-  profile_interval_us_ = options->profile_interval_us_;
-  profile_backoff_coefficient_ = options->profile_backoff_coefficient_;
-  profile_start_immediately_ = options->profile_start_immediately_;
-  profile_ = options->profile_;
   profile_output_filename_ = options->profile_output_filename_;
+  profiler_options_ = options->profiler_options_;
+
   // TODO: move this to just be an Trace::Start argument
   Trace::SetDefaultClockSource(options->profile_clock_source_);
 
@@ -1124,9 +1112,10 @@
   method_verifiers_.erase(it);
 }
 
-void Runtime::StartProfiler(const char* appDir, const char* procName) {
-  BackgroundMethodSamplingProfiler::Start(profile_period_s_, profile_duration_s_, appDir,
-      procName, profile_interval_us_, profile_backoff_coefficient_, profile_start_immediately_);
+void Runtime::StartProfiler(const char* profile_output_filename) {
+  profile_output_filename_ = profile_output_filename;
+  profiler_started_ =
+    BackgroundMethodSamplingProfiler::Start(profile_output_filename_, profiler_options_);
 }
 
 // Transaction support.