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

Unified Diff: mojo/common/tracing_impl.cc

Issue 769963004: Add tracing service and make the shell+sky_viewer+services talk to it (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 | « mojo/common/tracing_impl.h ('k') | mojo/services/native_viewport/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/common/tracing_impl.cc
diff --git a/mojo/common/tracing_impl.cc b/mojo/common/tracing_impl.cc
index ea912c99851bcfde4ccbbb41cd3ccd7dfc1cea8f..bfafcba1839aa87d35efb3b2eea82e73065e1284 100644
--- a/mojo/common/tracing_impl.cc
+++ b/mojo/common/tracing_impl.cc
@@ -4,68 +4,58 @@
#include "mojo/common/tracing_impl.h"
-#include "base/callback.h"
#include "base/debug/trace_event.h"
-#include "base/files/file_util.h"
+#include "mojo/public/cpp/application/application_connection.h"
+#include "mojo/public/cpp/application/application_impl.h"
namespace mojo {
-namespace {
-static bool g_tracing = false;
-static int g_blocks = 0;
-static FILE* g_trace_file = NULL;
-
-void WriteTraceDataCollected(
- const scoped_refptr<base::RefCountedString>& events_str,
- bool has_more_events) {
- if (g_blocks) {
- fwrite(",", 1, 1, g_trace_file);
- }
- ++g_blocks;
- fwrite(events_str->data().c_str(), 1, events_str->data().length(),
- g_trace_file);
- if (!has_more_events) {
- fwrite("]}", 1, 2, g_trace_file);
- base::CloseFile(g_trace_file);
- g_trace_file = NULL;
- g_blocks = 0;
- }
+// static
+void TracingImpl::Create(ApplicationImpl* app) {
+ new TracingImpl(app);
}
-void StopTracingAndFlushToDisk(base::FilePath::StringType base_name) {
- base::debug::TraceLog::GetInstance()->SetDisabled();
-
- base_name.append(FILE_PATH_LITERAL(".trace"));
- g_trace_file = base::OpenFile(base::FilePath(base_name), "w+");
- static const char start[] = "{\"traceEvents\":[";
- fwrite(start, 1, strlen(start), g_trace_file);
- base::debug::TraceLog::GetInstance()->Flush(
- base::Bind(&WriteTraceDataCollected));
+// static
+void TracingImpl::Create(tracing::TraceDataCollectorPtr ptr) {
+ new TracingImpl(ptr.Pass());
}
+
+TracingImpl::TracingImpl(ApplicationImpl* app) : binding_(this) {
+ ApplicationConnection* connection = app->ConnectToApplication("mojo:tracing");
+ tracing::TraceDataCollectorPtr trace_data_collector_ptr;
+ connection->ConnectToService(&trace_data_collector_ptr);
+ binding_.Bind(trace_data_collector_ptr.PassMessagePipe());
}
-TracingImpl::TracingImpl(InterfaceRequest<Tracing> request,
- base::FilePath::StringType base_name)
- : base_name_(base_name), binding_(this, request.Pass()) {
+TracingImpl::TracingImpl(tracing::TraceDataCollectorPtr ptr)
+ : binding_(this, ptr.PassMessagePipe()) {
}
TracingImpl::~TracingImpl() {
}
-void TracingImpl::Start() {
- if (g_tracing)
- return;
- g_tracing = true;
+void TracingImpl::StartTracing(const String& categories) {
+ std::string categories_str = categories.To<std::string>();
base::debug::TraceLog::GetInstance()->SetEnabled(
- base::debug::CategoryFilter("*"), base::debug::TraceLog::RECORDING_MODE,
+ base::debug::CategoryFilter(categories_str),
+ base::debug::TraceLog::RECORDING_MODE,
base::debug::TraceOptions(base::debug::RECORD_UNTIL_FULL));
}
-void TracingImpl::Stop() {
- if (!g_tracing)
- return;
- g_tracing = false;
- StopTracingAndFlushToDisk(base_name_);
+void TracingImpl::StopTracing() {
+ base::debug::TraceLog::GetInstance()->SetDisabled();
+
+ base::debug::TraceLog::GetInstance()->Flush(
+ base::Bind(&TracingImpl::SendChunk, base::Unretained(this)));
+}
+
+void TracingImpl::SendChunk(
+ const scoped_refptr<base::RefCountedString>& events_str,
+ bool has_more_events) {
+ binding_.client()->DataCollected(mojo::String(events_str->data()));
+ if (!has_more_events) {
+ binding_.client()->EndTracing();
+ }
}
} // namespace mojo
« no previous file with comments | « mojo/common/tracing_impl.h ('k') | mojo/services/native_viewport/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698