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

Side by Side Diff: base/debug/trace_event_impl.cc

Issue 11557009: Remove support for TRACE_EVENT_IF_LONGER_THANx macros (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/debug/trace_event_impl.h" 5 #include "base/debug/trace_event_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/debug/leak_annotations.h" 10 #include "base/debug/leak_annotations.h"
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 scoped_refptr<RefCountedString> json_events_str_ptr = 602 scoped_refptr<RefCountedString> json_events_str_ptr =
603 new RefCountedString(); 603 new RefCountedString();
604 TraceEvent::AppendEventsAsJSON(previous_logged_events, 604 TraceEvent::AppendEventsAsJSON(previous_logged_events,
605 i, 605 i,
606 kTraceEventBatchSize, 606 kTraceEventBatchSize,
607 &(json_events_str_ptr->data())); 607 &(json_events_str_ptr->data()));
608 cb.Run(json_events_str_ptr); 608 cb.Run(json_events_str_ptr);
609 } 609 }
610 } 610 }
611 611
612 int TraceLog::AddTraceEvent(char phase, 612 void TraceLog::AddTraceEvent(char phase,
613 const unsigned char* category_enabled, 613 const unsigned char* category_enabled,
614 const char* name, 614 const char* name,
615 unsigned long long id, 615 unsigned long long id,
616 int num_args, 616 int num_args,
617 const char** arg_names, 617 const char** arg_names,
618 const unsigned char* arg_types, 618 const unsigned char* arg_types,
619 const unsigned long long* arg_values, 619 const unsigned long long* arg_values,
620 int threshold_begin_id,
621 long long threshold,
622 unsigned char flags) { 620 unsigned char flags) {
623 DCHECK(name); 621 DCHECK(name);
624 622
625 #if defined(OS_ANDROID) 623 #if defined(OS_ANDROID)
626 SendToATrace(phase, GetCategoryName(category_enabled), name, 624 SendToATrace(phase, GetCategoryName(category_enabled), name,
627 num_args, arg_names, arg_types, arg_values); 625 num_args, arg_names, arg_types, arg_values);
628 #endif 626 #endif
629 627
630 TimeTicks now = TimeTicks::NowFromSystemTraceTime() - time_offset_; 628 TimeTicks now = TimeTicks::NowFromSystemTraceTime() - time_offset_;
631 NotificationHelper notifier(this); 629 NotificationHelper notifier(this);
632 int ret_begin_id = -1;
633 { 630 {
634 AutoLock lock(lock_); 631 AutoLock lock(lock_);
635 if (*category_enabled != CATEGORY_ENABLED) 632 if (*category_enabled != CATEGORY_ENABLED)
636 return -1; 633 return;
637 if (logged_events_.size() >= kTraceEventBufferSize) 634 if (logged_events_.size() >= kTraceEventBufferSize)
638 return -1; 635 return;
639 636
640 int thread_id = static_cast<int>(PlatformThread::CurrentId()); 637 int thread_id = static_cast<int>(PlatformThread::CurrentId());
641 638
642 const char* new_name = PlatformThread::GetName(); 639 const char* new_name = PlatformThread::GetName();
643 // Check if the thread name has been set or changed since the previous 640 // Check if the thread name has been set or changed since the previous
644 // call (if any), but don't bother if the new name is empty. Note this will 641 // call (if any), but don't bother if the new name is empty. Note this will
645 // not detect a thread name change within the same char* buffer address: we 642 // not detect a thread name change within the same char* buffer address: we
646 // favor common case performance over corner case correctness. 643 // favor common case performance over corner case correctness.
647 if (new_name != g_current_thread_name.Get().Get() && 644 if (new_name != g_current_thread_name.Get().Get() &&
648 new_name && *new_name) { 645 new_name && *new_name) {
(...skipping 11 matching lines...) Expand all
660 bool found = std::find(existing_names.begin(), 657 bool found = std::find(existing_names.begin(),
661 existing_names.end(), 658 existing_names.end(),
662 new_name) != existing_names.end(); 659 new_name) != existing_names.end();
663 if (!found) { 660 if (!found) {
664 existing_name->second.push_back(','); 661 existing_name->second.push_back(',');
665 existing_name->second.append(new_name); 662 existing_name->second.append(new_name);
666 } 663 }
667 } 664 }
668 } 665 }
669 666
670 if (threshold_begin_id > -1) {
671 DCHECK(phase == TRACE_EVENT_PHASE_END);
672 size_t begin_i = static_cast<size_t>(threshold_begin_id);
673 // Return now if there has been a flush since the begin event was posted.
674 if (begin_i >= logged_events_.size())
675 return -1;
676 // Determine whether to drop the begin/end pair.
677 TimeDelta elapsed = now - logged_events_[begin_i].timestamp();
678 if (elapsed < TimeDelta::FromMicroseconds(threshold)) {
679 // Remove begin event and do not add end event.
680 // This will be expensive if there have been other events in the
681 // mean time (should be rare).
682 logged_events_.erase(logged_events_.begin() + begin_i);
683 return -1;
684 }
685 }
686
687 if (flags & TRACE_EVENT_FLAG_MANGLE_ID) 667 if (flags & TRACE_EVENT_FLAG_MANGLE_ID)
688 id ^= process_id_hash_; 668 id ^= process_id_hash_;
689 669
690 ret_begin_id = static_cast<int>(logged_events_.size());
691 logged_events_.push_back( 670 logged_events_.push_back(
692 TraceEvent(thread_id, 671 TraceEvent(thread_id,
693 now, phase, category_enabled, name, id, 672 now, phase, category_enabled, name, id,
694 num_args, arg_names, arg_types, arg_values, 673 num_args, arg_names, arg_types, arg_values,
695 flags)); 674 flags));
696 675
697 if (logged_events_.size() == kTraceEventBufferSize) 676 if (logged_events_.size() == kTraceEventBufferSize)
698 notifier.AddNotificationWhileLocked(TRACE_BUFFER_FULL); 677 notifier.AddNotificationWhileLocked(TRACE_BUFFER_FULL);
699 678
700 if (watch_category_ == category_enabled && watch_event_name_ == name) 679 if (watch_category_ == category_enabled && watch_event_name_ == name)
701 notifier.AddNotificationWhileLocked(EVENT_WATCH_NOTIFICATION); 680 notifier.AddNotificationWhileLocked(EVENT_WATCH_NOTIFICATION);
702 } // release lock 681 } // release lock
703 682
704 notifier.SendNotificationIfAny(); 683 notifier.SendNotificationIfAny();
705
706 return ret_begin_id;
707 } 684 }
708 685
709 void TraceLog::AddTraceEventEtw(char phase, 686 void TraceLog::AddTraceEventEtw(char phase,
710 const char* name, 687 const char* name,
711 const void* id, 688 const void* id,
712 const char* extra) { 689 const char* extra) {
713 #if defined(OS_WIN) 690 #if defined(OS_WIN)
714 TraceEventETWProvider::Trace(name, phase, id, extra); 691 TraceEventETWProvider::Trace(name, phase, id, extra);
715 #endif 692 #endif
716 INTERNAL_TRACE_EVENT_ADD(phase, "ETW Trace Event", name, 693 INTERNAL_TRACE_EVENT_ADD(phase, "ETW Trace Event", name,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 unsigned long long pid = static_cast<unsigned long long>(process_id_); 780 unsigned long long pid = static_cast<unsigned long long>(process_id_);
804 process_id_hash_ = (offset_basis ^ pid) * fnv_prime; 781 process_id_hash_ = (offset_basis ^ pid) * fnv_prime;
805 } 782 }
806 783
807 void TraceLog::SetTimeOffset(TimeDelta offset) { 784 void TraceLog::SetTimeOffset(TimeDelta offset) {
808 time_offset_ = offset; 785 time_offset_ = offset;
809 } 786 }
810 787
811 } // namespace debug 788 } // namespace debug
812 } // namespace base 789 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698