diff options
author | kaiwang@chromium.org <kaiwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-28 01:14:23 +0000 |
---|---|---|
committer | kaiwang@chromium.org <kaiwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-28 01:14:23 +0000 |
commit | a32c34b9dd7bcf91f5911768e4d601e0546f0d68 (patch) | |
tree | 48678be23971c5c86c6f676cca667f6a2e56bbee /components | |
parent | ae2b0be000892f2c86aeb5a5aedb0ff4eb2d2063 (diff) | |
download | chromium_src-a32c34b9dd7bcf91f5911768e4d601e0546f0d68.zip chromium_src-a32c34b9dd7bcf91f5911768e4d601e0546f0d68.tar.gz chromium_src-a32c34b9dd7bcf91f5911768e4d601e0546f0d68.tar.bz2 |
Move tracing component to src/components
BUG=167317
COLLABORATOR=joi@chromium.org
Review URL: https://chromiumcodereview.appspot.com/11624021
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174716 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r-- | components/OWNERS | 3 | ||||
-rw-r--r-- | components/components_tracing.gyp | 27 | ||||
-rw-r--r-- | components/components_tracing_untrusted.gyp | 41 | ||||
-rw-r--r-- | components/tracing/DEPS | 8 | ||||
-rw-r--r-- | components/tracing/OWNERS | 2 | ||||
-rw-r--r-- | components/tracing/child_trace_message_filter.cc | 117 | ||||
-rw-r--r-- | components/tracing/child_trace_message_filter.h | 53 | ||||
-rw-r--r-- | components/tracing/tracing_messages.cc | 34 | ||||
-rw-r--r-- | components/tracing/tracing_messages.h | 56 |
9 files changed, 341 insertions, 0 deletions
diff --git a/components/OWNERS b/components/OWNERS index 4975363..4cc56a9 100644 --- a/components/OWNERS +++ b/components/OWNERS @@ -1 +1,4 @@ joi@chromium.org + +per-file components_tracing*=jbauman@chromium.org +per-file components_tracing*=nduca@chromium.org diff --git a/components/components_tracing.gyp b/components/components_tracing.gyp new file mode 100644 index 0000000..f11c823 --- /dev/null +++ b/components/components_tracing.gyp @@ -0,0 +1,27 @@ +# Copyright (c) 2012 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. + +{ + 'targets' : [ + { + 'target_name': 'tracing', + 'type': 'static_library', + 'defines!': ['CONTENT_IMPLEMENTATION'], + 'dependencies': [ + '../base/base.gyp:base', + '../ipc/ipc.gyp:ipc', + ], + 'include_dirs': [ + '..', + ], + 'sources': [ + 'tracing/child_trace_message_filter.cc', + 'tracing/child_trace_message_filter.h', + 'tracing/tracing_messages.cc', + 'tracing/tracing_messages.h', + ], + }, + ], +} diff --git a/components/components_tracing_untrusted.gyp b/components/components_tracing_untrusted.gyp new file mode 100644 index 0000000..ff3e720 --- /dev/null +++ b/components/components_tracing_untrusted.gyp @@ -0,0 +1,41 @@ +# Copyright (c) 2012 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. + +{ + 'includes': [ + '../build/common_untrusted.gypi', + ], + 'conditions': [ + ['disable_nacl==0 and disable_nacl_untrusted==0', { + 'targets': [ + { + 'target_name': 'tracing_untrusted', + 'type': 'none', + 'defines!': ['CONTENT_IMPLEMENTATION'], + 'dependencies': [ + '../base/base_untrusted.gyp:base_untrusted', + '../native_client/tools.gyp:prep_toolchain', + '../ipc/ipc.gyp:ipc', + ], + 'include_dirs': [ + '..', + ], + 'variables': { + 'nacl_untrusted_build': 1, + 'nlib_target': 'libtracing_untrusted.a', + 'build_glibc': 0, + 'build_newlib': 1, + }, + 'sources': [ + 'tracing/child_trace_message_filter.cc', + 'tracing/child_trace_message_filter.h', + 'tracing/tracing_messages.cc', + 'tracing/tracing_messages.h', + ], + }, + ], + }], + ], +} diff --git a/components/tracing/DEPS b/components/tracing/DEPS new file mode 100644 index 0000000..bd05a3e --- /dev/null +++ b/components/tracing/DEPS @@ -0,0 +1,8 @@ +include_rules = [ + "+base", + "+ipc", + + # This component will be compiled into NaCl, so it shouldn't depend on + # anything in content. + "-content", +] diff --git a/components/tracing/OWNERS b/components/tracing/OWNERS new file mode 100644 index 0000000..ba7dc1b --- /dev/null +++ b/components/tracing/OWNERS @@ -0,0 +1,2 @@ +jbauman@chromium.org +nduca@chromium.org diff --git a/components/tracing/child_trace_message_filter.cc b/components/tracing/child_trace_message_filter.cc new file mode 100644 index 0000000..161c778 --- /dev/null +++ b/components/tracing/child_trace_message_filter.cc @@ -0,0 +1,117 @@ +// Copyright (c) 2012 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 "components/tracing/child_trace_message_filter.h" + +#include "base/debug/trace_event.h" +#include "base/message_loop_proxy.h" +#include "components/tracing/tracing_messages.h" + +using base::debug::TraceLog; + +namespace components { + +ChildTraceMessageFilter::ChildTraceMessageFilter( + base::MessageLoopProxy* ipc_message_loop) + : channel_(NULL), + ipc_message_loop_(ipc_message_loop) {} + +void ChildTraceMessageFilter::OnFilterAdded(IPC::Channel* channel) { + channel_ = channel; + TraceLog::GetInstance()->SetNotificationCallback( + base::Bind(&ChildTraceMessageFilter::OnTraceNotification, this)); + channel_->Send(new TracingHostMsg_ChildSupportsTracing()); +} + +void ChildTraceMessageFilter::OnFilterRemoved() { + TraceLog::GetInstance()->SetNotificationCallback( + TraceLog::NotificationCallback()); +} + +bool ChildTraceMessageFilter::OnMessageReceived(const IPC::Message& message) { + bool handled = true; + IPC_BEGIN_MESSAGE_MAP(ChildTraceMessageFilter, message) + IPC_MESSAGE_HANDLER(TracingMsg_BeginTracing, OnBeginTracing) + IPC_MESSAGE_HANDLER(TracingMsg_EndTracing, OnEndTracing) + IPC_MESSAGE_HANDLER(TracingMsg_GetTraceBufferPercentFull, + OnGetTraceBufferPercentFull) + IPC_MESSAGE_HANDLER(TracingMsg_SetWatchEvent, OnSetWatchEvent) + IPC_MESSAGE_HANDLER(TracingMsg_CancelWatchEvent, OnCancelWatchEvent) + IPC_MESSAGE_UNHANDLED(handled = false) + IPC_END_MESSAGE_MAP() + return handled; +} + +ChildTraceMessageFilter::~ChildTraceMessageFilter() {} + +void ChildTraceMessageFilter::OnBeginTracing( + const std::vector<std::string>& included_categories, + const std::vector<std::string>& excluded_categories, + base::TimeTicks browser_time) { +#if defined(__native_client__) + // NaCl and system times are offset by a bit, so subtract some time from + // the captured timestamps. The value might be off by a bit due to messaging + // latency. + base::TimeDelta time_offset = base::TimeTicks::NowFromSystemTraceTime() - + browser_time; + TraceLog::GetInstance()->SetTimeOffset(time_offset); +#endif + TraceLog::GetInstance()->SetEnabled(included_categories, + excluded_categories); +} + +void ChildTraceMessageFilter::OnEndTracing() { + TraceLog::GetInstance()->SetDisabled(); + + // Flush will generate one or more callbacks to OnTraceDataCollected. It's + // important that the last OnTraceDataCollected gets called before + // EndTracingAck below. We are already on the IO thread, so the + // OnTraceDataCollected calls will not be deferred. + TraceLog::GetInstance()->Flush( + base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this)); + + std::vector<std::string> categories; + TraceLog::GetInstance()->GetKnownCategories(&categories); + channel_->Send(new TracingHostMsg_EndTracingAck(categories)); +} + +void ChildTraceMessageFilter::OnGetTraceBufferPercentFull() { + float bpf = TraceLog::GetInstance()->GetBufferPercentFull(); + + channel_->Send(new TracingHostMsg_TraceBufferPercentFullReply(bpf)); +} + +void ChildTraceMessageFilter::OnSetWatchEvent(const std::string& category_name, + const std::string& event_name) { + TraceLog::GetInstance()->SetWatchEvent(category_name.c_str(), + event_name.c_str()); +} + +void ChildTraceMessageFilter::OnCancelWatchEvent() { + TraceLog::GetInstance()->CancelWatchEvent(); +} + +void ChildTraceMessageFilter::OnTraceDataCollected( + const scoped_refptr<base::RefCountedString>& events_str_ptr) { + if (!ipc_message_loop_->BelongsToCurrentThread()) { + ipc_message_loop_->PostTask(FROM_HERE, + base::Bind(&ChildTraceMessageFilter::OnTraceDataCollected, this, + events_str_ptr)); + return; + } + channel_->Send(new TracingHostMsg_TraceDataCollected( + events_str_ptr->data())); +} + +void ChildTraceMessageFilter::OnTraceNotification(int notification) { + if (!ipc_message_loop_->BelongsToCurrentThread()) { + ipc_message_loop_->PostTask(FROM_HERE, + base::Bind(&ChildTraceMessageFilter::OnTraceNotification, this, + notification)); + return; + } + channel_->Send(new TracingHostMsg_TraceNotification(notification)); +} + +} // namespace components diff --git a/components/tracing/child_trace_message_filter.h b/components/tracing/child_trace_message_filter.h new file mode 100644 index 0000000..e4802ba --- /dev/null +++ b/components/tracing/child_trace_message_filter.h @@ -0,0 +1,53 @@ +// Copyright (c) 2012 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 COMPONENTS_TRACING_CHILD_TRACE_MESSAGE_FILTER_H_ +#define COMPONENTS_TRACING_CHILD_TRACE_MESSAGE_FILTER_H_ + +#include "ipc/ipc_channel_proxy.h" + +namespace base { +class MessageLoopProxy; +} + +namespace components { + +// This class sends and receives trace messages on child processes. +class ChildTraceMessageFilter : public IPC::ChannelProxy::MessageFilter { + public: + explicit ChildTraceMessageFilter(base::MessageLoopProxy* ipc_message_loop); + + // IPC::ChannelProxy::MessageFilter implementation. + virtual void OnFilterAdded(IPC::Channel* channel) OVERRIDE; + virtual void OnFilterRemoved() OVERRIDE; + virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; + + protected: + virtual ~ChildTraceMessageFilter(); + + private: + // Message handlers. + void OnBeginTracing(const std::vector<std::string>& included_categories, + const std::vector<std::string>& excluded_categories, + base::TimeTicks browser_time); + void OnEndTracing(); + void OnGetTraceBufferPercentFull(); + void OnSetWatchEvent(const std::string& category_name, + const std::string& event_name); + void OnCancelWatchEvent(); + + // Callback from trace subsystem. + void OnTraceDataCollected( + const scoped_refptr<base::RefCountedString>& events_str_ptr); + void OnTraceNotification(int notification); + + IPC::Channel* channel_; + base::MessageLoopProxy* ipc_message_loop_; + + DISALLOW_COPY_AND_ASSIGN(ChildTraceMessageFilter); +}; + +} // namespace components + +#endif // COMPONENTS_TRACING_CHILD_TRACE_MESSAGE_FILTER_H_ diff --git a/components/tracing/tracing_messages.cc b/components/tracing/tracing_messages.cc new file mode 100644 index 0000000..3d7637a --- /dev/null +++ b/components/tracing/tracing_messages.cc @@ -0,0 +1,34 @@ +// Copyright (c) 2010 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. + +// Get basic type definitions. +#define IPC_MESSAGE_IMPL +#include "components/tracing/tracing_messages.h" + +// Generate constructors. +#include "ipc/struct_constructor_macros.h" +#include "components/tracing/tracing_messages.h" + +// Generate destructors. +#include "ipc/struct_destructor_macros.h" +#include "components/tracing/tracing_messages.h" + +// Generate param traits write methods. +#include "ipc/param_traits_write_macros.h" +namespace IPC { +#include "components/tracing/tracing_messages.h" +} // namespace IPC + +// Generate param traits read methods. +#include "ipc/param_traits_read_macros.h" +namespace IPC { +#include "components/tracing/tracing_messages.h" +} // namespace IPC + +// Generate param traits log methods. +#include "ipc/param_traits_log_macros.h" +namespace IPC { +#include "components/tracing/tracing_messages.h" +} // namespace IPC + diff --git a/components/tracing/tracing_messages.h b/components/tracing/tracing_messages.h new file mode 100644 index 0000000..792c476 --- /dev/null +++ b/components/tracing/tracing_messages.h @@ -0,0 +1,56 @@ +// Copyright (c) 2012 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. + +// Multiply-included message header, no traditional include guard. +#include <string> +#include <vector> + +#include "base/basictypes.h" +#include "base/sync_socket.h" +#include "ipc/ipc_channel_handle.h" +#include "ipc/ipc_message_macros.h" +#include "ipc/ipc_message_utils.h" +#include "ipc/ipc_platform_file.h" + +#define IPC_MESSAGE_START TracingMsgStart + +// Sent to all child processes to enable trace event recording. +IPC_MESSAGE_CONTROL3(TracingMsg_BeginTracing, + std::vector<std::string> /* included_categories */, + std::vector<std::string> /* excluded_categories */, + base::TimeTicks /* browser_time */) + +// Sent to all child processes to disable trace event recording. +IPC_MESSAGE_CONTROL0(TracingMsg_EndTracing) + +// Sent to all child processes to get trace buffer fullness. +IPC_MESSAGE_CONTROL0(TracingMsg_GetTraceBufferPercentFull) + +// Sent to all child processes to set watch event. +IPC_MESSAGE_CONTROL2(TracingMsg_SetWatchEvent, + std::string /* category_name */, + std::string /* event_name */) + +// Sent to all child processes to clear watch event. +IPC_MESSAGE_CONTROL0(TracingMsg_CancelWatchEvent) + +// Notify the browser that this child process supports tracing. +IPC_MESSAGE_CONTROL0(TracingHostMsg_ChildSupportsTracing) + +// Reply from child processes acking ChildProcessMsg_TraceChangeStatus(false). +IPC_MESSAGE_CONTROL1(TracingHostMsg_EndTracingAck, + std::vector<std::string> /* known_categories */) + +// Sent if the trace buffer becomes full. +IPC_MESSAGE_CONTROL1(TracingHostMsg_TraceNotification, + int /* base::debug::TraceLog::Notification */) + +// Child processes send trace data back in JSON chunks. +IPC_MESSAGE_CONTROL1(TracingHostMsg_TraceDataCollected, + std::string /*json trace data*/) + +// Reply to TracingMsg_GetTraceBufferPercentFull. +IPC_MESSAGE_CONTROL1(TracingHostMsg_TraceBufferPercentFullReply, + float /*trace buffer percent full*/) + |