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