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 shell { |
| 17 |
| 18 // 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 |
| 20 // 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 |
| 22 // as late as possible to capture as much initialization/shutdown code as |
| 23 // possible. |
| 24 class Tracer { |
| 25 public: |
| 26 Tracer(); |
| 27 ~Tracer(); |
| 28 |
| 29 // Starts tracing the current process with the given set of categories. |
| 30 void Start(const std::string& categories); |
| 31 |
| 32 // 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 |
| 34 // loop is shut down. |
| 35 void StopAndFlushToFile(const std::string& filename); |
| 36 |
| 37 private: |
| 38 void StopTracingAndFlushToDisk(const std::string& filename); |
| 39 |
| 40 // Called from the flush thread. When all data is collected this runs |
| 41 // |done_callback| on the flush thread. |
| 42 void EndTraceAndFlush(const std::string& filename, |
| 43 const base::Closure& done_callback); |
| 44 |
| 45 // Called from the flush thread. |
| 46 void WriteTraceDataCollected( |
| 47 const base::Closure& done_callback, |
| 48 const scoped_refptr<base::RefCountedString>& events_str, |
| 49 bool has_more_events); |
| 50 |
| 51 // Whether we're currently tracing. Main thread only. |
| 52 bool tracing_; |
| 53 |
| 54 // Whether we've written the first chunk. Flush thread only. |
| 55 bool first_chunk_written_; |
| 56 |
| 57 // Trace file, if open. Flush thread only. |
| 58 FILE* trace_file_; |
| 59 |
| 60 DISALLOW_COPY_AND_ASSIGN(Tracer); |
| 61 }; |
| 62 |
| 63 } // namespace shell |
| 64 |
| 65 #endif // SHELL_TRACER_H_ |
OLD | NEW |