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_
10 #include "base/basictypes.h"
11 #include "base/command_line.h"
12 #include "base/files/file_path.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/platform_thread.h"
15 #include "base/time/time.h"
29 TRACE_CHECK_HEADER
, // One file.
30 TRACE_CHECK_HEADERS
, // All files.
34 const std::string
& name
,
35 base::PlatformThreadId thread_id
);
38 Type
type() const { return type_
; }
39 const std::string
& name() const { return name_
; }
40 base::PlatformThreadId
thread_id() const { return thread_id_
; }
42 base::TimeTicks
begin() const { return begin_
; }
43 void set_begin(base::TimeTicks b
) { begin_
= b
; }
44 base::TimeTicks
end() const { return end_
; }
45 void set_end(base::TimeTicks e
) { end_
= e
; }
47 base::TimeDelta
delta() const { return end_
- begin_
; }
49 // Optional toolchain label.
50 const std::string
& toolchain() const { return toolchain_
; }
51 void set_toolchain(const std::string
& t
) { toolchain_
= t
; }
53 // Optional command line.
54 const std::string
& cmdline() const { return cmdline_
; }
55 void set_cmdline(const std::string
& c
) { cmdline_
= c
; }
60 base::PlatformThreadId thread_id_
;
62 base::TimeTicks begin_
;
65 std::string toolchain_
;
71 ScopedTrace(TraceItem::Type t
, const std::string
& name
);
72 ScopedTrace(TraceItem::Type t
, const Label
& label
);
75 void SetToolchain(const Label
& label
);
76 void SetCommandLine(const base::CommandLine
& cmdline
);
85 // Call to turn tracing on. It's off by default.
88 // Adds a trace event to the log. Takes ownership of the pointer.
89 void AddTrace(TraceItem
* item
);
91 // Returns a summary of the current traces, or the empty string if tracing is
93 std::string
SummarizeTraces();
95 // Saves the current traces to the given filename in JSON format.
96 void SaveTraces(const base::FilePath
& file_name
);
98 #endif // TOOLS_GN_TRACE_H_