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

Side by Side 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, 5 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/test/launcher/test_launcher_tracer.h"
6
7 #include "base/json/json_file_value_serializer.h"
8 #include "base/strings/stringprintf.h"
9 #include "base/values.h"
10
11 namespace base {
12
13 TestLauncherTracer::TestLauncherTracer()
14 : trace_start_time_(TimeTicks::Now()) {}
15
16 TestLauncherTracer::~TestLauncherTracer() {}
17
18 void TestLauncherTracer::RecordProcessExecution(TimeTicks start_time,
19 TimeDelta duration) {
20 AutoLock lock(lock_);
21
22 Event event;
23 event.name = StringPrintf("process #%zu", events_.size());
24 event.timestamp = start_time;
25 event.duration = duration;
26 event.thread_id = PlatformThread::CurrentId();
27 events_.push_back(event);
28 }
29
30 bool TestLauncherTracer::Dump(const FilePath& path) {
31 AutoLock lock(lock_);
32
33 std::unique_ptr<ListValue> json_events(new ListValue);
34 for (const Event& event : events_) {
35 std::unique_ptr<DictionaryValue> json_event(new DictionaryValue);
36 json_event->SetString("name", event.name);
37 json_event->SetString("ph", "X");
38 json_event->SetInteger(
39 "ts", (event.timestamp - trace_start_time_).InMicroseconds());
40 json_event->SetInteger("dur", event.duration.InMicroseconds());
41 json_event->SetInteger("tid", event.thread_id);
42
43 // Add fake values required by the trace viewer.
44 json_event->SetInteger("pid", 0);
45
46 json_events->Append(std::move(json_event));
47 }
48
49 JSONFileValueSerializer serializer(path);
50 return serializer.Serialize(*json_events);
51 }
52
53 } // namespace base
OLDNEW
« 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