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 "ppapi/shared_impl/ppb_trace_event_impl.h" | 5 #include "ppapi/shared_impl/ppb_trace_event_impl.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
10 #include "ppapi/thunk/thunk.h" | 10 #include "ppapi/thunk/thunk.h" |
11 | 11 |
12 | |
13 namespace ppapi { | 12 namespace ppapi { |
14 | 13 |
15 // PPB_Trace_Event_Dev is a shared implementation because Trace Events can be | 14 // PPB_Trace_Event_Dev is a shared implementation because Trace Events can be |
16 // sent from either the plugin process or renderer process depending on whether | 15 // sent from either the plugin process or renderer process depending on whether |
17 // the plugin is in- or out-of-process. Also, for NaCl plugins these functions | 16 // the plugin is in- or out-of-process. Also, for NaCl plugins these functions |
18 // will be executed from untrusted code and handled appropriately by tracing | 17 // will be executed from untrusted code and handled appropriately by tracing |
19 // functionality in the IRT. | 18 // functionality in the IRT. |
20 | 19 |
21 // static | 20 // static |
22 void* TraceEventImpl::GetCategoryEnabled(const char* category_name) { | 21 void* TraceEventImpl::GetCategoryEnabled(const char* category_name) { |
23 // This casting is here because all mem_t return types in Pepper are void* and | 22 // This casting is here because all mem_t return types in Pepper are void* and |
24 // non-const. All mem_t parameters are const void* so there is no way to | 23 // non-const. All mem_t parameters are const void* so there is no way to |
25 // return a pointer type to the caller without some const_cast. The pointer | 24 // return a pointer type to the caller without some const_cast. The pointer |
26 // type the tracing system works with is normally unsigned char*. | 25 // type the tracing system works with is normally unsigned char*. |
27 return const_cast<void*>(static_cast<const void*>( | 26 return const_cast<void*>(static_cast<const void*>( |
28 base::debug::TraceLog::GetInstance()->GetCategoryGroupEnabled( | 27 base::debug::TraceLog::GetInstance()->GetCategoryGroupEnabled( |
29 category_name))); | 28 category_name))); |
30 } | 29 } |
31 | 30 |
32 // static | 31 // static |
33 void TraceEventImpl::AddTraceEvent( | 32 void TraceEventImpl::AddTraceEvent(int8_t phase, |
34 int8_t phase, | 33 const void* category_enabled, |
35 const void* category_enabled, | 34 const char* name, |
36 const char* name, | 35 uint64_t id, |
37 uint64_t id, | 36 uint32_t num_args, |
38 uint32_t num_args, | 37 const char* arg_names[], |
39 const char* arg_names[], | 38 const uint8_t arg_types[], |
40 const uint8_t arg_types[], | 39 const uint64_t arg_values[], |
41 const uint64_t arg_values[], | 40 uint8_t flags) { |
42 uint8_t flags) { | |
43 | 41 |
44 COMPILE_ASSERT(sizeof(unsigned long long) == sizeof(uint64_t), msg); | 42 COMPILE_ASSERT(sizeof(unsigned long long) == sizeof(uint64_t), msg); |
45 | 43 |
46 base::debug::TraceLog::GetInstance()->AddTraceEvent(phase, | 44 base::debug::TraceLog::GetInstance()->AddTraceEvent( |
47 static_cast<const unsigned char*>(category_enabled), name, id, num_args, | 45 phase, |
48 arg_names, arg_types, | 46 static_cast<const unsigned char*>(category_enabled), |
| 47 name, |
| 48 id, |
| 49 num_args, |
| 50 arg_names, |
| 51 arg_types, |
49 // This cast is necessary for LP64 systems, where uint64_t is defined as | 52 // This cast is necessary for LP64 systems, where uint64_t is defined as |
50 // an unsigned long int, but trace_event internals are hermetic and | 53 // an unsigned long int, but trace_event internals are hermetic and |
51 // accepts an |unsigned long long*|. The pointer types are compatible but | 54 // accepts an |unsigned long long*|. The pointer types are compatible but |
52 // the compiler throws an error without an explicit cast. | 55 // the compiler throws an error without an explicit cast. |
53 reinterpret_cast<const unsigned long long*>(arg_values), NULL, flags); | 56 reinterpret_cast<const unsigned long long*>(arg_values), |
| 57 NULL, |
| 58 flags); |
54 } | 59 } |
55 | 60 |
56 // static | 61 // static |
57 void TraceEventImpl::AddTraceEventWithThreadIdAndTimestamp( | 62 void TraceEventImpl::AddTraceEventWithThreadIdAndTimestamp( |
58 int8_t phase, | 63 int8_t phase, |
59 const void* category_enabled, | 64 const void* category_enabled, |
60 const char* name, | 65 const char* name, |
61 uint64_t id, | 66 uint64_t id, |
62 int32_t thread_id, | 67 int32_t thread_id, |
63 int64_t timestamp, | 68 int64_t timestamp, |
64 uint32_t num_args, | 69 uint32_t num_args, |
65 const char* arg_names[], | 70 const char* arg_names[], |
66 const uint8_t arg_types[], | 71 const uint8_t arg_types[], |
67 const uint64_t arg_values[], | 72 const uint64_t arg_values[], |
68 uint8_t flags) { | 73 uint8_t flags) { |
69 base::debug::TraceLog::GetInstance()->AddTraceEventWithThreadIdAndTimestamp( | 74 base::debug::TraceLog::GetInstance()->AddTraceEventWithThreadIdAndTimestamp( |
70 phase, | 75 phase, |
71 static_cast<const unsigned char*>(category_enabled), name, id, | 76 static_cast<const unsigned char*>(category_enabled), |
| 77 name, |
| 78 id, |
72 thread_id, | 79 thread_id, |
73 base::TimeTicks::FromInternalValue(timestamp), | 80 base::TimeTicks::FromInternalValue(timestamp), |
74 num_args, arg_names, arg_types, | 81 num_args, |
| 82 arg_names, |
| 83 arg_types, |
75 // This cast is necessary for LP64 systems, where uint64_t is defined as | 84 // This cast is necessary for LP64 systems, where uint64_t is defined as |
76 // an unsigned long int, but trace_event internals are hermetic and | 85 // an unsigned long int, but trace_event internals are hermetic and |
77 // accepts an |unsigned long long*|. The pointer types are compatible but | 86 // accepts an |unsigned long long*|. The pointer types are compatible but |
78 // the compiler throws an error without an explicit cast. | 87 // the compiler throws an error without an explicit cast. |
79 reinterpret_cast<const unsigned long long*>(arg_values), NULL, flags); | 88 reinterpret_cast<const unsigned long long*>(arg_values), |
| 89 NULL, |
| 90 flags); |
80 } | 91 } |
81 | 92 |
82 // static | 93 // static |
83 int64_t TraceEventImpl::Now() { | 94 int64_t TraceEventImpl::Now() { |
84 return base::TimeTicks::NowFromSystemTraceTime().ToInternalValue(); | 95 return base::TimeTicks::NowFromSystemTraceTime().ToInternalValue(); |
85 } | 96 } |
86 | 97 |
87 // static | 98 // static |
88 void TraceEventImpl::SetThreadName(const char* thread_name) { | 99 void TraceEventImpl::SetThreadName(const char* thread_name) { |
89 base::PlatformThread::SetName(thread_name); | 100 base::PlatformThread::SetName(thread_name); |
90 } | 101 } |
91 | 102 |
92 namespace { | 103 namespace { |
93 | 104 |
94 const PPB_Trace_Event_Dev_0_1 g_ppb_trace_event_thunk_0_1 = { | 105 const PPB_Trace_Event_Dev_0_1 g_ppb_trace_event_thunk_0_1 = { |
95 &TraceEventImpl::GetCategoryEnabled, | 106 &TraceEventImpl::GetCategoryEnabled, &TraceEventImpl::AddTraceEvent, |
96 &TraceEventImpl::AddTraceEvent, | 107 &TraceEventImpl::SetThreadName, }; |
97 &TraceEventImpl::SetThreadName, | |
98 }; | |
99 | 108 |
100 const PPB_Trace_Event_Dev_0_2 g_ppb_trace_event_thunk_0_2 = { | 109 const PPB_Trace_Event_Dev_0_2 g_ppb_trace_event_thunk_0_2 = { |
101 &TraceEventImpl::GetCategoryEnabled, | 110 &TraceEventImpl::GetCategoryEnabled, |
102 &TraceEventImpl::AddTraceEvent, | 111 &TraceEventImpl::AddTraceEvent, |
103 &TraceEventImpl::AddTraceEventWithThreadIdAndTimestamp, | 112 &TraceEventImpl::AddTraceEventWithThreadIdAndTimestamp, |
104 &TraceEventImpl::Now, | 113 &TraceEventImpl::Now, |
105 &TraceEventImpl::SetThreadName, | 114 &TraceEventImpl::SetThreadName, }; |
106 }; | |
107 | 115 |
108 } // namespace ppapi | 116 } // namespace ppapi |
109 | 117 |
110 } // namespace | 118 } // namespace |
111 | 119 |
112 namespace ppapi { | 120 namespace ppapi { |
113 namespace thunk { | 121 namespace thunk { |
114 | 122 |
115 const PPB_Trace_Event_Dev_0_1* GetPPB_Trace_Event_Dev_0_1_Thunk() { | 123 const PPB_Trace_Event_Dev_0_1* GetPPB_Trace_Event_Dev_0_1_Thunk() { |
116 return &g_ppb_trace_event_thunk_0_1; | 124 return &g_ppb_trace_event_thunk_0_1; |
117 } | 125 } |
118 | 126 |
119 const PPB_Trace_Event_Dev_0_2* GetPPB_Trace_Event_Dev_0_2_Thunk() { | 127 const PPB_Trace_Event_Dev_0_2* GetPPB_Trace_Event_Dev_0_2_Thunk() { |
120 return &g_ppb_trace_event_thunk_0_2; | 128 return &g_ppb_trace_event_thunk_0_2; |
121 } | 129 } |
122 | 130 |
123 } // namespace thunk | 131 } // namespace thunk |
124 } // namespace ppapi | 132 } // namespace ppapi |
OLD | NEW |