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

Unified Diff: base/debug/trace_event_impl.cc

Issue 109933006: Implement sampling profiler (chromium side change) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: first CL Created 7 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
Index: base/debug/trace_event_impl.cc
diff --git a/base/debug/trace_event_impl.cc b/base/debug/trace_event_impl.cc
index 50bf342c4d8ea0431b00ea15a6b4274df3c2d16d..8d4ecfa4375ec3403d2ed2ccc86986cc34b7928d 100644
--- a/base/debug/trace_event_impl.cc
+++ b/base/debug/trace_event_impl.cc
@@ -898,7 +898,7 @@ void TraceSamplingThread::DefaultSamplingCallback(
ExtractCategoryAndName(combined, &category_group, &name);
TRACE_EVENT_API_ADD_TRACE_EVENT(TRACE_EVENT_PHASE_SAMPLE,
TraceLog::GetCategoryGroupEnabled(category_group),
- name, 0, 0, NULL, NULL, NULL, NULL, 0);
+ name, 0, 0, NULL, NULL, NULL, NULL, TRACE_EVENT_FLAG_SAMPLING);
nduca 2013/12/12 07:02:41 i'm a little confused on this side. what is the ca
haraken 2013/12/12 07:34:28 (1) The sampling thread gets the current category
dsinclair 2013/12/12 15:19:31 If we really want everything then why not set hte
haraken 2013/12/12 15:32:17 Then there arises another problem: If we use "*",
dsinclair 2013/12/13 15:55:57 Isn't adding the TRACE_EVENT_FLAG_SAMPLING the sam
}
void TraceSamplingThread::GetSamples() {
@@ -1094,7 +1094,7 @@ void TraceLog::ThreadLocalEventBuffer::FlushWhileLocked() {
trace_log_->lock_.AssertAcquired();
if (trace_log_->CheckGeneration(generation_)) {
- // Return the chunk to the buffer only if the generation matches,
+ // Return the chunk to the buffer only if the generation matches.
trace_log_->logged_events_->ReturnChunk(chunk_index_, chunk_.Pass());
}
// Otherwise this method may be called from the destructor, or TraceLog will
@@ -1349,6 +1349,9 @@ void TraceLog::SetDisabledWhileLocked() {
enabled_ = false;
if (sampling_thread_.get()) {
+ // TODO(haraken): Don't call Platform::Join from the UI thread.
dsinclair 2013/12/11 15:55:04 Is this todo to be done before commit? Or for late
haraken 2013/12/12 00:48:47 Sure, I'll fix before commit.
haraken 2013/12/12 01:54:52 Question: Would the right fix for this be to chang
dsinclair 2013/12/13 15:55:57 I believe this was handled in a separate CL correc
+ base::ThreadRestrictions::SetIOAllowed(true);
+
// Stop the sampling thread.
sampling_thread_->Stop();
lock_.Release();
@@ -1356,6 +1359,8 @@ void TraceLog::SetDisabledWhileLocked() {
lock_.Acquire();
sampling_thread_handle_ = PlatformThreadHandle();
sampling_thread_.reset();
+
+ base::ThreadRestrictions::SetIOAllowed(false);
}
category_filter_.Clear();
@@ -1433,6 +1438,7 @@ TraceEvent* TraceLog::AddEventToThreadSharedChunkWhileLocked(
lock_.AssertAcquired();
if (thread_shared_chunk_ && thread_shared_chunk_->IsFull()) {
+ // Return the chunk to the buffer only if the generation matches.
logged_events_->ReturnChunk(thread_shared_chunk_index_,
thread_shared_chunk_.Pass());
}
@@ -1649,6 +1655,13 @@ void TraceLog::FlushButLeaveBufferIntact(
flush_output_callback);
}
+int TraceLog::NextGeneration()
+{
+ thread_shared_chunk_.reset();
+ thread_shared_chunk_index_ = 0;
+ return static_cast<int>(subtle::NoBarrier_AtomicIncrement(&generation_, 1));
Xianzhu 2013/12/11 17:53:42 Thanks for fixing this! Would it be even better t
haraken 2013/12/12 00:48:47 Sure, will do!
+}
+
TraceEventHandle TraceLog::AddTraceEvent(
char phase,
const unsigned char* category_group_enabled,
@@ -1683,7 +1696,10 @@ TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp(
const scoped_refptr<ConvertableToTraceFormat>* convertable_values,
unsigned char flags) {
TraceEventHandle handle = { 0, 0, 0 };
- if (!*category_group_enabled)
+
+ // We enable all categories in sampling tracing, since it doesn't make sense
dsinclair 2013/12/11 15:55:04 Does this include disabled-by-default- categories?
haraken 2013/12/12 00:48:47 I think the answer is yes. Given that the sampling
dsinclair 2013/12/12 15:19:31 The problem with having disabled-by-default- is th
haraken 2013/12/12 15:32:17 Now I agree that we shouldn't enable all categorie
dsinclair 2013/12/13 15:55:57 I think this was my own confusion with how samplin
+ // to filter sample events by categories.
+ if (!(flags & TRACE_EVENT_FLAG_SAMPLING) && !*category_group_enabled)
dsinclair 2013/12/11 15:55:04 If we always enable all categories then why does t
haraken 2013/12/12 00:48:47 I think that's because the monitoring mode is goin
dsinclair 2013/12/12 15:19:31 Why can't I use monitoring mode to say, tell me th
haraken 2013/12/12 15:32:17 Sounds reasonable. We want to have category filter
dsinclair 2013/12/13 15:55:57 I think I'm getting confused on how this works. Pl
return handle;
// Avoid re-entrance of AddTraceEvent. This may happen in GPU process when
@@ -1759,7 +1775,8 @@ TraceEventHandle TraceLog::AddTraceEventWithThreadIdAndTimestamp(
}
std::string console_message;
- if ((*category_group_enabled & ENABLED_FOR_RECORDING)) {
+ if ((flags & TRACE_EVENT_FLAG_SAMPLING) ||
+ (*category_group_enabled & ENABLED_FOR_RECORDING)) {
OptionalAutoLock lock(lock_);
TraceEvent* trace_event = NULL;

Powered by Google App Engine
This is Rietveld 408576698