[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / tools / gn / trace.h
blob384907b221eadb44ffaf6d4e42b8bb60fd23e819
1 // Copyright (c) 2013 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.
5 #ifndef TOOLS_GN_TRACE_H_
6 #define TOOLS_GN_TRACE_H_
8 #include <string>
10 #include "base/command_line.h"
11 #include "base/files/file_path.h"
12 #include "base/macros.h"
13 #include "base/threading/platform_thread.h"
14 #include "base/time/time.h"
16 class Label;
18 class TraceItem {
19 public:
20 enum Type {
21 TRACE_SETUP,
22 TRACE_FILE_LOAD,
23 TRACE_FILE_PARSE,
24 TRACE_FILE_EXECUTE,
25 TRACE_FILE_WRITE,
26 TRACE_SCRIPT_EXECUTE,
27 TRACE_DEFINE_TARGET,
28 TRACE_CHECK_HEADER, // One file.
29 TRACE_CHECK_HEADERS, // All files.
32 TraceItem(Type type,
33 const std::string& name,
34 base::PlatformThreadId thread_id);
35 ~TraceItem();
37 Type type() const { return type_; }
38 const std::string& name() const { return name_; }
39 base::PlatformThreadId thread_id() const { return thread_id_; }
41 base::TimeTicks begin() const { return begin_; }
42 void set_begin(base::TimeTicks b) { begin_ = b; }
43 base::TimeTicks end() const { return end_; }
44 void set_end(base::TimeTicks e) { end_ = e; }
46 base::TimeDelta delta() const { return end_ - begin_; }
48 // Optional toolchain label.
49 const std::string& toolchain() const { return toolchain_; }
50 void set_toolchain(const std::string& t) { toolchain_ = t; }
52 // Optional command line.
53 const std::string& cmdline() const { return cmdline_; }
54 void set_cmdline(const std::string& c) { cmdline_ = c; }
56 private:
57 Type type_;
58 std::string name_;
59 base::PlatformThreadId thread_id_;
61 base::TimeTicks begin_;
62 base::TimeTicks end_;
64 std::string toolchain_;
65 std::string cmdline_;
68 class ScopedTrace {
69 public:
70 ScopedTrace(TraceItem::Type t, const std::string& name);
71 ScopedTrace(TraceItem::Type t, const Label& label);
72 ~ScopedTrace();
74 void SetToolchain(const Label& label);
75 void SetCommandLine(const base::CommandLine& cmdline);
77 void Done();
79 private:
80 TraceItem* item_;
81 bool done_;
84 // Call to turn tracing on. It's off by default.
85 void EnableTracing();
87 // Adds a trace event to the log. Takes ownership of the pointer.
88 void AddTrace(TraceItem* item);
90 // Returns a summary of the current traces, or the empty string if tracing is
91 // not enabled.
92 std::string SummarizeTraces();
94 // Saves the current traces to the given filename in JSON format.
95 void SaveTraces(const base::FilePath& file_name);
97 #endif // TOOLS_GN_TRACE_H_