| 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
|
|
|