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

Unified Diff: content/browser/tracing/tracing_controller_impl.cc

Issue 171143002: Implements Windows system tracing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@tracing
Patch Set: fix android build Created 6 years, 9 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 | « content/browser/tracing/tracing_controller_impl.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/tracing/tracing_controller_impl.cc
diff --git a/content/browser/tracing/tracing_controller_impl.cc b/content/browser/tracing/tracing_controller_impl.cc
index 7523e833cf26cdee9d3843b04668b4ca92474867..dd153403be6538cb641652c3d35743af7639c145 100644
--- a/content/browser/tracing/tracing_controller_impl.cc
+++ b/content/browser/tracing/tracing_controller_impl.cc
@@ -1,7 +1,6 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
+// Copyright (c) 2013 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.
-
#include "content/browser/tracing/tracing_controller_impl.h"
#include "base/bind.h"
@@ -20,6 +19,10 @@
#include "chromeos/dbus/debug_daemon_client.h"
#endif
+#if defined(OS_WIN)
+#include "content/browser/tracing/etw_system_event_consumer_win.h"
+#endif
+
using base::debug::TraceLog;
namespace content {
@@ -101,7 +104,7 @@ void TracingControllerImpl::ResultFile::WriteTask(
if (!file_ || !events_str_ptr->data().size())
return;
- // If there is already a result in the file, then put a commma
+ // If there is already a result in the file, then put a comma
// before the next batch of results.
if (has_at_least_one_result_) {
size_t written = fwrite(",", 1, 1, file_);
@@ -129,9 +132,15 @@ void TracingControllerImpl::ResultFile::CloseTask(
DCHECK(written == 1);
if (system_trace_) {
+#if defined(OS_WIN)
+ // The Windows kernel events are kept into a JSon format stored as string
+ // and must not be escaped.
+ std::string json_string = system_trace_->data();
+#else
std::string json_string = base::GetQuotedJSONString(system_trace_->data());
+#endif
- const char* systemTraceHead = ", \"systemTraceEvents\": ";
+ const char* systemTraceHead = ",\n\"systemTraceEvents\": ";
written = fwrite(systemTraceHead, strlen(systemTraceHead), 1, file_);
DCHECK(written == 1);
@@ -158,7 +167,7 @@ TracingControllerImpl::TracingControllerImpl() :
maximum_trace_buffer_percent_full_(0),
// Tracing may have been enabled by ContentMainRunner if kTraceStartup
// is specified in command line.
-#if defined(OS_CHROMEOS)
+#if defined(OS_CHROMEOS) || defined(OS_WIN)
is_system_tracing_(false),
#endif
is_recording_(TraceLog::GetInstance()->IsEnabled()),
@@ -234,21 +243,27 @@ bool TracingControllerImpl::EnableRecording(
int trace_options = (options & RECORD_CONTINUOUSLY) ?
TraceLog::RECORD_CONTINUOUSLY : TraceLog::RECORD_UNTIL_FULL;
if (options & ENABLE_SAMPLING) {
- trace_options |= TraceLog::ENABLE_SAMPLING;
+ trace_options |= TraceLog::ENABLE_SAMPLING;
}
-#if defined(OS_CHROMEOS)
+
if (options & ENABLE_SYSTRACE) {
+#if defined(OS_CHROMEOS)
DCHECK(!is_system_tracing_);
chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()->
StartSystemTracing();
is_system_tracing_ = true;
- }
+#elif defined(OS_WIN)
+ DCHECK(!is_system_tracing_);
+ is_system_tracing_ =
+ EtwSystemEventConsumer::GetInstance()->StartSystemTracing();
#endif
+ }
+
base::Closure on_enable_recording_done_callback =
base::Bind(&TracingControllerImpl::OnEnableRecordingDone,
base::Unretained(this),
- category_filter,trace_options, callback);
+ category_filter, trace_options, callback);
BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
base::Bind(&TracingControllerImpl::SetEnabledOnFileThread,
base::Unretained(this),
@@ -425,7 +440,7 @@ void TracingControllerImpl::GetMonitoringStatus(
TracingController::Options* out_options) {
*out_enabled = is_monitoring_;
*out_category_filter =
- TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString();
+ TraceLog::GetInstance()->GetCurrentCategoryFilter().ToString();
*out_options = options_;
}
@@ -668,19 +683,33 @@ void TracingControllerImpl::OnDisableRecordingComplete() {
#if defined(OS_CHROMEOS)
if (is_system_tracing_) {
+ // Disable system tracing.
+ is_system_tracing_ = false;
+
// Disable system tracing now that the local trace has shutdown.
// This must be done last because we potentially need to push event
// records into the system event log for synchronizing system event
// timestamps with chrome event timestamps--and since the system event
// log is a ring-buffer (on linux) adding them at the end is the only
// way we're confident we'll have them in the final result.
- is_system_tracing_ = false;
chromeos::DBusThreadManager::Get()->GetDebugDaemonClient()->
RequestStopSystemTracing(
base::Bind(&TracingControllerImpl::OnEndSystemTracingAcked,
base::Unretained(this)));
return;
}
+#elif defined(OS_WIN)
+ if (is_system_tracing_) {
+ // Disable system tracing.
+ is_system_tracing_ = false;
+
+
+ // Stop kernel tracing and flush events.
+ EtwSystemEventConsumer::GetInstance()->StopSystemTracing(
+ base::Bind(&TracingControllerImpl::OnEndSystemTracingAcked,
+ base::Unretained(this)));
+ return;
+ }
#endif
// Trigger callback if one is set.
@@ -707,7 +736,7 @@ void TracingControllerImpl::OnResultFileClosed() {
result_file_.reset();
}
-#if defined(OS_CHROMEOS)
+#if defined(OS_CHROMEOS) || defined(OS_WIN)
void TracingControllerImpl::OnEndSystemTracingAcked(
const scoped_refptr<base::RefCountedString>& events_str_ptr) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
@@ -873,21 +902,18 @@ void TracingControllerImpl::OnWatchEventMatched() {
watch_event_callback_.Run();
}
-void TracingControllerImpl::RegisterTracingUI(TracingUI* tracing_ui)
-{
+void TracingControllerImpl::RegisterTracingUI(TracingUI* tracing_ui) {
DCHECK(tracing_uis_.find(tracing_ui) == tracing_uis_.end());
tracing_uis_.insert(tracing_ui);
}
-void TracingControllerImpl::UnregisterTracingUI(TracingUI* tracing_ui)
-{
+void TracingControllerImpl::UnregisterTracingUI(TracingUI* tracing_ui) {
std::set<TracingUI*>::iterator it = tracing_uis_.find(tracing_ui);
DCHECK(it != tracing_uis_.end());
tracing_uis_.erase(it);
}
-void TracingControllerImpl::OnMonitoringStateChanged(bool is_monitoring)
-{
+void TracingControllerImpl::OnMonitoringStateChanged(bool is_monitoring) {
if (is_monitoring_ == is_monitoring)
return;
« no previous file with comments | « content/browser/tracing/tracing_controller_impl.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698