Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2484)

Unified Diff: base/trace_event.cc

Issue 3086: * Change output of trace_event log to JSON to enable easier integration with ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/trace_event.cc
===================================================================
--- base/trace_event.cc (revision 2262)
+++ base/trace_event.cc (working copy)
@@ -24,6 +24,8 @@
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 @@
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::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 @@
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,
EventType type,
- void* id,
+ const void* id,
const std::string& extra,
const char* file,
int line) {
@@ -131,8 +143,9 @@
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 @@
id,
extra.c_str(),
file,
- line);
+ line,
+ usec);
Log(msg);
}
« no previous file with comments | « base/trace_event.h ('k') | net/base/tcp_client_socket.cc » ('j') | tools/trace/trace_data.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698