| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/debug/trace_event.h" | 5 #include "base/debug/trace_event.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(proc, | 38 process_metrics_.reset(base::ProcessMetrics::CreateProcessMetrics(proc, |
| 39 NULL)); | 39 NULL)); |
| 40 #endif | 40 #endif |
| 41 } | 41 } |
| 42 | 42 |
| 43 TraceLog::~TraceLog() { | 43 TraceLog::~TraceLog() { |
| 44 Stop(); | 44 Stop(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // static | 47 // static |
| 48 TraceLog* TraceLog::GetInstance() { |
| 49 return Singleton<TraceLog, DefaultSingletonTraits<TraceLog> >::get(); |
| 50 } |
| 51 |
| 52 // static |
| 48 bool TraceLog::IsTracing() { | 53 bool TraceLog::IsTracing() { |
| 49 TraceLog* trace = Singleton<TraceLog>::get(); | 54 return TraceLog::GetInstance()->enabled_; |
| 50 return trace->enabled_; | |
| 51 } | 55 } |
| 52 | 56 |
| 53 // static | 57 // static |
| 54 bool TraceLog::StartTracing() { | 58 bool TraceLog::StartTracing() { |
| 55 TraceLog* trace = Singleton<TraceLog>::get(); | 59 return TraceLog::GetInstance()->Start(); |
| 56 return trace->Start(); | |
| 57 } | 60 } |
| 58 | 61 |
| 59 bool TraceLog::Start() { | 62 bool TraceLog::Start() { |
| 60 if (enabled_) | 63 if (enabled_) |
| 61 return true; | 64 return true; |
| 62 enabled_ = OpenLogFile(); | 65 enabled_ = OpenLogFile(); |
| 63 if (enabled_) { | 66 if (enabled_) { |
| 64 Log("var raw_trace_events = [\n"); | 67 Log("var raw_trace_events = [\n"); |
| 65 trace_start_time_ = TimeTicks::Now(); | 68 trace_start_time_ = TimeTicks::Now(); |
| 66 timer_.Start(TimeDelta::FromMilliseconds(250), this, &TraceLog::Heartbeat); | 69 timer_.Start(TimeDelta::FromMilliseconds(250), this, &TraceLog::Heartbeat); |
| 67 } | 70 } |
| 68 return enabled_; | 71 return enabled_; |
| 69 } | 72 } |
| 70 | 73 |
| 71 // static | 74 // static |
| 72 void TraceLog::StopTracing() { | 75 void TraceLog::StopTracing() { |
| 73 TraceLog* trace = Singleton<TraceLog>::get(); | 76 return TraceLog::GetInstance()->Stop(); |
| 74 return trace->Stop(); | |
| 75 } | 77 } |
| 76 | 78 |
| 77 void TraceLog::Stop() { | 79 void TraceLog::Stop() { |
| 78 if (enabled_) { | 80 if (enabled_) { |
| 79 enabled_ = false; | 81 enabled_ = false; |
| 80 Log("];\n"); | 82 Log("];\n"); |
| 81 CloseLogFile(); | 83 CloseLogFile(); |
| 82 timer_.Stop(); | 84 timer_.Stop(); |
| 83 } | 85 } |
| 84 } | 86 } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 } | 159 } |
| 158 | 160 |
| 159 void TraceLog::Log(const std::string& msg) { | 161 void TraceLog::Log(const std::string& msg) { |
| 160 AutoLock lock(file_lock_); | 162 AutoLock lock(file_lock_); |
| 161 | 163 |
| 162 fprintf(log_file_, "%s", msg.c_str()); | 164 fprintf(log_file_, "%s", msg.c_str()); |
| 163 } | 165 } |
| 164 | 166 |
| 165 } // namespace debug | 167 } // namespace debug |
| 166 } // namespace base | 168 } // namespace base |
| OLD | NEW |