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 "base/debug/trace_event_impl.h" | 5 #include "base/debug/trace_event_impl.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 | 31 |
| 32 void TraceLog::StopATrace() { | 32 void TraceLog::StopATrace() { |
| 33 AutoLock lock(lock_); | 33 AutoLock lock(lock_); |
| 34 if (g_atrace_fd != -1) { | 34 if (g_atrace_fd != -1) { |
| 35 close(g_atrace_fd); | 35 close(g_atrace_fd); |
| 36 g_atrace_fd = -1; | 36 g_atrace_fd = -1; |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 void TraceLog::SendToATrace(char phase, | 40 void TraceLog::SendToATrace(char phase, |
| 41 const char* category, | 41 const char* category_group, |
| 42 const char* name, | 42 const char* name, |
| 43 int num_args, | 43 int num_args, |
| 44 const char** arg_names, | 44 const char** arg_names, |
| 45 const unsigned char* arg_types, | 45 const unsigned char* arg_types, |
| 46 const unsigned long long* arg_values) { | 46 const unsigned long long* arg_values) { |
| 47 if (g_atrace_fd == -1) | 47 if (g_atrace_fd == -1) |
| 48 return; | 48 return; |
| 49 | 49 |
| 50 switch (phase) { | 50 switch (phase) { |
| 51 case TRACE_EVENT_PHASE_BEGIN: | 51 case TRACE_EVENT_PHASE_BEGIN: |
| 52 case TRACE_EVENT_PHASE_INSTANT: { | 52 case TRACE_EVENT_PHASE_INSTANT: { |
| 53 std::string out = StringPrintf("B|%d|%s-%s", getpid(), category, name); | 53 std::string out = StringPrintf("B|%d|%s-%s", getpid(), category_group, |
|
nduca
2013/02/21 06:02:36
style nit - you could wrap this at the opening ( a
rterrazas
2013/02/25 05:55:02
Done.
| |
| 54 name); | |
| 54 for (int i = 0; i < num_args; ++i) { | 55 for (int i = 0; i < num_args; ++i) { |
| 55 out += (i == 0 ? '|' : ';'); | 56 out += (i == 0 ? '|' : ';'); |
| 56 out += arg_names[i]; | 57 out += arg_names[i]; |
| 57 out += '='; | 58 out += '='; |
| 58 TraceEvent::TraceValue value; | 59 TraceEvent::TraceValue value; |
| 59 value.as_uint = arg_values[i]; | 60 value.as_uint = arg_values[i]; |
| 60 std::string::size_type value_start = out.length(); | 61 std::string::size_type value_start = out.length(); |
| 61 TraceEvent::AppendValueAsJSON(arg_types[i], value, &out); | 62 TraceEvent::AppendValueAsJSON(arg_types[i], value, &out); |
| 62 // Remove the quotes which may confuse the atrace script. | 63 // Remove the quotes which may confuse the atrace script. |
| 63 ReplaceSubstringsAfterOffset(&out, value_start, "\\\"", "'"); | 64 ReplaceSubstringsAfterOffset(&out, value_start, "\\\"", "'"); |
| 64 ReplaceSubstringsAfterOffset(&out, value_start, "\"", ""); | 65 ReplaceSubstringsAfterOffset(&out, value_start, "\"", ""); |
| 65 // Replace chars used for separators with similar chars in the value. | 66 // Replace chars used for separators with similar chars in the value. |
| 66 std::replace(out.begin() + value_start, out.end(), ';', ','); | 67 std::replace(out.begin() + value_start, out.end(), ';', ','); |
| 67 std::replace(out.begin() + value_start, out.end(), '|', '!'); | 68 std::replace(out.begin() + value_start, out.end(), '|', '!'); |
| 68 } | 69 } |
| 69 write(g_atrace_fd, out.c_str(), out.size()); | 70 write(g_atrace_fd, out.c_str(), out.size()); |
| 70 | 71 |
| 71 if (phase != TRACE_EVENT_PHASE_INSTANT) | 72 if (phase != TRACE_EVENT_PHASE_INSTANT) |
| 72 break; | 73 break; |
| 73 // Fall through. Simulate an instance event with a pair of begin/end. | 74 // Fall through. Simulate an instance event with a pair of begin/end. |
| 74 } | 75 } |
| 75 case TRACE_EVENT_PHASE_END: { | 76 case TRACE_EVENT_PHASE_END: { |
| 76 // Though a single 'E' is enough, here append pid and name so that | 77 // Though a single 'E' is enough, here append pid and name so that |
| 77 // unpaired events can be found easily. | 78 // unpaired events can be found easily. |
| 78 std::string out = StringPrintf("E|%d|%s-%s", getpid(), category, name); | 79 std::string out = StringPrintf("E|%d|%s-%s", getpid(), category_group, |
| 80 name); | |
| 79 write(g_atrace_fd, out.c_str(), out.size()); | 81 write(g_atrace_fd, out.c_str(), out.size()); |
| 80 break; | 82 break; |
| 81 } | 83 } |
| 82 case TRACE_EVENT_PHASE_COUNTER: | 84 case TRACE_EVENT_PHASE_COUNTER: |
| 83 for (int i = 0; i < num_args; ++i) { | 85 for (int i = 0; i < num_args; ++i) { |
| 84 DCHECK(arg_types[i] == TRACE_VALUE_TYPE_INT); | 86 DCHECK(arg_types[i] == TRACE_VALUE_TYPE_INT); |
| 85 std::string out = StringPrintf( | 87 std::string out = StringPrintf( |
| 86 "C|%d|%s-%s-%s|%d", | 88 "C|%d|%s-%s-%s|%d", |
| 87 getpid(), category, name, | 89 getpid(), category_group, name, |
| 88 arg_names[i], static_cast<int>(arg_values[i])); | 90 arg_names[i], static_cast<int>(arg_values[i])); |
| 89 write(g_atrace_fd, out.c_str(), out.size()); | 91 write(g_atrace_fd, out.c_str(), out.size()); |
| 90 } | 92 } |
| 91 break; | 93 break; |
| 92 | 94 |
| 93 default: | 95 default: |
| 94 // Do nothing. | 96 // Do nothing. |
| 95 break; | 97 break; |
| 96 } | 98 } |
| 97 } | 99 } |
| 98 | 100 |
| 99 // Must be called with lock_ locked. | 101 // Must be called with lock_ locked. |
| 100 void TraceLog::ApplyATraceEnabledFlag(unsigned char* category_enabled) { | 102 void TraceLog::ApplyATraceEnabledFlag(unsigned char* category_group_enabled) { |
| 101 if (g_atrace_fd != -1) | 103 if (g_atrace_fd != -1) |
| 102 *category_enabled |= ATRACE_ENABLED; | 104 *category_group_enabled |= ATRACE_ENABLED; |
| 103 else | 105 else |
| 104 *category_enabled &= ~ATRACE_ENABLED; | 106 *category_group_enabled &= ~ATRACE_ENABLED; |
| 105 } | 107 } |
| 106 | 108 |
| 107 } // namespace debug | 109 } // namespace debug |
| 108 } // namespace base | 110 } // namespace base |
| OLD | NEW |