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" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 int g_atrace_fd = -1; | 15 int g_atrace_fd = -1; |
16 const char* kATraceMarkerFile = "/sys/kernel/debug/tracing/trace_marker"; | 16 const char* kATraceMarkerFile = "/sys/kernel/debug/tracing/trace_marker"; |
17 | 17 |
18 } // namespace | 18 } // namespace |
19 | 19 |
20 namespace base { | 20 namespace base { |
21 namespace debug { | 21 namespace debug { |
22 | 22 |
23 // static | 23 void TraceLog::StartATrace() { |
24 void TraceLog::InitATrace() { | 24 AutoLock lock(lock_); |
25 DCHECK(g_atrace_fd == -1); | 25 if (g_atrace_fd == -1) { |
26 g_atrace_fd = open(kATraceMarkerFile, O_WRONLY | O_APPEND); | 26 g_atrace_fd = open(kATraceMarkerFile, O_WRONLY); |
27 if (g_atrace_fd == -1) | 27 if (g_atrace_fd == -1) |
28 LOG(WARNING) << "Couldn't open " << kATraceMarkerFile; | 28 LOG(WARNING) << "Couldn't open " << kATraceMarkerFile; |
| 29 } |
| 30 } |
| 31 |
| 32 void TraceLog::StopATrace() { |
| 33 AutoLock lock(lock_); |
| 34 if (g_atrace_fd != -1) { |
| 35 close(g_atrace_fd); |
| 36 g_atrace_fd = -1; |
| 37 } |
29 } | 38 } |
30 | 39 |
31 void TraceLog::SendToATrace(char phase, | 40 void TraceLog::SendToATrace(char phase, |
32 const char* category, | 41 const char* category, |
33 const char* name, | 42 const char* name, |
34 int num_args, | 43 int num_args, |
35 const char** arg_names, | 44 const char** arg_names, |
36 const unsigned char* arg_types, | 45 const unsigned char* arg_types, |
37 const unsigned long long* arg_values) { | 46 const unsigned long long* arg_values) { |
38 if (g_atrace_fd == -1) | 47 if (g_atrace_fd == -1) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 default: | 93 default: |
85 // Do nothing. | 94 // Do nothing. |
86 break; | 95 break; |
87 } | 96 } |
88 } | 97 } |
89 | 98 |
90 // Must be called with lock_ locked. | 99 // Must be called with lock_ locked. |
91 void TraceLog::ApplyATraceEnabledFlag(unsigned char* category_enabled) { | 100 void TraceLog::ApplyATraceEnabledFlag(unsigned char* category_enabled) { |
92 if (g_atrace_fd != -1) | 101 if (g_atrace_fd != -1) |
93 *category_enabled |= ATRACE_ENABLED; | 102 *category_enabled |= ATRACE_ENABLED; |
| 103 else |
| 104 *category_enabled &= ~ATRACE_ENABLED; |
94 } | 105 } |
95 | 106 |
96 } // namespace debug | 107 } // namespace debug |
97 } // namespace base | 108 } // namespace base |
OLD | NEW |