OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SHELL_TRACER_H_ |
| 6 #define SHELL_TRACER_H_ |
| 7 |
| 8 #include <stdio.h> |
| 9 |
| 10 #include <string> |
| 11 |
| 12 #include "base/callback.h" |
| 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted_memory.h" |
| 15 |
| 16 namespace mojo { |
| 17 namespace shell { |
| 18 |
| 19 // Tracer collects tracing data from base/trace_event and from externally |
| 20 // configured sources, aggregates it into a single stream, and writes it out to |
| 21 // a file. It should be constructed very early in a process' lifetime before any |
| 22 // initialization that may be interesting to trace has occured and be shut down |
| 23 // as late as possible to capture as much initialization/shutdown code as |
| 24 // possible. |
| 25 class Tracer { |
| 26 public: |
| 27 Tracer(); |
| 28 ~Tracer(); |
| 29 |
| 30 // Starts tracing the current process with the given set of categories. |
| 31 void Start(const std::string& categories); |
| 32 |
| 33 // Stops tracing and flushes all collected trace data to the given filename. |
| 34 // Blocks until the file write is complete. May be called after the message |
| 35 // loop is shut down. |
| 36 void StopAndFlushToFile(const std::string& filename); |
| 37 |
| 38 private: |
| 39 void StopTracingAndFlushToDisk(const std::string& filename); |
| 40 |
| 41 // Called from the flush thread. When all data is collected this runs |
| 42 // |done_callback| on the flush thread. |
| 43 void EndTraceAndFlush(const std::string& filename, |
| 44 const base::Closure& done_callback); |
| 45 |
| 46 // Called from the flush thread. |
| 47 void WriteTraceDataCollected( |
| 48 const base::Closure& done_callback, |
| 49 const scoped_refptr<base::RefCountedString>& events_str, |
| 50 bool has_more_events); |
| 51 |
| 52 // Whether we're currently tracing. Main thread only. |
| 53 bool tracing_; |
| 54 |
| 55 // Whether we've written the first chunk. Flush thread only. |
| 56 bool first_chunk_written_; |
| 57 |
| 58 // Trace file, if open. Flush thread only. |
| 59 FILE* trace_file_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(Tracer); |
| 62 }; |
| 63 |
| 64 } // namespace shell |
| 65 } // namespace mojo |
| 66 |
| 67 #endif // SHELL_TRACER_H_ |
OLD | NEW |