OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef SHELL_TRACER_H_ | 5 #ifndef SHELL_TRACER_H_ |
6 #define SHELL_TRACER_H_ | 6 #define SHELL_TRACER_H_ |
7 | 7 |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ref_counted_memory.h" | 14 #include "base/memory/ref_counted_memory.h" |
15 #include "mojo/common/data_pipe_drainer.h" | |
16 #include "mojo/common/trace_controller_impl.h" | |
17 #include "services/tracing/tracing.mojom.h" | |
15 | 18 |
16 namespace shell { | 19 namespace shell { |
17 | 20 |
18 // Tracer collects tracing data from base/trace_event and from externally | 21 // Tracer collects tracing data from base/trace_event and from externally |
19 // configured sources, aggregates it into a single stream, and writes it out to | 22 // configured sources, aggregates it into a single stream, and writes it out to |
20 // a file. It should be constructed very early in a process' lifetime before any | 23 // a file. It should be constructed very early in a process' lifetime before any |
21 // initialization that may be interesting to trace has occured and be shut down | 24 // initialization that may be interesting to trace has occured and be shut down |
22 // as late as possible to capture as much initialization/shutdown code as | 25 // as late as possible to capture as much initialization/shutdown code as |
23 // possible. | 26 // possible. |
24 class Tracer { | 27 class Tracer : public mojo::common::DataPipeDrainer::Client { |
25 public: | 28 public: |
26 Tracer(); | 29 Tracer(); |
27 ~Tracer(); | 30 ~Tracer() override; |
28 | 31 |
29 // Starts tracing the current process with the given set of categories. | 32 // Starts tracing the current process with the given set of categories. |
30 void Start(const std::string& categories); | 33 void Start(const std::string& categories); |
31 | 34 |
35 // Starts collecting data from the tracing service with the given set of | |
36 // categories. | |
37 void StartCollectingFromTracingService( | |
38 tracing::TraceCoordinatorPtr coordinator); | |
39 | |
32 // Stops tracing and flushes all collected trace data to the given filename. | 40 // Stops tracing and flushes all collected trace data to the given filename. |
33 // Blocks until the file write is complete. May be called after the message | 41 // Blocks until the file write is complete. May be called after the message |
34 // loop is shut down. | 42 // loop is shut down. |
35 void StopAndFlushToFile(const std::string& filename); | 43 void StopAndFlushToFile(const std::string& filename); |
36 | 44 |
45 void ConnectToController( | |
46 mojo::InterfaceRequest<tracing::TraceController> request); | |
47 | |
37 private: | 48 private: |
38 void StopTracingAndFlushToDisk(const std::string& filename); | 49 void StopTracingAndFlushToDisk(const std::string& filename); |
39 | 50 |
40 // Called from the flush thread. When all data is collected this runs | 51 // Called from the flush thread. When all data is collected this runs |
41 // |done_callback| on the flush thread. | 52 // |done_callback| on the flush thread. |
42 void EndTraceAndFlush(const std::string& filename, | 53 void EndTraceAndFlush(const std::string& filename, |
43 const base::Closure& done_callback); | 54 const base::Closure& done_callback); |
44 | 55 |
45 // Called from the flush thread. | 56 // Called from the flush thread. |
46 void WriteTraceDataCollected( | 57 void WriteTraceDataCollected( |
47 const base::Closure& done_callback, | 58 const base::Closure& done_callback, |
48 const scoped_refptr<base::RefCountedString>& events_str, | 59 const scoped_refptr<base::RefCountedString>& events_str, |
49 bool has_more_events); | 60 bool has_more_events); |
50 | 61 |
51 // Whether we're currently tracing. Main thread only. | 62 // mojo::common::DataPipeDrainer::Client implementation. |
63 void OnDataAvailable(const void* data, size_t num_bytes) override; | |
64 void OnDataComplete() override; | |
65 | |
66 // Emits a comma if needed. | |
67 void WriteCommaIfNeeded(); | |
68 | |
69 // Writes trace file footer and closes out the file. | |
70 void WriteFooterAndClose(); | |
71 | |
72 // Pointer to the tracing service. | |
viettrungluu
2015/04/27 17:04:11
I'm confused by this comment (and/or its placement
jamesr
2015/04/27 23:46:57
Took another crack
| |
73 scoped_ptr<mojo::common::DataPipeDrainer> drainer_; | |
74 tracing::TraceCoordinatorPtr coordinator_; | |
75 | |
76 // Connection from the tracing service to us when the tracing service is | |
77 // active. | |
78 scoped_ptr<mojo::TraceControllerImpl> controller_impl_; | |
79 | |
80 // Whether we're currently tracing. | |
52 bool tracing_; | 81 bool tracing_; |
53 | 82 |
54 // Whether we've written the first chunk. Flush thread only. | 83 // Whether we've written the first chunk. |
55 bool first_chunk_written_; | 84 bool first_chunk_written_; |
56 | 85 |
57 // Trace file, if open. Flush thread only. | 86 // Trace file, if open. |
58 FILE* trace_file_; | 87 FILE* trace_file_; |
88 std::string trace_filename_; | |
59 | 89 |
60 DISALLOW_COPY_AND_ASSIGN(Tracer); | 90 DISALLOW_COPY_AND_ASSIGN(Tracer); |
61 }; | 91 }; |
62 | 92 |
63 } // namespace shell | 93 } // namespace shell |
64 | 94 |
65 #endif // SHELL_TRACER_H_ | 95 #endif // SHELL_TRACER_H_ |
OLD | NEW |