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

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: trybots 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
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() : trace_start_time_(TimeTicks::Now()) {
14 }
15
16 TestLauncherTracer::~TestLauncherTracer() {
17 }
18
19 void TestLauncherTracer::RecordProcessExecution(
20 TimeTicks start_time, TimeDelta duration) {
21 AutoLock lock(lock_);
22
23 Event event;
24 event.name = StringPrintf("process #%zu", events_.size());
25 event.timestamp = start_time;
26 event.duration = duration;
27 event.thread_id = PlatformThread::CurrentId();
Primiano Tucci (use gerrit) 2016/07/01 11:34:30 Not sure you want this, as opposite as passing a h
Paweł Hajdan Jr. 2016/07/01 12:47:32 Yup, that's actually what I want. When I didn't us
28 events_.push_back(event);
Primiano Tucci (use gerrit) 2016/07/01 11:34:30 It's not goting to make any major difference but t
Paweł Hajdan Jr. 2016/07/01 12:47:32 Well, events_ is read above to compute event name.
29 }
30
31 bool TestLauncherTracer::Dump(const FilePath& path) {
32 AutoLock lock(lock_);
33
34 std::unique_ptr<ListValue> json_events(new ListValue);
Primiano Tucci (use gerrit) 2016/07/01 11:34:30 does this import in TraceViewer? I thought you hav
Paweł Hajdan Jr. 2016/07/01 12:47:32 Yeah, there's a format which takes just a list. It
35 for (const Event& event : events_) {
36 std::unique_ptr<DictionaryValue> json_event(new DictionaryValue);
37 json_event->SetString("name", event.name);
38 json_event->SetString("ph", "X");
39 json_event->SetInteger(
40 "ts", (event.timestamp - trace_start_time_).InMicroseconds());
41 json_event->SetInteger("dur", event.duration.InMicroseconds());
42 json_event->SetInteger("tid", event.thread_id);
43
44 // Add fake values required by the trace viewer.
45 json_event->SetInteger("pid", 0);
46
47 json_events->Append(std::move(json_event));
48 }
49
50 JSONFileValueSerializer serializer(path);
51 return serializer.Serialize(*json_events);
52 }
53
54 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698