Chromium Code Reviews| Index: shell/tracer.h |
| diff --git a/shell/tracer.h b/shell/tracer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c20ea8278a0aea0a512a81c3f5849f563ed29c6c |
| --- /dev/null |
| +++ b/shell/tracer.h |
| @@ -0,0 +1,65 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef SHELL_TRACER_H_ |
| +#define SHELL_TRACER_H_ |
| + |
| +#include <stdio.h> |
| + |
| +#include <string> |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ref_counted_memory.h" |
| + |
| +namespace shell { |
|
viettrungluu
2015/04/07 22:05:44
For consistency, could you put this in the mojo::s
jamesr
2015/04/07 22:20:07
:(
ok
|
| + |
| +// Tracer collects tracing data from base/trace_event and from externally |
| +// configured sources, aggregates it into a single stream, and writes it out to |
| +// a file. It should be constructed very early in a process' lifetime before any |
| +// initialization that may be interesting to trace has occured and be shut down |
| +// as late as possible to capture as much initialization/shutdown code as |
| +// possible. |
| +class Tracer { |
| + public: |
| + Tracer(); |
| + ~Tracer(); |
| + |
| + // Starts tracing the current process with the given set of categories. |
| + void Start(std::string categories); |
| + |
| + // Stops tracing and flushes all collected trace data to the given filename. |
| + // Blocks until the file write is complete. May be called after the message |
| + // loop is shut down. |
| + void StopAndFlushToFile(std::string filename); |
|
viettrungluu
2015/04/07 22:05:44
const std::string&?
Maybe also merge StopTracingA
jamesr
2015/04/07 22:20:07
done
|
| + |
| + private: |
| + void StopTracingAndFlushToDisk(const std::string& filename); |
| + |
| + // Called from the flush thread. When all data is collected this runs |
| + // |done_callback| on the flush thread. |
| + void EndTraceAndFlush(const std::string& filename, |
| + const base::Closure& done_callback); |
| + |
| + // Called from the flush thread. |
| + void WriteTraceDataCollected( |
| + const base::Closure& done_callback, |
| + const scoped_refptr<base::RefCountedString>& events_str, |
| + bool has_more_events); |
| + |
| + // Whether we're currently tracing. Main thread only. |
| + bool tracing_; |
| + |
| + // Number of tracing blocks written. Flush thread only. |
| + uint32_t blocks_written_; |
|
viettrungluu
2015/04/07 22:05:44
size_t instead?
jamesr
2015/04/07 22:20:07
actually we just need one bit to tell if we need t
|
| + |
| + // Trace file, if open. Flush thread only. |
| + FILE* trace_file_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(Tracer); |
| +}; |
| + |
| +} // namespace shell |
| + |
| +#endif // SHELL_TRACER_H_ |