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/debug/trace_event.h"
8 #include "ppapi/thunk/thunk.h"
13 // 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 // 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 // functionality in the IRT.
20 void* TraceEventImpl::GetCategoryEnabled(const char* category_name
) {
21 // 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 // 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 return const_cast<void*>(static_cast<const void*>(
26 base::debug::TraceLog::GetInstance()->GetCategoryEnabled(category_name
)));
30 void TraceEventImpl::AddTraceEvent(int8_t phase
,
31 const void* category_enabled
,
35 const char* arg_names
[],
36 const uint8_t arg_types
[],
37 const uint64_t arg_values
[],
39 base::debug::TraceLog::GetInstance()->AddTraceEvent(phase
,
40 static_cast<const unsigned char*>(category_enabled
), name
, id
, num_args
,
42 // This cast is necessary for LP64 systems, where uint64_t is defined as
43 // an unsigned long int, but trace_event internals are hermetic and
44 // accepts an |unsigned long long*|. The pointer types are compatible but
45 // the compiler throws an error without an explicit cast.
46 reinterpret_cast<const unsigned long long*>(arg_values
), NULL
, flags
);
50 void TraceEventImpl::SetThreadName(const char* thread_name
) {
51 base::PlatformThread::SetName(thread_name
);
56 const PPB_Trace_Event_Dev g_ppb_trace_event_thunk
= {
57 &TraceEventImpl::GetCategoryEnabled
,
58 &TraceEventImpl::AddTraceEvent
,
59 &TraceEventImpl::SetThreadName
,
69 const PPB_Trace_Event_Dev_0_1
* GetPPB_Trace_Event_Dev_0_1_Thunk() {
70 return &g_ppb_trace_event_thunk
;