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
3 // found in the LICENSE file.
5 #include "ppapi/shared_impl/ppb_trace_event_impl.h"
7 #include "base/basictypes.h"
8 #include "base/debug/trace_event.h"
9 #include "base/threading/platform_thread.h"
10 #include "ppapi/thunk/thunk.h"
15 // 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
17 // 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
19 // functionality in the IRT.
22 void* TraceEventImpl::GetCategoryEnabled(const char* category_name
) {
23 // 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
25 // return a pointer type to the caller without some const_cast. The pointer
26 // type the tracing system works with is normally unsigned char*.
27 return const_cast<void*>(static_cast<const void*>(
28 base::debug::TraceLog::GetInstance()->GetCategoryGroupEnabled(
33 void TraceEventImpl::AddTraceEvent(
35 const void* category_enabled
,
39 const char* arg_names
[],
40 const uint8_t arg_types
[],
41 const uint64_t arg_values
[],
44 COMPILE_ASSERT(sizeof(unsigned long long) == sizeof(uint64_t), msg
);
46 base::debug::TraceLog::GetInstance()->AddTraceEvent(phase
,
47 static_cast<const unsigned char*>(category_enabled
), name
, id
, num_args
,
49 // 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
51 // accepts an |unsigned long long*|. The pointer types are compatible but
52 // the compiler throws an error without an explicit cast.
53 reinterpret_cast<const unsigned long long*>(arg_values
), NULL
, flags
);
57 void TraceEventImpl::AddTraceEventWithThreadIdAndTimestamp(
59 const void* category_enabled
,
65 const char* arg_names
[],
66 const uint8_t arg_types
[],
67 const uint64_t arg_values
[],
69 base::debug::TraceLog::GetInstance()->AddTraceEventWithThreadIdAndTimestamp(
71 static_cast<const unsigned char*>(category_enabled
), name
, id
,
73 base::TimeTicks::FromInternalValue(timestamp
),
74 num_args
, arg_names
, arg_types
,
75 // 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
77 // accepts an |unsigned long long*|. The pointer types are compatible but
78 // the compiler throws an error without an explicit cast.
79 reinterpret_cast<const unsigned long long*>(arg_values
), NULL
, flags
);
83 int64_t TraceEventImpl::Now() {
84 return base::TimeTicks::NowFromSystemTraceTime().ToInternalValue();
88 void TraceEventImpl::SetThreadName(const char* thread_name
) {
89 base::PlatformThread::SetName(thread_name
);
94 const PPB_Trace_Event_Dev_0_1 g_ppb_trace_event_thunk_0_1
= {
95 &TraceEventImpl::GetCategoryEnabled
,
96 &TraceEventImpl::AddTraceEvent
,
97 &TraceEventImpl::SetThreadName
,
100 const PPB_Trace_Event_Dev_0_2 g_ppb_trace_event_thunk_0_2
= {
101 &TraceEventImpl::GetCategoryEnabled
,
102 &TraceEventImpl::AddTraceEvent
,
103 &TraceEventImpl::AddTraceEventWithThreadIdAndTimestamp
,
104 &TraceEventImpl::Now
,
105 &TraceEventImpl::SetThreadName
,
115 const PPB_Trace_Event_Dev_0_1
* GetPPB_Trace_Event_Dev_0_1_Thunk() {
116 return &g_ppb_trace_event_thunk_0_1
;
119 const PPB_Trace_Event_Dev_0_2
* GetPPB_Trace_Event_Dev_0_2_Thunk() {
120 return &g_ppb_trace_event_thunk_0_2
;