Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(644)

Unified Diff: shell/tracer.h

Issue 1067023003: Add shell::Tracer object and wire up to --trace-startup on Android (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « shell/desktop/main.cc ('k') | shell/tracer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: shell/tracer.h
diff --git a/shell/tracer.h b/shell/tracer.h
new file mode 100644
index 0000000000000000000000000000000000000000..4af166bd2e8a3a419996e429e7b25b7b820ed3d7
--- /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 {
+
+// 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(const 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(const std::string& filename);
+
+ 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_;
+
+ // Whether we've written the first chunk. Flush thread only.
+ bool first_chunk_written_;
+
+ // Trace file, if open. Flush thread only.
+ FILE* trace_file_;
+
+ DISALLOW_COPY_AND_ASSIGN(Tracer);
+};
+
+} // namespace shell
+
+#endif // SHELL_TRACER_H_
« no previous file with comments | « shell/desktop/main.cc ('k') | shell/tracer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698