• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef BASE_TEST_LAUNCHER_TEST_LAUNCHER_TRACER_H_
6 #define BASE_TEST_LAUNCHER_TEST_LAUNCHER_TRACER_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/synchronization/lock.h"
12 #include "base/threading/platform_thread.h"
13 #include "base/time/time.h"
14 
15 namespace base {
16 
17 class FilePath;
18 
19 // Records traces of test execution, e.g. to analyze performance.
20 // Thread safe.
21 class TestLauncherTracer {
22  public:
23   TestLauncherTracer();
24   ~TestLauncherTracer();
25 
26   // Records an event corresponding to test process execution.
27   void RecordProcessExecution(TimeTicks start_time, TimeDelta duration);
28 
29   // Dumps trace data as JSON. Returns true on success.
30   bool Dump(const FilePath& path) WARN_UNUSED_RESULT;
31 
32  private:
33   // Simplified version of base::TraceEvent.
34   struct Event {
35     std::string name;            // Displayed name.
36     TimeTicks timestamp;         // Timestamp when this event began.
37     TimeDelta duration;          // How long was this event.
38     PlatformThreadId thread_id;  // Thread ID where event was reported.
39   };
40 
41   // Timestamp when tracing started.
42   TimeTicks trace_start_time_;
43 
44   // Log of trace events.
45   std::vector<Event> events_;
46 
47   // Lock to protect all member variables.
48   Lock lock_;
49 
50   DISALLOW_COPY_AND_ASSIGN(TestLauncherTracer);
51 };
52 
53 }  // namespace base
54 
55 #endif  // BASE_TEST_LAUNCHER_TEST_LAUNCHER_TRACER_H_
56