| 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 "base/trace_event/trace_event_impl.h" | 5 #include "base/trace_event/trace_event_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 unsigned char flags) { | 595 unsigned char flags) { |
| 596 timestamp_ = timestamp; | 596 timestamp_ = timestamp; |
| 597 thread_timestamp_ = thread_timestamp; | 597 thread_timestamp_ = thread_timestamp; |
| 598 duration_ = TimeDelta::FromInternalValue(-1); | 598 duration_ = TimeDelta::FromInternalValue(-1); |
| 599 id_ = id; | 599 id_ = id; |
| 600 category_group_enabled_ = category_group_enabled; | 600 category_group_enabled_ = category_group_enabled; |
| 601 name_ = name; | 601 name_ = name; |
| 602 thread_id_ = thread_id; | 602 thread_id_ = thread_id; |
| 603 phase_ = phase; | 603 phase_ = phase; |
| 604 flags_ = flags; | 604 flags_ = flags; |
| 605 flowEvent_ = NULL; |
| 605 | 606 |
| 606 // Clamp num_args since it may have been set by a third_party library. | 607 // Clamp num_args since it may have been set by a third_party library. |
| 607 num_args = (num_args > kTraceMaxNumArgs) ? kTraceMaxNumArgs : num_args; | 608 num_args = (num_args > kTraceMaxNumArgs) ? kTraceMaxNumArgs : num_args; |
| 608 int i = 0; | 609 int i = 0; |
| 609 for (; i < num_args; ++i) { | 610 for (; i < num_args; ++i) { |
| 610 arg_names_[i] = arg_names[i]; | 611 arg_names_[i] = arg_names[i]; |
| 611 arg_types_[i] = arg_types[i]; | 612 arg_types_[i] = arg_types[i]; |
| 612 | 613 |
| 613 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE) | 614 if (arg_types[i] == TRACE_VALUE_TYPE_CONVERTABLE) |
| 614 convertable_values_[i] = convertable_values[i]; | 615 convertable_values_[i] = convertable_values[i]; |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 scope = TRACE_EVENT_SCOPE_NAME_PROCESS; | 856 scope = TRACE_EVENT_SCOPE_NAME_PROCESS; |
| 856 break; | 857 break; |
| 857 | 858 |
| 858 case TRACE_EVENT_SCOPE_THREAD: | 859 case TRACE_EVENT_SCOPE_THREAD: |
| 859 scope = TRACE_EVENT_SCOPE_NAME_THREAD; | 860 scope = TRACE_EVENT_SCOPE_NAME_THREAD; |
| 860 break; | 861 break; |
| 861 } | 862 } |
| 862 StringAppendF(out, ",\"s\":\"%c\"", scope); | 863 StringAppendF(out, ",\"s\":\"%c\"", scope); |
| 863 } | 864 } |
| 864 | 865 |
| 866 // Output flow event info if there is any |
| 867 if (flowEvent_) { |
| 868 StringAppendF(out, ",\"flow\":"); |
| 869 flowEvent_->AppendAsJSON(out, argument_filter_predicate); |
| 870 } |
| 871 |
| 865 *out += "}"; | 872 *out += "}"; |
| 866 } | 873 } |
| 867 | 874 |
| 868 void TraceEvent::AppendPrettyPrinted(std::ostringstream* out) const { | 875 void TraceEvent::AppendPrettyPrinted(std::ostringstream* out) const { |
| 869 *out << name_ << "["; | 876 *out << name_ << "["; |
| 870 *out << TraceLog::GetCategoryGroupName(category_group_enabled_); | 877 *out << TraceLog::GetCategoryGroupName(category_group_enabled_); |
| 871 *out << "]"; | 878 *out << "]"; |
| 872 if (arg_names_[0]) { | 879 if (arg_names_[0]) { |
| 873 *out << ", {"; | 880 *out << ", {"; |
| 874 for (int i = 0; i < kTraceMaxNumArgs && arg_names_[i]; ++i) { | 881 for (int i = 0; i < kTraceMaxNumArgs && arg_names_[i]; ++i) { |
| 875 if (i > 0) | 882 if (i > 0) |
| 876 *out << ", "; | 883 *out << ", "; |
| 877 *out << arg_names_[i] << ":"; | 884 *out << arg_names_[i] << ":"; |
| 878 std::string value_as_text; | 885 std::string value_as_text; |
| 879 | 886 |
| 880 if (arg_types_[i] == TRACE_VALUE_TYPE_CONVERTABLE) | 887 if (arg_types_[i] == TRACE_VALUE_TYPE_CONVERTABLE) |
| 881 convertable_values_[i]->AppendAsTraceFormat(&value_as_text); | 888 convertable_values_[i]->AppendAsTraceFormat(&value_as_text); |
| 882 else | 889 else |
| 883 AppendValueAsJSON(arg_types_[i], arg_values_[i], &value_as_text); | 890 AppendValueAsJSON(arg_types_[i], arg_values_[i], &value_as_text); |
| 884 | 891 |
| 885 *out << value_as_text; | 892 *out << value_as_text; |
| 886 } | 893 } |
| 887 *out << "}"; | 894 *out << "}"; |
| 888 } | 895 } |
| 889 } | 896 } |
| 890 | 897 |
| 898 bool TraceEvent::isFlowEvent() const { |
| 899 return ((phase() == TRACE_EVENT_PHASE_FLOW_BEGIN) || |
| 900 (phase() == TRACE_EVENT_PHASE_FLOW_STEP) || |
| 901 (phase() == TRACE_EVENT_PHASE_FLOW_END)); |
| 902 } |
| 903 |
| 891 //////////////////////////////////////////////////////////////////////////////// | 904 //////////////////////////////////////////////////////////////////////////////// |
| 892 // | 905 // |
| 893 // TraceResultBuffer | 906 // TraceResultBuffer |
| 894 // | 907 // |
| 895 //////////////////////////////////////////////////////////////////////////////// | 908 //////////////////////////////////////////////////////////////////////////////// |
| 896 | 909 |
| 897 TraceResultBuffer::OutputCallback | 910 TraceResultBuffer::OutputCallback |
| 898 TraceResultBuffer::SimpleOutput::GetCallback() { | 911 TraceResultBuffer::SimpleOutput::GetCallback() { |
| 899 return Bind(&SimpleOutput::Append, Unretained(this)); | 912 return Bind(&SimpleOutput::Append, Unretained(this)); |
| 900 } | 913 } |
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1844 const OutputCallback& flush_output_callback, | 1857 const OutputCallback& flush_output_callback, |
| 1845 const TraceEvent::ArgumentFilterPredicate& argument_filter_predicate) { | 1858 const TraceEvent::ArgumentFilterPredicate& argument_filter_predicate) { |
| 1846 if (flush_output_callback.is_null()) | 1859 if (flush_output_callback.is_null()) |
| 1847 return; | 1860 return; |
| 1848 | 1861 |
| 1849 // The callback need to be called at least once even if there is no events | 1862 // The callback need to be called at least once even if there is no events |
| 1850 // to let the caller know the completion of flush. | 1863 // to let the caller know the completion of flush. |
| 1851 scoped_refptr<RefCountedString> json_events_str_ptr = new RefCountedString(); | 1864 scoped_refptr<RefCountedString> json_events_str_ptr = new RefCountedString(); |
| 1852 while (const TraceBufferChunk* chunk = logged_events->NextChunk()) { | 1865 while (const TraceBufferChunk* chunk = logged_events->NextChunk()) { |
| 1853 for (size_t j = 0; j < chunk->size(); ++j) { | 1866 for (size_t j = 0; j < chunk->size(); ++j) { |
| 1867 // Flow Events are always bundled to regular events, and will be handled |
| 1868 // within their bundled events. |
| 1869 if (chunk->GetEventAt(j)->isFlowEvent()) |
| 1870 continue; |
| 1871 |
| 1854 size_t size = json_events_str_ptr->size(); | 1872 size_t size = json_events_str_ptr->size(); |
| 1855 if (size > kTraceEventBufferSizeInBytes) { | 1873 if (size > kTraceEventBufferSizeInBytes) { |
| 1856 flush_output_callback.Run(json_events_str_ptr, true); | 1874 flush_output_callback.Run(json_events_str_ptr, true); |
| 1857 json_events_str_ptr = new RefCountedString(); | 1875 json_events_str_ptr = new RefCountedString(); |
| 1858 } else if (size) { | 1876 } else if (size) { |
| 1859 json_events_str_ptr->data().append(",\n"); | 1877 json_events_str_ptr->data().append(",\n"); |
| 1860 } | 1878 } |
| 1861 chunk->GetEventAt(j)->AppendAsJSON(&(json_events_str_ptr->data()), | 1879 chunk->GetEventAt(j)->AppendAsJSON(&(json_events_str_ptr->data()), |
| 1862 argument_filter_predicate); | 1880 argument_filter_predicate); |
| 1863 } | 1881 } |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2512 } | 2530 } |
| 2513 | 2531 |
| 2514 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { | 2532 ScopedTraceBinaryEfficient::~ScopedTraceBinaryEfficient() { |
| 2515 if (*category_group_enabled_) { | 2533 if (*category_group_enabled_) { |
| 2516 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, | 2534 TRACE_EVENT_API_UPDATE_TRACE_EVENT_DURATION(category_group_enabled_, |
| 2517 name_, event_handle_); | 2535 name_, event_handle_); |
| 2518 } | 2536 } |
| 2519 } | 2537 } |
| 2520 | 2538 |
| 2521 } // namespace trace_event_internal | 2539 } // namespace trace_event_internal |
| OLD | NEW |