diff options
author | wangxianzhu@chromium.org <wangxianzhu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-16 00:05:18 +0000 |
---|---|---|
committer | wangxianzhu@chromium.org <wangxianzhu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-16 00:05:18 +0000 |
commit | 53e6eb13e0972462dd83108e3b264ee5069aeee2 (patch) | |
tree | 3417429fb69161623e33d7a5fb27cbcf591227bf /base/debug | |
parent | e07556d897a812dad540c6c8b9ead4ef6f366e43 (diff) | |
download | chromium_src-53e6eb13e0972462dd83108e3b264ee5069aeee2.zip chromium_src-53e6eb13e0972462dd83108e3b264ee5069aeee2.tar.gz chromium_src-53e6eb13e0972462dd83108e3b264ee5069aeee2.tar.bz2 |
Enable chromium trace when atrace is started.
The X event change (https://codereview.chromium.org/23799005/) depends
on the TraceBuffer to handle X events, so we need to enable chromium
trace when using systrace on Android to trace WebView or Chrome.
Part of this change is separated from https://codereview.chromium.org/26675003/
which is not ready to submit before WebView and Android are ready for
combined trace.
BUG=trace-viewer:142
Review URL: https://codereview.chromium.org/26848006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@228813 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/debug')
-rw-r--r-- | base/debug/trace_event_android.cc | 53 | ||||
-rw-r--r-- | base/debug/trace_event_impl.cc | 29 | ||||
-rw-r--r-- | base/debug/trace_event_impl.h | 16 |
3 files changed, 33 insertions, 65 deletions
diff --git a/base/debug/trace_event_android.cc b/base/debug/trace_event_android.cc index 05f8dcf..d4b4770 100644 --- a/base/debug/trace_event_android.cc +++ b/base/debug/trace_event_android.cc @@ -64,25 +64,38 @@ void WriteEvent( namespace base { namespace debug { +// These functions support Android systrace.py when 'webview' category is +// traced. With the new adb_profile_chrome, we may have two phases: +// - before WebView is ready for combined tracing, we can use adb_profile_chrome +// to trace android categories other than 'webview' and chromium categories. +// In this way we can avoid the conflict between StartATrace/StopATrace and +// the intents. +// - TODO(wangxianzhu): after WebView is ready for combined tracing, remove +// StartATrace, StopATrace and SendToATrace, and perhaps send Java traces +// directly to atrace in trace_event_binding.cc. + void TraceLog::StartATrace() { - AutoLock lock(lock_); + if (g_atrace_fd != -1) + return; + + g_atrace_fd = open(kATraceMarkerFile, O_WRONLY); if (g_atrace_fd == -1) { - g_atrace_fd = open(kATraceMarkerFile, O_WRONLY); - if (g_atrace_fd == -1) { - LOG(WARNING) << "Couldn't open " << kATraceMarkerFile; - } else { - UpdateCategoryGroupEnabledFlags(); - } + PLOG(WARNING) << "Couldn't open " << kATraceMarkerFile; + return; } + SetEnabled(CategoryFilter(CategoryFilter::kDefaultCategoryFilterString), + RECORD_CONTINUOUSLY); } void TraceLog::StopATrace() { - AutoLock lock(lock_); - if (g_atrace_fd != -1) { - close(g_atrace_fd); - g_atrace_fd = -1; - UpdateCategoryGroupEnabledFlags(); - } + if (g_atrace_fd == -1) + return; + + close(g_atrace_fd); + g_atrace_fd = -1; + SetDisabled(); + // Delete the buffered trace events as they have been sent to atrace. + Flush(OutputCallback()); } void TraceLog::SendToATrace( @@ -141,20 +154,6 @@ void TraceLog::SendToATrace( } } -// Must be called with lock_ locked. -void TraceLog::ApplyATraceEnabledFlag(unsigned char* category_group_enabled) { - if (g_atrace_fd == -1) - return; - - // Don't enable disabled-by-default categories for atrace. - const char* category_group = GetCategoryGroupName(category_group_enabled); - if (strncmp(category_group, TRACE_DISABLED_BY_DEFAULT(""), - strlen(TRACE_DISABLED_BY_DEFAULT(""))) == 0) - return; - - *category_group_enabled |= ATRACE_ENABLED; -} - void TraceLog::AddClockSyncMetadataEvent() { int atrace_fd = open(kATraceMarkerFile, O_WRONLY | O_APPEND); if (atrace_fd == -1) { diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc index e606717..6a0bff9 100644 --- a/base/debug/trace_event_impl.cc +++ b/base/debug/trace_event_impl.cc @@ -1212,9 +1212,10 @@ const char* TraceLog::GetCategoryGroupName( } void TraceLog::UpdateCategoryGroupEnabledFlag(int category_index) { - bool is_enabled = enable_count_ && category_filter_.IsCategoryGroupEnabled( - g_category_groups[category_index]); - SetCategoryGroupEnabled(category_index, is_enabled); + g_category_group_enabled[category_index] = + enable_count_ && + category_filter_.IsCategoryGroupEnabled( + g_category_groups[category_index]); } void TraceLog::UpdateCategoryGroupEnabledFlags() { @@ -1222,22 +1223,6 @@ void TraceLog::UpdateCategoryGroupEnabledFlags() { UpdateCategoryGroupEnabledFlag(i); } -void TraceLog::SetCategoryGroupEnabled(int category_index, bool is_enabled) { - g_category_group_enabled[category_index] = - is_enabled ? CATEGORY_GROUP_ENABLED : 0; - -#if defined(OS_ANDROID) - ApplyATraceEnabledFlag(&g_category_group_enabled[category_index]); -#endif -} - -bool TraceLog::IsCategoryGroupEnabled( - const unsigned char* category_group_enabled) { - // On Android, ATrace and normal trace can be enabled independently. - // This function checks if the normal trace is enabled. - return *category_group_enabled & CATEGORY_GROUP_ENABLED; -} - const unsigned char* TraceLog::GetCategoryGroupEnabledInternal( const char* category_group) { DCHECK(!strchr(category_group, '"')) << @@ -1700,6 +1685,9 @@ void TraceLog::AddTraceEventWithThreadIdAndTimestamp( const unsigned long long* arg_values, const scoped_refptr<ConvertableToTraceFormat>* convertable_values, unsigned char flags) { + if (!*category_group_enabled) + return; + DCHECK(name); if (flags & TRACE_EVENT_FLAG_MANGLE_ID) @@ -1711,9 +1699,6 @@ void TraceLog::AddTraceEventWithThreadIdAndTimestamp( flags); #endif - if (!IsCategoryGroupEnabled(category_group_enabled)) - return; - TimeTicks now = timestamp - time_offset_; TimeTicks thread_now = ThreadNow(); diff --git a/base/debug/trace_event_impl.h b/base/debug/trace_event_impl.h index b101bc8..75fa5aa 100644 --- a/base/debug/trace_event_impl.h +++ b/base/debug/trace_event_impl.h @@ -573,21 +573,6 @@ class BASE_EXPORT TraceLog { void UpdateCategoryGroupEnabledFlags(); void UpdateCategoryGroupEnabledFlag(int category_index); - static void SetCategoryGroupEnabled(int category_index, bool enabled); - static bool IsCategoryGroupEnabled( - const unsigned char* category_group_enabled); - - // The pointer returned from GetCategoryGroupEnabledInternal() points to a - // value with zero or more of the following bits. Used in this class only. - // The TRACE_EVENT macros should only use the value as a bool. - enum CategoryGroupEnabledFlags { - // Normal enabled flag for category groups enabled with Enable(). - CATEGORY_GROUP_ENABLED = 1 << 0, - // On Android if ATrace is enabled, all categories will have this bit. - // Not used on other platforms. - ATRACE_ENABLED = 1 << 1 - }; - // Helper class for managing notification_thread_count_ and running // notification callbacks. This is very similar to a reader-writer lock, but // shares the lock with TraceLog and manages the notification flags. @@ -630,7 +615,6 @@ class BASE_EXPORT TraceLog { const unsigned long long* arg_values, const scoped_refptr<ConvertableToTraceFormat>* convertable_values, unsigned char flags); - static void ApplyATraceEnabledFlag(unsigned char* category_group_enabled); #endif TraceBuffer* trace_buffer() const { return logged_events_.get(); } |