diff options
author | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-18 20:42:55 +0000 |
---|---|---|
committer | erikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-18 20:42:55 +0000 |
commit | 113ab13f317a212284c022771438705c6cba6227 (patch) | |
tree | 7c92495aa899a2cdf20be7819ef69b3d06a42533 /base/trace_event.cc | |
parent | 37cbdcc9964ad7b3af8a5420fdbaebe67d11a60c (diff) | |
download | chromium_src-113ab13f317a212284c022771438705c6cba6227.zip chromium_src-113ab13f317a212284c022771438705c6cba6227.tar.gz chromium_src-113ab13f317a212284c022771438705c6cba6227.tar.bz2 |
* Change output of trace_event log to JSON to enable easier integration with visualization UI.
* Simple (manual) trace visualizer with some sample data.
* a few more trace events
* add process_util function for current process handle
Review URL: http://codereview.chromium.org/3086
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2381 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/trace_event.cc')
-rw-r--r-- | base/trace_event.cc | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/base/trace_event.cc b/base/trace_event.cc index 3225830..4ed41d5 100644 --- a/base/trace_event.cc +++ b/base/trace_event.cc @@ -24,6 +24,8 @@ static const char* kEventTypeNames[] = { static const wchar_t* kLogFileName = L"trace_%d.log"; TraceLog::TraceLog() : enabled_(false), log_file_(NULL) { + ProcessHandle proc = process_util::GetCurrentProcessHandle(); + process_metrics_.reset(process_util::ProcessMetrics::CreateProcessMetrics(proc)); } TraceLog::~TraceLog() { @@ -46,8 +48,11 @@ bool TraceLog::Start() { if (enabled_) return true; enabled_ = OpenLogFile(); - if (enabled_) + if (enabled_) { + Log("var raw_trace_events = [\r\n"); trace_start_time_ = TimeTicks::Now(); + timer_.Start(TimeDelta::FromMilliseconds(250), this, &TraceLog::Heartbeat); + } return enabled_; } @@ -60,10 +65,17 @@ void TraceLog::StopTracing() { void TraceLog::Stop() { if (enabled_) { enabled_ = false; + Log("];\r\n"); CloseLogFile(); + timer_.Stop(); } } +void TraceLog::Heartbeat() { + std::string cpu = StringPrintf("%d", process_metrics_->GetCPUUsage()); + TRACE_EVENT_INSTANT("heartbeat.cpu", 0, cpu); +} + void TraceLog::CloseLogFile() { if (log_file_) { #if defined(OS_WIN) @@ -105,7 +117,7 @@ bool TraceLog::OpenLogFile() { void TraceLog::Trace(const std::string& name, EventType type, - void* id, + const void* id, const std::wstring& extra, const char* file, int line) { @@ -116,7 +128,7 @@ void TraceLog::Trace(const std::string& name, void TraceLog::Trace(const std::string& name, EventType type, - void* id, + const void* id, const std::string& extra, const char* file, int line) { @@ -131,8 +143,9 @@ void TraceLog::Trace(const std::string& name, TimeDelta delta = tick - trace_start_time_; int64 usec = delta.InMicroseconds(); std::string msg = - StringPrintf("%I64d 0x%lx:0x%lx %s %s [0x%lx %s] <%s:%d>\r\n", - usec, + StringPrintf("{'pid':'0x%lx', 'tid':'0x%lx', 'type':'%s', " + "'name':'%s', 'id':'0x%lx', 'extra':'%s', 'file':'%s', " + "'line_number':'%d', 'usec_begin': %I64d},\r\n", process_util::GetCurrentProcId(), PlatformThread::CurrentId(), kEventTypeNames[type], @@ -140,7 +153,8 @@ void TraceLog::Trace(const std::string& name, id, extra.c_str(), file, - line); + line, + usec); Log(msg); } |