| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/trace_event.h" | 5 #include "base/trace_event.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/platform_thread.h" | 10 #include "base/platform_thread.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 bool TraceLog::StartTracing() { | 44 bool TraceLog::StartTracing() { |
| 45 TraceLog* trace = Singleton<TraceLog>::get(); | 45 TraceLog* trace = Singleton<TraceLog>::get(); |
| 46 return trace->Start(); | 46 return trace->Start(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool TraceLog::Start() { | 49 bool TraceLog::Start() { |
| 50 if (enabled_) | 50 if (enabled_) |
| 51 return true; | 51 return true; |
| 52 enabled_ = OpenLogFile(); | 52 enabled_ = OpenLogFile(); |
| 53 if (enabled_) { | 53 if (enabled_) { |
| 54 Log("var raw_trace_events = [\r\n"); | 54 Log("var raw_trace_events = [\n"); |
| 55 trace_start_time_ = TimeTicks::Now(); | 55 trace_start_time_ = TimeTicks::Now(); |
| 56 timer_.Start(TimeDelta::FromMilliseconds(250), this, &TraceLog::Heartbeat); | 56 timer_.Start(TimeDelta::FromMilliseconds(250), this, &TraceLog::Heartbeat); |
| 57 } | 57 } |
| 58 return enabled_; | 58 return enabled_; |
| 59 } | 59 } |
| 60 | 60 |
| 61 // static | 61 // static |
| 62 void TraceLog::StopTracing() { | 62 void TraceLog::StopTracing() { |
| 63 TraceLog* trace = Singleton<TraceLog>::get(); | 63 TraceLog* trace = Singleton<TraceLog>::get(); |
| 64 return trace->Stop(); | 64 return trace->Stop(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void TraceLog::Stop() { | 67 void TraceLog::Stop() { |
| 68 if (enabled_) { | 68 if (enabled_) { |
| 69 enabled_ = false; | 69 enabled_ = false; |
| 70 Log("];\r\n"); | 70 Log("];\n"); |
| 71 CloseLogFile(); | 71 CloseLogFile(); |
| 72 timer_.Stop(); | 72 timer_.Stop(); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 void TraceLog::Heartbeat() { | 76 void TraceLog::Heartbeat() { |
| 77 std::string cpu = StringPrintf("%d", process_metrics_->GetCPUUsage()); | 77 std::string cpu = StringPrintf("%d", process_metrics_->GetCPUUsage()); |
| 78 TRACE_EVENT_INSTANT("heartbeat.cpu", 0, cpu); | 78 TRACE_EVENT_INSTANT("heartbeat.cpu", 0, cpu); |
| 79 } | 79 } |
| 80 | 80 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 #ifdef USE_UNRELIABLE_NOW | 125 #ifdef USE_UNRELIABLE_NOW |
| 126 TimeTicks tick = TimeTicks::HighResNow(); | 126 TimeTicks tick = TimeTicks::HighResNow(); |
| 127 #else | 127 #else |
| 128 TimeTicks tick = TimeTicks::Now(); | 128 TimeTicks tick = TimeTicks::Now(); |
| 129 #endif | 129 #endif |
| 130 TimeDelta delta = tick - trace_start_time_; | 130 TimeDelta delta = tick - trace_start_time_; |
| 131 int64 usec = delta.InMicroseconds(); | 131 int64 usec = delta.InMicroseconds(); |
| 132 std::string msg = | 132 std::string msg = |
| 133 StringPrintf("{'pid':'0x%lx', 'tid':'0x%lx', 'type':'%s', " | 133 StringPrintf("{'pid':'0x%lx', 'tid':'0x%lx', 'type':'%s', " |
| 134 "'name':'%s', 'id':'0x%lx', 'extra':'%s', 'file':'%s', " | 134 "'name':'%s', 'id':'0x%lx', 'extra':'%s', 'file':'%s', " |
| 135 "'line_number':'%d', 'usec_begin': %I64d},\r\n", | 135 "'line_number':'%d', 'usec_begin': %I64d},\n", |
| 136 base::GetCurrentProcId(), | 136 base::GetCurrentProcId(), |
| 137 PlatformThread::CurrentId(), | 137 PlatformThread::CurrentId(), |
| 138 kEventTypeNames[type], | 138 kEventTypeNames[type], |
| 139 name.c_str(), | 139 name.c_str(), |
| 140 id, | 140 id, |
| 141 extra.c_str(), | 141 extra.c_str(), |
| 142 file, | 142 file, |
| 143 line, | 143 line, |
| 144 usec); | 144 usec); |
| 145 | 145 |
| 146 Log(msg); | 146 Log(msg); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void TraceLog::Log(const std::string& msg) { | 149 void TraceLog::Log(const std::string& msg) { |
| 150 AutoLock lock(file_lock_); | 150 AutoLock lock(file_lock_); |
| 151 | 151 |
| 152 fprintf(log_file_, "%s", msg.c_str()); | 152 fprintf(log_file_, "%s", msg.c_str()); |
| 153 } | 153 } |
| 154 | 154 |
| 155 } // namespace base | 155 } // namespace base |
| OLD | NEW |