Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/metrics/histogram_synchronizer.h" | 5 #include "content/browser/histogram_synchronizer.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/lazy_instance.h" | |
| 8 #include "base/logging.h" | 9 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| 10 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 11 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 12 #include "chrome/common/chrome_constants.h" | 13 #include "content/browser/histogram_controller.h" |
| 13 #include "chrome/common/render_messages.h" | |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/histogram_fetcher.h" |
| 16 #include "content/public/common/content_constants.h" | |
| 16 | 17 |
| 17 using base::Time; | 18 using base::Time; |
| 18 using base::TimeDelta; | 19 using base::TimeDelta; |
| 19 using base::TimeTicks; | 20 using base::TimeTicks; |
| 20 using content::BrowserThread; | 21 |
| 22 namespace { | |
| 21 | 23 |
| 22 // Negative numbers are never used as sequence numbers. We explicitly pick a | 24 // Negative numbers are never used as sequence numbers. We explicitly pick a |
| 23 // negative number that is "so negative" that even when we add one (as is done | 25 // negative number that is "so negative" that even when we add one (as is done |
| 24 // when we generated the next sequence number) that it will still be negative. | 26 // when we generated the next sequence number) that it will still be negative. |
| 25 // We have code that handles wrapping around on an overflow into negative | 27 // We have code that handles wrapping around on an overflow into negative |
| 26 // territory. | 28 // territory. |
| 27 static const int kNeverUsableSequenceNumber = -2; | 29 static const int kNeverUsableSequenceNumber = -2; |
| 28 | 30 |
| 31 } // anonymous namespace | |
| 32 | |
| 33 namespace content { | |
| 34 | |
| 35 // The "RequestContext" structure describes an individual request received from | |
| 36 // the UI. All methods are accessible on UI thread. | |
| 37 class HistogramSynchronizer::RequestContext { | |
| 38 public: | |
| 39 // A map from sequence_number_ to the actual RequestContexts. | |
| 40 typedef std::map<int, RequestContext*> RequestContextMap; | |
| 41 | |
| 42 RequestContext(const base::Closure& callback, int sequence_number) | |
| 43 : callback_(callback), | |
| 44 sequence_number_(sequence_number), | |
| 45 received_process_group_count_(0), | |
| 46 processes_pending_(0) { | |
| 47 } | |
| 48 ~RequestContext() {} | |
| 49 | |
| 50 void SetReceivedProcessGroupCount(bool done) { | |
| 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 52 received_process_group_count_ = done; | |
| 53 } | |
| 54 | |
| 55 // Methods for book keeping of processes_pending_. | |
| 56 void AddProcessesPending(int processes_pending) { | |
| 57 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 58 processes_pending_ += processes_pending; | |
| 59 } | |
| 60 | |
| 61 void DecrementProcessesPending() { | |
| 62 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 63 --processes_pending_; | |
| 64 } | |
| 65 | |
| 66 // Records that we are waiting for one less histogram data from a process for | |
| 67 // the given sequence number. If |received_process_group_count_| and | |
| 68 // |processes_pending_| are zero, then delete the current object by calling | |
| 69 // Unregister. | |
| 70 void DeleteIfAllDone() { | |
| 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 72 | |
| 73 if (processes_pending_ <= 0 && received_process_group_count_) | |
| 74 RequestContext::Unregister(sequence_number_); | |
| 75 } | |
| 76 | |
| 77 // Register |callback| in |outstanding_requests_| map for the given | |
| 78 // |sequence_number|. | |
| 79 static void Register(const base::Closure& callback, int sequence_number) { | |
| 80 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 81 | |
| 82 RequestContext* request = new RequestContext(callback, sequence_number); | |
| 83 outstanding_requests_.Get()[sequence_number] = request; | |
| 84 } | |
| 85 | |
| 86 // Find the |RequestContext| in |outstanding_requests_| map for the given | |
| 87 // |sequence_number|. | |
| 88 static RequestContext* GetRequestContext(int sequence_number) { | |
| 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 90 | |
| 91 RequestContextMap::iterator it = | |
| 92 outstanding_requests_.Get().find(sequence_number); | |
| 93 if (it == outstanding_requests_.Get().end()) | |
| 94 return NULL; | |
| 95 | |
| 96 RequestContext* request = it->second; | |
| 97 DCHECK_EQ(sequence_number, request->sequence_number_); | |
| 98 return request; | |
| 99 } | |
| 100 | |
| 101 // Delete the entry for the given |sequence_number| from | |
| 102 // |outstanding_requests_| map. This method is called when all changes have | |
| 103 // been acquired, or when the wait time expires (whichever is sooner). | |
| 104 static void Unregister(int sequence_number) { | |
| 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 106 | |
| 107 RequestContextMap::iterator it = | |
| 108 outstanding_requests_.Get().find(sequence_number); | |
| 109 if (it == outstanding_requests_.Get().end()) | |
| 110 return; | |
| 111 | |
| 112 RequestContext* request = it->second; | |
| 113 DCHECK_EQ(sequence_number, request->sequence_number_); | |
| 114 bool received_process_group_count = request->received_process_group_count_; | |
| 115 int unresponsive_processes = request->processes_pending_; | |
| 116 | |
| 117 request->callback_.Run(); | |
| 118 | |
| 119 delete request; | |
| 120 outstanding_requests_.Get().erase(it); | |
| 121 | |
| 122 UMA_HISTOGRAM_BOOLEAN("Histogram.ReceivedProcessGroupCount", | |
|
jar (doing other things)
2012/07/09 23:04:12
Be sure to update histograms.xml
ramant (doing other things)
2012/07/11 23:52:54
Will submit a separate CL for it.
Done.
| |
| 123 received_process_group_count); | |
| 124 UMA_HISTOGRAM_COUNTS("Histogram.PendingProcessNotResponding", | |
| 125 unresponsive_processes); | |
| 126 } | |
| 127 | |
| 128 // Delete all the entries in |outstanding_requests_| map. | |
| 129 static void OnShutdown() { | |
| 130 // Just in case we have any pending tasks, clear them out. | |
| 131 while (!outstanding_requests_.Get().empty()) { | |
| 132 RequestContextMap::iterator it = outstanding_requests_.Get().begin(); | |
| 133 delete it->second; | |
| 134 outstanding_requests_.Get().erase(it); | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 // Requests are made to asynchronously send data to the |callback_|. | |
| 139 base::Closure callback_; | |
| 140 | |
| 141 // The sequence number used by the most recent update request to contact all | |
| 142 // processes. | |
| 143 int sequence_number_; | |
| 144 | |
| 145 // Indicates if we have received all pending processes count. | |
| 146 bool received_process_group_count_; | |
| 147 | |
| 148 // The number of pending processes (all renderer processes and browser child | |
| 149 // processes) that have not yet responded to requests. | |
| 150 int processes_pending_; | |
| 151 | |
| 152 // Map of all outstanding RequestContexts, from sequence_number_ to | |
| 153 // RequestContext. | |
| 154 static base::LazyInstance<RequestContextMap>::Leaky outstanding_requests_; | |
| 155 }; | |
| 156 | |
| 29 HistogramSynchronizer::HistogramSynchronizer() | 157 HistogramSynchronizer::HistogramSynchronizer() |
| 30 : lock_(), | 158 : lock_(), |
| 31 received_all_renderer_histograms_(&lock_), | 159 callback_thread_(NULL), |
| 32 callback_thread_(NULL), | 160 last_used_sequence_number_(kNeverUsableSequenceNumber), |
| 33 last_used_sequence_number_(kNeverUsableSequenceNumber), | 161 async_sequence_number_(kNeverUsableSequenceNumber) { |
| 34 async_sequence_number_(kNeverUsableSequenceNumber), | 162 content::HistogramController::GetInstance()->Register(this); |
| 35 async_renderers_pending_(0), | |
| 36 synchronous_sequence_number_(kNeverUsableSequenceNumber), | |
| 37 synchronous_renderers_pending_(0) { | |
| 38 DCHECK(histogram_synchronizer_ == NULL); | |
| 39 histogram_synchronizer_ = this; | |
| 40 } | 163 } |
| 41 | 164 |
| 42 HistogramSynchronizer::~HistogramSynchronizer() { | 165 HistogramSynchronizer::~HistogramSynchronizer() { |
| 166 RequestContext::OnShutdown(); | |
| 167 | |
| 43 // Just in case we have any pending tasks, clear them out. | 168 // Just in case we have any pending tasks, clear them out. |
| 44 SetCallbackTaskAndThread(NULL, base::Closure()); | 169 SetCallbackTaskAndThread(NULL, base::Closure()); |
| 45 histogram_synchronizer_ = NULL; | 170 } |
| 171 | |
| 172 HistogramSynchronizer* HistogramSynchronizer::GetInstance() { | |
| 173 return Singleton<HistogramSynchronizer, | |
| 174 LeakySingletonTraits<HistogramSynchronizer> >::get(); | |
| 46 } | 175 } |
| 47 | 176 |
| 48 // static | 177 // static |
| 49 HistogramSynchronizer* HistogramSynchronizer::CurrentSynchronizer() { | 178 void HistogramSynchronizer::FetchHistograms() { |
| 50 DCHECK(histogram_synchronizer_ != NULL); | 179 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| 51 return histogram_synchronizer_; | 180 BrowserThread::PostTask( |
| 52 } | 181 BrowserThread::UI, FROM_HERE, |
| 53 | 182 base::Bind(&HistogramSynchronizer::FetchHistograms)); |
| 54 void HistogramSynchronizer::FetchRendererHistogramsSynchronously( | 183 return; |
| 55 TimeDelta wait_time) { | 184 } |
| 56 NotifyAllRenderers(SYNCHRONOUS_HISTOGRAMS); | 185 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 57 | 186 |
| 58 TimeTicks start = TimeTicks::Now(); | 187 HistogramSynchronizer* current_synchronizer = |
| 59 TimeTicks end_time = start + wait_time; | 188 HistogramSynchronizer::GetInstance(); |
| 60 int unresponsive_renderer_count; | 189 if (current_synchronizer == NULL) |
| 61 { | 190 return; |
| 62 base::AutoLock auto_lock(lock_); | 191 |
| 63 while (synchronous_renderers_pending_ > 0 && TimeTicks::Now() < end_time) { | 192 current_synchronizer->RegisterAndNotifyAllProcesses( |
| 64 wait_time = end_time - TimeTicks::Now(); | 193 HistogramSynchronizer::UNKNOWN, |
| 65 base::ThreadRestrictions::ScopedAllowWait allow_wait; | 194 base::TimeDelta::FromMinutes(1)); |
| 66 received_all_renderer_histograms_.TimedWait(wait_time); | 195 } |
| 67 } | 196 |
| 68 unresponsive_renderer_count = synchronous_renderers_pending_; | 197 void FetchHistogramsAsynchronously(MessageLoop* callback_thread, |
| 69 synchronous_renderers_pending_ = 0; | 198 const base::Closure& callback, |
| 70 synchronous_sequence_number_ = kNeverUsableSequenceNumber; | 199 base::TimeDelta wait_time) { |
| 71 } | 200 HistogramSynchronizer::FetchHistogramsAsynchronously( |
| 72 UMA_HISTOGRAM_COUNTS("Histogram.RendersNotRespondingSynchronous", | 201 callback_thread, callback, wait_time); |
| 73 unresponsive_renderer_count); | |
| 74 if (!unresponsive_renderer_count) | |
| 75 UMA_HISTOGRAM_TIMES("Histogram.FetchRendererHistogramsSynchronously", | |
| 76 TimeTicks::Now() - start); | |
| 77 } | 202 } |
| 78 | 203 |
| 79 // static | 204 // static |
| 80 void HistogramSynchronizer::FetchRendererHistogramsAsynchronously( | 205 void HistogramSynchronizer::FetchHistogramsAsynchronously( |
| 81 MessageLoop* callback_thread, | 206 MessageLoop* callback_thread, |
| 82 const base::Closure& callback, | 207 const base::Closure& callback, |
| 83 base::TimeDelta wait_time) { | 208 base::TimeDelta wait_time) { |
| 84 DCHECK(callback_thread != NULL); | 209 DCHECK(callback_thread != NULL); |
| 85 DCHECK(!callback.is_null()); | 210 DCHECK(!callback.is_null()); |
| 86 | 211 |
| 87 HistogramSynchronizer* current_synchronizer = CurrentSynchronizer(); | 212 HistogramSynchronizer* current_synchronizer = |
| 88 | 213 HistogramSynchronizer::GetInstance(); |
| 89 if (current_synchronizer == NULL) { | 214 if (current_synchronizer == NULL) { |
| 90 // System teardown is happening. | |
| 91 callback_thread->PostTask(FROM_HERE, callback); | 215 callback_thread->PostTask(FROM_HERE, callback); |
| 92 return; | 216 return; |
|
jar (doing other things)
2012/07/09 23:04:12
nit: lines 214-217 are probably not needed here (u
ramant (doing other things)
2012/07/11 23:52:54
Done.
| |
| 93 } | 217 } |
| 94 | 218 |
| 95 current_synchronizer->SetCallbackTaskAndThread(callback_thread, | 219 current_synchronizer->SetCallbackTaskAndThread( |
| 96 callback); | 220 callback_thread, callback); |
| 97 | 221 |
| 98 int sequence_number = | 222 current_synchronizer->RegisterAndNotifyAllProcesses( |
| 99 current_synchronizer->NotifyAllRenderers(ASYNC_HISTOGRAMS); | 223 HistogramSynchronizer::ASYNC_HISTOGRAMS, wait_time); |
| 224 } | |
| 225 | |
| 226 void HistogramSynchronizer::RegisterAndNotifyAllProcesses( | |
| 227 ProcessHistogramRequester requester, | |
| 228 base::TimeDelta wait_time) { | |
| 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 230 | |
| 231 int sequence_number = GetNextAvailableSequenceNumber(requester); | |
| 232 | |
| 233 base::Closure callback = | |
| 234 base::Bind( | |
|
jar (doing other things)
2012/07/09 23:04:12
nit: move to previous line.
ramant (doing other things)
2012/07/11 23:52:54
Done.
| |
| 235 &HistogramSynchronizer::ForceHistogramSynchronizationDoneCallback, | |
| 236 base::Unretained(this), | |
| 237 sequence_number); | |
| 238 | |
| 239 RequestContext::Register(callback, sequence_number); | |
| 240 | |
| 241 // Get histogram data from renderer and browser child processes. | |
| 242 content::HistogramController::GetInstance()->GetHistogramData( | |
| 243 sequence_number); | |
| 100 | 244 |
| 101 // Post a task that would be called after waiting for wait_time. This acts | 245 // Post a task that would be called after waiting for wait_time. This acts |
| 102 // as a watchdog, to ensure that a non-responsive renderer won't block us from | 246 // as a watchdog, to cancel the requests for non-responsive processes. |
| 103 // making the callback. | |
| 104 BrowserThread::PostDelayedTask( | 247 BrowserThread::PostDelayedTask( |
| 105 BrowserThread::UI, FROM_HERE, | 248 BrowserThread::UI, FROM_HERE, |
| 106 base::Bind( | 249 base::Bind(&RequestContext::Unregister, sequence_number), |
| 107 &HistogramSynchronizer::ForceHistogramSynchronizationDoneCallback, | |
| 108 current_synchronizer, | |
| 109 sequence_number), | |
| 110 wait_time); | 250 wait_time); |
| 111 } | 251 } |
| 112 | 252 |
| 113 // static | 253 void HistogramSynchronizer::OnPendingProcesses(int sequence_number, |
| 114 void HistogramSynchronizer::DeserializeHistogramList( | 254 int pending_processes, |
| 255 bool end) { | |
| 256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 257 | |
| 258 RequestContext* request = RequestContext::GetRequestContext(sequence_number); | |
| 259 if (!request) | |
| 260 return; | |
| 261 request->AddProcessesPending(pending_processes); | |
| 262 request->SetReceivedProcessGroupCount(end); | |
| 263 request->DeleteIfAllDone(); | |
| 264 } | |
| 265 | |
| 266 void HistogramSynchronizer::OnHistogramDataCollected( | |
| 115 int sequence_number, | 267 int sequence_number, |
| 116 const std::vector<std::string>& histograms) { | 268 const std::vector<std::string>& pickled_histograms) { |
| 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 118 for (std::vector<std::string>::const_iterator it = histograms.begin(); | 270 |
| 119 it < histograms.end(); | 271 RequestContext* request = RequestContext::GetRequestContext(sequence_number); |
| 272 | |
| 273 for (std::vector<std::string>::const_iterator it = pickled_histograms.begin(); | |
| 274 it < pickled_histograms.end(); | |
| 120 ++it) { | 275 ++it) { |
| 121 base::Histogram::DeserializeHistogramInfo(*it); | 276 base::Histogram::DeserializeHistogramInfo(*it); |
| 122 } | 277 } |
| 123 | 278 |
| 124 HistogramSynchronizer* current_synchronizer = CurrentSynchronizer(); | 279 if (!request) |
| 125 if (current_synchronizer == NULL) | 280 return; |
| 126 return; | 281 |
| 127 | 282 // Delete request if we have heard back from all child processes. |
| 128 // Record that we have received a histogram from renderer process. | 283 request->DecrementProcessesPending(); |
| 129 current_synchronizer->DecrementPendingRenderers(sequence_number); | 284 request->DeleteIfAllDone(); |
| 130 } | |
| 131 | |
| 132 int HistogramSynchronizer::NotifyAllRenderers( | |
| 133 RendererHistogramRequester requester) { | |
| 134 // To iterate over RenderProcessHosts, or to send messages to the hosts, we | |
| 135 // need to be on the UI thread. | |
| 136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 137 | |
| 138 int notification_count = 0; | |
| 139 for (content::RenderProcessHost::iterator it( | |
| 140 content::RenderProcessHost::AllHostsIterator()); | |
| 141 !it.IsAtEnd(); it.Advance()) | |
| 142 ++notification_count; | |
| 143 | |
| 144 int sequence_number = GetNextAvailableSequenceNumber(requester, | |
| 145 notification_count); | |
| 146 for (content::RenderProcessHost::iterator it( | |
| 147 content::RenderProcessHost::AllHostsIterator()); | |
| 148 !it.IsAtEnd(); it.Advance()) { | |
| 149 if (!it.GetCurrentValue()->Send( | |
| 150 new ChromeViewMsg_GetRendererHistograms(sequence_number))) | |
| 151 DecrementPendingRenderers(sequence_number); | |
| 152 } | |
| 153 | |
| 154 return sequence_number; | |
| 155 } | |
| 156 | |
| 157 void HistogramSynchronizer::DecrementPendingRenderers(int sequence_number) { | |
| 158 bool synchronous_completed = false; | |
| 159 bool asynchronous_completed = false; | |
| 160 | |
| 161 { | |
| 162 base::AutoLock auto_lock(lock_); | |
| 163 if (sequence_number == async_sequence_number_) { | |
| 164 if (--async_renderers_pending_ <= 0) | |
| 165 asynchronous_completed = true; | |
| 166 } else if (sequence_number == synchronous_sequence_number_) { | |
| 167 if (--synchronous_renderers_pending_ <= 0) | |
| 168 synchronous_completed = true; | |
| 169 } | |
| 170 } | |
| 171 | |
| 172 if (asynchronous_completed) | |
| 173 ForceHistogramSynchronizationDoneCallback(sequence_number); | |
| 174 else if (synchronous_completed) | |
| 175 received_all_renderer_histograms_.Signal(); | |
| 176 } | 285 } |
| 177 | 286 |
| 178 void HistogramSynchronizer::SetCallbackTaskAndThread( | 287 void HistogramSynchronizer::SetCallbackTaskAndThread( |
| 179 MessageLoop* callback_thread, | 288 MessageLoop* callback_thread, |
| 180 const base::Closure& callback) { | 289 const base::Closure& callback) { |
| 181 base::Closure old_callback; | 290 base::Closure old_callback; |
| 182 MessageLoop* old_thread = NULL; | 291 MessageLoop* old_thread = NULL; |
| 183 TimeTicks old_start_time; | |
| 184 int unresponsive_renderers; | |
| 185 const TimeTicks now = TimeTicks::Now(); | |
| 186 { | 292 { |
| 187 base::AutoLock auto_lock(lock_); | 293 base::AutoLock auto_lock(lock_); |
| 188 old_callback = callback_; | 294 old_callback = callback_; |
| 189 callback_ = callback; | 295 callback_ = callback; |
| 190 old_thread = callback_thread_; | 296 old_thread = callback_thread_; |
| 191 callback_thread_ = callback_thread; | 297 callback_thread_ = callback_thread; |
| 192 unresponsive_renderers = async_renderers_pending_; | |
| 193 old_start_time = async_callback_start_time_; | |
| 194 async_callback_start_time_ = now; | |
| 195 // Prevent premature calling of our new callbacks. | 298 // Prevent premature calling of our new callbacks. |
| 196 async_sequence_number_ = kNeverUsableSequenceNumber; | 299 async_sequence_number_ = kNeverUsableSequenceNumber; |
| 197 } | 300 } |
| 198 // Just in case there was a task pending.... | 301 // Just in case there was a task pending.... |
| 199 InternalPostTask(old_thread, old_callback, unresponsive_renderers, | 302 InternalPostTask(old_thread, old_callback); |
| 200 old_start_time); | |
| 201 } | 303 } |
| 202 | 304 |
| 203 void HistogramSynchronizer::ForceHistogramSynchronizationDoneCallback( | 305 void HistogramSynchronizer::ForceHistogramSynchronizationDoneCallback( |
| 204 int sequence_number) { | 306 int sequence_number) { |
| 205 base::Closure callback; | 307 base::Closure callback; |
| 206 MessageLoop* thread = NULL; | 308 MessageLoop* thread = NULL; |
| 207 TimeTicks started; | |
| 208 int unresponsive_renderers; | |
| 209 { | 309 { |
| 210 base::AutoLock lock(lock_); | 310 base::AutoLock lock(lock_); |
| 211 if (sequence_number != async_sequence_number_) | 311 if (sequence_number != async_sequence_number_) |
| 212 return; | 312 return; |
| 213 callback = callback_; | 313 callback = callback_; |
| 214 thread = callback_thread_; | 314 thread = callback_thread_; |
| 215 callback_.Reset(); | 315 callback_.Reset(); |
| 216 callback_thread_ = NULL; | 316 callback_thread_ = NULL; |
| 217 started = async_callback_start_time_; | |
| 218 unresponsive_renderers = async_renderers_pending_; | |
| 219 } | 317 } |
| 220 InternalPostTask(thread, callback, unresponsive_renderers, started); | 318 InternalPostTask(thread, callback); |
| 221 } | 319 } |
| 222 | 320 |
| 223 void HistogramSynchronizer::InternalPostTask(MessageLoop* thread, | 321 void HistogramSynchronizer::InternalPostTask(MessageLoop* thread, |
| 224 const base::Closure& callback, | 322 const base::Closure& callback) { |
| 225 int unresponsive_renderers, | |
| 226 const base::TimeTicks& started) { | |
| 227 if (callback.is_null() || !thread) | 323 if (callback.is_null() || !thread) |
| 228 return; | 324 return; |
| 229 UMA_HISTOGRAM_COUNTS("Histogram.RendersNotRespondingAsynchronous", | |
|
jar (doing other things)
2012/07/09 23:04:12
nit: consider obsoleting in the histograms.xml fil
ramant (doing other things)
2012/07/11 23:52:54
Submitting a separate CL for histograms.xml change
| |
| 230 unresponsive_renderers); | |
| 231 if (!unresponsive_renderers) { | |
| 232 UMA_HISTOGRAM_TIMES("Histogram.FetchRendererHistogramsAsynchronously", | |
| 233 TimeTicks::Now() - started); | |
| 234 } | |
| 235 | |
| 236 thread->PostTask(FROM_HERE, callback); | 325 thread->PostTask(FROM_HERE, callback); |
| 237 } | 326 } |
| 238 | 327 |
| 239 int HistogramSynchronizer::GetNextAvailableSequenceNumber( | 328 int HistogramSynchronizer::GetNextAvailableSequenceNumber( |
| 240 RendererHistogramRequester requester, | 329 ProcessHistogramRequester requester) { |
| 241 int renderer_count) { | |
| 242 base::AutoLock auto_lock(lock_); | 330 base::AutoLock auto_lock(lock_); |
| 243 ++last_used_sequence_number_; | 331 ++last_used_sequence_number_; |
| 244 // Watch out for wrapping to a negative number. | 332 // Watch out for wrapping to a negative number. |
| 245 if (last_used_sequence_number_ < 0) { | 333 if (last_used_sequence_number_ < 0) { |
| 246 // Bypass the reserved number, which is used when a renderer spontaneously | 334 // Bypass the reserved number, which is used when a renderer spontaneously |
| 247 // decides to send some histogram data. | 335 // decides to send some histogram data. |
| 248 last_used_sequence_number_ = | 336 last_used_sequence_number_ = |
| 249 chrome::kHistogramSynchronizerReservedSequenceNumber + 1; | 337 kHistogramSynchronizerReservedSequenceNumber + 1; |
| 250 } | 338 } |
| 251 DCHECK_NE(last_used_sequence_number_, | 339 DCHECK_NE(last_used_sequence_number_, |
| 252 chrome::kHistogramSynchronizerReservedSequenceNumber); | 340 kHistogramSynchronizerReservedSequenceNumber); |
| 253 if (requester == ASYNC_HISTOGRAMS) { | 341 if (requester == ASYNC_HISTOGRAMS) |
| 254 async_sequence_number_ = last_used_sequence_number_; | 342 async_sequence_number_ = last_used_sequence_number_; |
| 255 async_renderers_pending_ = renderer_count; | |
| 256 } else if (requester == SYNCHRONOUS_HISTOGRAMS) { | |
| 257 synchronous_sequence_number_ = last_used_sequence_number_; | |
| 258 synchronous_renderers_pending_ = renderer_count; | |
| 259 } | |
| 260 return last_used_sequence_number_; | 343 return last_used_sequence_number_; |
| 261 } | 344 } |
| 262 | 345 |
| 263 // static | 346 // static |
| 264 HistogramSynchronizer* HistogramSynchronizer::histogram_synchronizer_ = NULL; | 347 base::LazyInstance |
| 348 <HistogramSynchronizer::RequestContext::RequestContextMap>::Leaky | |
| 349 HistogramSynchronizer::RequestContext::outstanding_requests_ = | |
| 350 LAZY_INSTANCE_INITIALIZER; | |
|
jar (doing other things)
2012/07/09 23:04:12
nit: typedef to reduce length of line.
ramant (doing other things)
2012/07/11 23:52:54
Wasn't able to define a typedef. Will leave it int
| |
| 351 | |
| 352 } // namespace content | |
| OLD | NEW |