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

Unified Diff: base/test/launcher/test_launcher_tracer.cc

Issue 2112253002: Add basic tracing support to the gtest launcher (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sort Created 4 years, 6 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
« no previous file with comments | « base/test/launcher/test_launcher_tracer.h ('k') | base/test/test_switches.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/test/launcher/test_launcher_tracer.cc
diff --git a/base/test/launcher/test_launcher_tracer.cc b/base/test/launcher/test_launcher_tracer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4ffa8de3ec6aa7543a40b5e84ee1272323033a6a
--- /dev/null
+++ b/base/test/launcher/test_launcher_tracer.cc
@@ -0,0 +1,53 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/test/launcher/test_launcher_tracer.h"
+
+#include "base/json/json_file_value_serializer.h"
+#include "base/strings/stringprintf.h"
+#include "base/values.h"
+
+namespace base {
+
+TestLauncherTracer::TestLauncherTracer()
+ : trace_start_time_(TimeTicks::Now()) {}
+
+TestLauncherTracer::~TestLauncherTracer() {}
+
+void TestLauncherTracer::RecordProcessExecution(TimeTicks start_time,
+ TimeDelta duration) {
+ AutoLock lock(lock_);
+
+ Event event;
+ event.name = StringPrintf("process #%zu", events_.size());
+ event.timestamp = start_time;
+ event.duration = duration;
+ event.thread_id = PlatformThread::CurrentId();
+ events_.push_back(event);
+}
+
+bool TestLauncherTracer::Dump(const FilePath& path) {
+ AutoLock lock(lock_);
+
+ std::unique_ptr<ListValue> json_events(new ListValue);
+ for (const Event& event : events_) {
+ std::unique_ptr<DictionaryValue> json_event(new DictionaryValue);
+ json_event->SetString("name", event.name);
+ json_event->SetString("ph", "X");
+ json_event->SetInteger(
+ "ts", (event.timestamp - trace_start_time_).InMicroseconds());
+ json_event->SetInteger("dur", event.duration.InMicroseconds());
+ json_event->SetInteger("tid", event.thread_id);
+
+ // Add fake values required by the trace viewer.
+ json_event->SetInteger("pid", 0);
+
+ json_events->Append(std::move(json_event));
+ }
+
+ JSONFileValueSerializer serializer(path);
+ return serializer.Serialize(*json_events);
+}
+
+} // namespace base
« no previous file with comments | « base/test/launcher/test_launcher_tracer.h ('k') | base/test/test_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698