test_launcher_tracer.h 1.5 KB

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