Changed tracer to use an instance to hold state instead of statics.

Change-Id: I2fdcf5de7fbc745273b1a33cb409d13e72d24ab4
diff --git a/src/trace.h b/src/trace.h
index 9637163..85d328c 100644
--- a/src/trace.h
+++ b/src/trace.h
@@ -11,6 +11,7 @@
 #include "file.h"
 #include "globals.h"
 #include "macros.h"
+#include "UniquePtr.h"
 
 namespace art {
 
@@ -38,50 +39,57 @@
   static void Start(const char* trace_filename, int trace_fd, int buffer_size, int flags, bool direct_to_ddms);
   static void Stop();
 
-  static void LogMethodTraceEvent(Thread* self, const Method* method, TraceEvent event);
+  void LogMethodTraceEvent(Thread* self, const Method* method, TraceEvent event);
 
-  static bool IsMethodTracingActive();
-  static void SetMethodTracingActive(bool value);
+  void AddSavedCodeToMap(const Method* method, const void* code);
+  void RemoveSavedCodeFromMap(const Method* method);
+  const void* GetSavedCodeFromMap(const Method* method);
 
-  static void AddSavedCodeToMap(const Method* method, const void* code);
-  static void RemoveSavedCodeFromMap(const Method* method);
-  static const void* GetSavedCodeFromMap(const Method* method);
-
-  static void SaveAndUpdateCode(Method* method, const void* new_code);
-  static void ResetSavedCode(Method* method);
+  void SaveAndUpdateCode(Method* method, const void* new_code);
+  void ResetSavedCode(Method* method);
 
  private:
+  explicit Trace(File* trace_file, int buffer_size)
+      : trace_file_(trace_file), buf_(new uint8_t[buffer_size]()), overflow_(false), buffer_size_(buffer_size),
+        start_time_(0), trace_version_(0), record_size_(0), cur_offset_(0) {
+  }
+
+  void BeginTracing();
+  void FinishTracing();
+
   // Replaces code of each method with a pointer to a stub for method tracing.
-  static void InstallStubs();
+  void InstallStubs();
 
   // Restores original code for each method and fixes the return values of each thread's stack.
-  static void UninstallStubs();
+  void UninstallStubs();
 
   // Methods to output traced methods and threads.
-  static void GetVisitedMethods(size_t end_offset);
-  static void DumpMethodList(std::ostream& os);
-  static void DumpThreadList(std::ostream& os);
+  void GetVisitedMethods(size_t end_offset);
+  void DumpMethodList(std::ostream& os);
+  void DumpThreadList(std::ostream& os);
 
-  static bool method_tracing_active_;
+  // Maps a method to its original code pointer.
+  std::map<const Method*, const void*> saved_code_map_;
 
-  // Maps a method to its original code pointer
-  static std::map<const Method*, const void*> saved_code_map_;
+  // Set of methods visited by the profiler.
+  std::set<const Method*> visited_methods_;
 
-  // Set of methods visited by the profiler
-  static std::set<const Method*> visited_methods_;
+  // Maps a thread to its clock base.
+  std::map<Thread*, uint64_t> thread_clock_base_map_;
 
-  // Maps a thread to its clock base
-  static std::map<Thread*, uint64_t> thread_clock_base_map_;
+  // File to write trace data out to, NULL if direct to ddms.
+  UniquePtr<File> trace_file_;
 
-  static uint8_t* buf_;
-  static File* trace_file_;
-  static bool direct_to_ddms_;
-  static int buffer_size_;
-  static uint64_t start_time_;
-  static bool overflow_;
-  static uint16_t trace_version_;
-  static uint16_t record_size_;
-  static volatile int32_t cur_offset_;
+  // Buffer to store trace data.
+  UniquePtr<uint8_t> buf_;
+
+  bool overflow_;
+  int buffer_size_;
+  uint64_t start_time_;
+  uint16_t trace_version_;
+  uint16_t record_size_;
+
+  volatile int32_t cur_offset_;
 
   DISALLOW_COPY_AND_ASSIGN(Trace);
 };