| 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 "base/format_macros.h" | 7 #include "base/format_macros.h" |
| 8 #include "base/json/string_escape.h" | 8 #include "base/json/string_escape.h" |
| 9 #include "base/process/process_handle.h" | 9 #include "base/process/process_handle.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 } | 51 } |
| 52 | 52 |
| 53 TraceEvent::~TraceEvent() { | 53 TraceEvent::~TraceEvent() { |
| 54 } | 54 } |
| 55 | 55 |
| 56 void TraceEvent::CopyFrom(const TraceEvent& other) { | 56 void TraceEvent::CopyFrom(const TraceEvent& other) { |
| 57 timestamp_ = other.timestamp_; | 57 timestamp_ = other.timestamp_; |
| 58 thread_timestamp_ = other.thread_timestamp_; | 58 thread_timestamp_ = other.thread_timestamp_; |
| 59 duration_ = other.duration_; | 59 duration_ = other.duration_; |
| 60 id_ = other.id_; | 60 id_ = other.id_; |
| 61 context_id_ = other.context_id_; | |
| 62 category_group_enabled_ = other.category_group_enabled_; | 61 category_group_enabled_ = other.category_group_enabled_; |
| 63 name_ = other.name_; | 62 name_ = other.name_; |
| 64 if (other.flags_ & TRACE_EVENT_FLAG_HAS_PROCESS_ID) | 63 if (other.flags_ & TRACE_EVENT_FLAG_HAS_PROCESS_ID) |
| 65 process_id_ = other.process_id_; | 64 process_id_ = other.process_id_; |
| 66 else | 65 else |
| 67 thread_id_ = other.thread_id_; | 66 thread_id_ = other.thread_id_; |
| 68 phase_ = other.phase_; | 67 phase_ = other.phase_; |
| 69 flags_ = other.flags_; | 68 flags_ = other.flags_; |
| 70 parameter_copy_storage_ = other.parameter_copy_storage_; | 69 parameter_copy_storage_ = other.parameter_copy_storage_; |
| 71 | 70 |
| 72 for (int i = 0; i < kTraceMaxNumArgs; ++i) { | 71 for (int i = 0; i < kTraceMaxNumArgs; ++i) { |
| 73 arg_names_[i] = other.arg_names_[i]; | 72 arg_names_[i] = other.arg_names_[i]; |
| 74 arg_types_[i] = other.arg_types_[i]; | 73 arg_types_[i] = other.arg_types_[i]; |
| 75 arg_values_[i] = other.arg_values_[i]; | 74 arg_values_[i] = other.arg_values_[i]; |
| 76 convertable_values_[i] = other.convertable_values_[i]; | 75 convertable_values_[i] = other.convertable_values_[i]; |
| 77 } | 76 } |
| 78 } | 77 } |
| 79 | 78 |
| 80 void TraceEvent::Initialize( | 79 void TraceEvent::Initialize( |
| 81 int thread_id, | 80 int thread_id, |
| 82 TimeTicks timestamp, | 81 TimeTicks timestamp, |
| 83 ThreadTicks thread_timestamp, | 82 ThreadTicks thread_timestamp, |
| 84 char phase, | 83 char phase, |
| 85 const unsigned char* category_group_enabled, | 84 const unsigned char* category_group_enabled, |
| 86 const char* name, | 85 const char* name, |
| 87 unsigned long long id, | 86 unsigned long long id, |
| 88 unsigned long long context_id, | |
| 89 unsigned long long bind_id, | 87 unsigned long long bind_id, |
| 90 int num_args, | 88 int num_args, |
| 91 const char** arg_names, | 89 const char** arg_names, |
| 92 const unsigned char* arg_types, | 90 const unsigned char* arg_types, |
| 93 const unsigned long long* arg_values, | 91 const unsigned long long* arg_values, |
| 94 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, | 92 const scoped_refptr<ConvertableToTraceFormat>* convertable_values, |
| 95 unsigned int flags) { | 93 unsigned int flags) { |
| 96 timestamp_ = timestamp; | 94 timestamp_ = timestamp; |
| 97 thread_timestamp_ = thread_timestamp; | 95 thread_timestamp_ = thread_timestamp; |
| 98 duration_ = TimeDelta::FromInternalValue(-1); | 96 duration_ = TimeDelta::FromInternalValue(-1); |
| 99 id_ = id; | 97 id_ = id; |
| 100 context_id_ = context_id; | |
| 101 category_group_enabled_ = category_group_enabled; | 98 category_group_enabled_ = category_group_enabled; |
| 102 name_ = name; | 99 name_ = name; |
| 103 thread_id_ = thread_id; | 100 thread_id_ = thread_id; |
| 104 phase_ = phase; | 101 phase_ = phase; |
| 105 flags_ = flags; | 102 flags_ = flags; |
| 106 bind_id_ = bind_id; | 103 bind_id_ = bind_id; |
| 107 | 104 |
| 108 // Clamp num_args since it may have been set by a third_party library. | 105 // Clamp num_args since it may have been set by a third_party library. |
| 109 num_args = (num_args > kTraceMaxNumArgs) ? kTraceMaxNumArgs : num_args; | 106 num_args = (num_args > kTraceMaxNumArgs) ? kTraceMaxNumArgs : num_args; |
| 110 int i = 0; | 107 int i = 0; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 if ((flags_ & TRACE_EVENT_FLAG_FLOW_OUT) || | 361 if ((flags_ & TRACE_EVENT_FLAG_FLOW_OUT) || |
| 365 (flags_ & TRACE_EVENT_FLAG_FLOW_IN)) { | 362 (flags_ & TRACE_EVENT_FLAG_FLOW_IN)) { |
| 366 StringAppendF(out, ",\"bind_id\":\"0x%" PRIx64 "\"", | 363 StringAppendF(out, ",\"bind_id\":\"0x%" PRIx64 "\"", |
| 367 static_cast<uint64>(bind_id_)); | 364 static_cast<uint64>(bind_id_)); |
| 368 } | 365 } |
| 369 if (flags_ & TRACE_EVENT_FLAG_FLOW_IN) | 366 if (flags_ & TRACE_EVENT_FLAG_FLOW_IN) |
| 370 StringAppendF(out, ",\"flow_in\":true"); | 367 StringAppendF(out, ",\"flow_in\":true"); |
| 371 if (flags_ & TRACE_EVENT_FLAG_FLOW_OUT) | 368 if (flags_ & TRACE_EVENT_FLAG_FLOW_OUT) |
| 372 StringAppendF(out, ",\"flow_out\":true"); | 369 StringAppendF(out, ",\"flow_out\":true"); |
| 373 | 370 |
| 374 // Similar to id_, print the context_id as hex if present. | |
| 375 if (flags_ & TRACE_EVENT_FLAG_HAS_CONTEXT_ID) | |
| 376 StringAppendF(out, ",\"cid\":\"0x%" PRIx64 "\"", | |
| 377 static_cast<uint64>(context_id_)); | |
| 378 | |
| 379 // Instant events also output their scope. | 371 // Instant events also output their scope. |
| 380 if (phase_ == TRACE_EVENT_PHASE_INSTANT) { | 372 if (phase_ == TRACE_EVENT_PHASE_INSTANT) { |
| 381 char scope = '?'; | 373 char scope = '?'; |
| 382 switch (flags_ & TRACE_EVENT_FLAG_SCOPE_MASK) { | 374 switch (flags_ & TRACE_EVENT_FLAG_SCOPE_MASK) { |
| 383 case TRACE_EVENT_SCOPE_GLOBAL: | 375 case TRACE_EVENT_SCOPE_GLOBAL: |
| 384 scope = TRACE_EVENT_SCOPE_NAME_GLOBAL; | 376 scope = TRACE_EVENT_SCOPE_NAME_GLOBAL; |
| 385 break; | 377 break; |
| 386 | 378 |
| 387 case TRACE_EVENT_SCOPE_PROCESS: | 379 case TRACE_EVENT_SCOPE_PROCESS: |
| 388 scope = TRACE_EVENT_SCOPE_NAME_PROCESS; | 380 scope = TRACE_EVENT_SCOPE_NAME_PROCESS; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 416 AppendValueAsJSON(arg_types_[i], arg_values_[i], &value_as_text); | 408 AppendValueAsJSON(arg_types_[i], arg_values_[i], &value_as_text); |
| 417 | 409 |
| 418 *out << value_as_text; | 410 *out << value_as_text; |
| 419 } | 411 } |
| 420 *out << "}"; | 412 *out << "}"; |
| 421 } | 413 } |
| 422 } | 414 } |
| 423 | 415 |
| 424 } // namespace trace_event | 416 } // namespace trace_event |
| 425 } // namespace base | 417 } // namespace base |
| OLD | NEW |