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

Side by Side Diff: webrtc/base/messagequeue.cc

Issue 2019423006: Adding more detail to MessageQueue::Dispatch logging. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 #include <algorithm> 10 #include <algorithm>
11 11
12 #include "webrtc/base/checks.h" 12 #include "webrtc/base/checks.h"
13 #include "webrtc/base/common.h" 13 #include "webrtc/base/common.h"
14 #include "webrtc/base/logging.h" 14 #include "webrtc/base/logging.h"
15 #include "webrtc/base/messagequeue.h" 15 #include "webrtc/base/messagequeue.h"
16 #include "webrtc/base/stringencode.h"
16 #include "webrtc/base/trace_event.h" 17 #include "webrtc/base/trace_event.h"
17 18
18 namespace rtc { 19 namespace rtc {
19 20
20 const int kMaxMsgLatency = 150; // 150 ms 21 const int kMaxMsgLatency = 150; // 150 ms
22 const int kSlowDispatchLoggingThreshold = 50; // 50 ms
21 23
22 //------------------------------------------------------------------ 24 //------------------------------------------------------------------
23 // MessageQueueManager 25 // MessageQueueManager
24 26
25 MessageQueueManager* MessageQueueManager::instance_ = NULL; 27 MessageQueueManager* MessageQueueManager::instance_ = NULL;
26 28
27 MessageQueueManager* MessageQueueManager::Instance() { 29 MessageQueueManager* MessageQueueManager::Instance() {
28 // Note: This is not thread safe, but it is first called before threads are 30 // Note: This is not thread safe, but it is first called before threads are
29 // spawned. 31 // spawned.
30 if (!instance_) 32 if (!instance_)
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 if (cmsElapsed >= cmsWait) 303 if (cmsElapsed >= cmsWait)
302 return false; 304 return false;
303 } 305 }
304 } 306 }
305 return false; 307 return false;
306 } 308 }
307 309
308 void MessageQueue::ReceiveSends() { 310 void MessageQueue::ReceiveSends() {
309 } 311 }
310 312
311 void MessageQueue::Post(MessageHandler* phandler, 313 void MessageQueue::Post(const Location& posted_from,
314 MessageHandler* phandler,
312 uint32_t id, 315 uint32_t id,
313 MessageData* pdata, 316 MessageData* pdata,
314 bool time_sensitive) { 317 bool time_sensitive) {
315 if (fStop_) 318 if (fStop_)
316 return; 319 return;
317 320
318 // Keep thread safe 321 // Keep thread safe
319 // Add the message to the end of the queue 322 // Add the message to the end of the queue
320 // Signal for the multiplexer to return 323 // Signal for the multiplexer to return
321 324
322 { 325 {
323 CritScope cs(&crit_); 326 CritScope cs(&crit_);
324 Message msg; 327 Message msg;
328 msg.posted_from = posted_from;
325 msg.phandler = phandler; 329 msg.phandler = phandler;
326 msg.message_id = id; 330 msg.message_id = id;
327 msg.pdata = pdata; 331 msg.pdata = pdata;
328 if (time_sensitive) { 332 if (time_sensitive) {
329 msg.ts_sensitive = TimeMillis() + kMaxMsgLatency; 333 msg.ts_sensitive = TimeMillis() + kMaxMsgLatency;
330 } 334 }
331 msgq_.push_back(msg); 335 msgq_.push_back(msg);
332 } 336 }
333 WakeUpSocketServer(); 337 WakeUpSocketServer();
334 } 338 }
335 339
336 void MessageQueue::PostDelayed(int cmsDelay, 340 void MessageQueue::PostDelayed(const Location& posted_from,
341 int cmsDelay,
337 MessageHandler* phandler, 342 MessageHandler* phandler,
338 uint32_t id, 343 uint32_t id,
339 MessageData* pdata) { 344 MessageData* pdata) {
340 return DoDelayPost(cmsDelay, TimeAfter(cmsDelay), phandler, id, pdata); 345 return DoDelayPost(posted_from, cmsDelay, TimeAfter(cmsDelay), phandler, id,
346 pdata);
341 } 347 }
342 348
343 void MessageQueue::PostAt(uint32_t tstamp, 349 void MessageQueue::PostAt(const Location& posted_from,
350 uint32_t tstamp,
344 MessageHandler* phandler, 351 MessageHandler* phandler,
345 uint32_t id, 352 uint32_t id,
346 MessageData* pdata) { 353 MessageData* pdata) {
347 // This should work even if it is used (unexpectedly). 354 // This should work even if it is used (unexpectedly).
348 int delay = static_cast<uint32_t>(TimeMillis()) - tstamp; 355 int delay = static_cast<uint32_t>(TimeMillis()) - tstamp;
349 return DoDelayPost(delay, tstamp, phandler, id, pdata); 356 return DoDelayPost(posted_from, delay, tstamp, phandler, id, pdata);
350 } 357 }
351 358
352 void MessageQueue::PostAt(int64_t tstamp, 359 void MessageQueue::PostAt(const Location& posted_from,
360 int64_t tstamp,
353 MessageHandler* phandler, 361 MessageHandler* phandler,
354 uint32_t id, 362 uint32_t id,
355 MessageData* pdata) { 363 MessageData* pdata) {
356 return DoDelayPost(TimeUntil(tstamp), tstamp, phandler, id, pdata); 364 return DoDelayPost(posted_from, TimeUntil(tstamp), tstamp, phandler, id,
365 pdata);
357 } 366 }
358 367
359 void MessageQueue::DoDelayPost(int cmsDelay, 368 void MessageQueue::DoDelayPost(const Location& posted_from,
369 int cmsDelay,
360 int64_t tstamp, 370 int64_t tstamp,
361 MessageHandler* phandler, 371 MessageHandler* phandler,
362 uint32_t id, 372 uint32_t id,
363 MessageData* pdata) { 373 MessageData* pdata) {
364 if (fStop_) 374 if (fStop_)
365 return; 375 return;
366 376
367 // Keep thread safe 377 // Keep thread safe
368 // Add to the priority queue. Gets sorted soonest first. 378 // Add to the priority queue. Gets sorted soonest first.
369 // Signal for the multiplexer to return. 379 // Signal for the multiplexer to return.
370 380
371 { 381 {
372 CritScope cs(&crit_); 382 CritScope cs(&crit_);
373 Message msg; 383 Message msg;
384 msg.posted_from = posted_from;
374 msg.phandler = phandler; 385 msg.phandler = phandler;
375 msg.message_id = id; 386 msg.message_id = id;
376 msg.pdata = pdata; 387 msg.pdata = pdata;
377 DelayedMessage dmsg(cmsDelay, tstamp, dmsgq_next_num_, msg); 388 DelayedMessage dmsg(cmsDelay, tstamp, dmsgq_next_num_, msg);
378 dmsgq_.push(dmsg); 389 dmsgq_.push(dmsg);
379 // If this message queue processes 1 message every millisecond for 50 days, 390 // If this message queue processes 1 message every millisecond for 50 days,
380 // we will wrap this number. Even then, only messages with identical times 391 // we will wrap this number. Even then, only messages with identical times
381 // will be misordered, and then only briefly. This is probably ok. 392 // will be misordered, and then only briefly. This is probably ok.
382 VERIFY(0 != ++dmsgq_next_num_); 393 VERIFY(0 != ++dmsgq_next_num_);
383 } 394 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 } 455 }
445 } else { 456 } else {
446 *new_end++ = *it; 457 *new_end++ = *it;
447 } 458 }
448 } 459 }
449 dmsgq_.container().erase(new_end, dmsgq_.container().end()); 460 dmsgq_.container().erase(new_end, dmsgq_.container().end());
450 dmsgq_.reheap(); 461 dmsgq_.reheap();
451 } 462 }
452 463
453 void MessageQueue::Dispatch(Message *pmsg) { 464 void MessageQueue::Dispatch(Message *pmsg) {
454 TRACE_EVENT0("webrtc", "MessageQueue::Dispatch"); 465 TRACE_EVENT3("webrtc", "MessageQueue::Dispatch", "src_file",
466 pmsg->posted_from.file_name(), "src_func",
467 pmsg->posted_from.function_name(), "src_line",
468 pmsg->posted_from.line_number());
469 int64_t start_time = TimeMillis();
455 pmsg->phandler->OnMessage(pmsg); 470 pmsg->phandler->OnMessage(pmsg);
471 int64_t end_time = TimeMillis();
472 int64_t diff = TimeDiff(end_time, start_time);
473 if (diff >= kSlowDispatchLoggingThreshold) {
474 LOG(LS_INFO) << "Message took " << diff << "ms to dispatch. Posted from: "
tommi 2016/05/31 19:56:27 LS_WARNING?
Taylor Brandstetter 2016/06/02 22:38:41 I'd prefer INFO since this is more for performance
pthatcher1 2016/06/03 00:09:30 INFO is fine.
475 << pmsg->posted_from.ToString();
476 }
456 } 477 }
457 478
458 } // namespace rtc 479 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698