ppb_trace_event_impl.cc revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
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. 4 5#include "ppapi/shared_impl/ppb_trace_event_impl.h" 6 7#include "base/debug/trace_event.h" 8#include "ppapi/thunk/thunk.h" 9 10 11namespace ppapi { 12 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. 18 19// static 20void* 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()->GetCategoryGroupEnabled( 27 category_name))); 28} 29 30// static 31void TraceEventImpl::AddTraceEvent(int8_t phase, 32 const void* category_enabled, 33 const char* name, 34 uint64_t id, 35 uint32_t num_args, 36 const char* arg_names[], 37 const uint8_t arg_types[], 38 const uint64_t arg_values[], 39 uint8_t flags) { 40 base::debug::TraceLog::GetInstance()->AddTraceEvent(phase, 41 static_cast<const unsigned char*>(category_enabled), name, id, num_args, 42 arg_names, arg_types, 43 // 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 45 // accepts an |unsigned long long*|. The pointer types are compatible but 46 // the compiler throws an error without an explicit cast. 47 reinterpret_cast<const unsigned long long*>(arg_values), NULL, flags); 48} 49 50// static 51void TraceEventImpl::SetThreadName(const char* thread_name) { 52 base::PlatformThread::SetName(thread_name); 53} 54 55namespace { 56 57const PPB_Trace_Event_Dev g_ppb_trace_event_thunk = { 58 &TraceEventImpl::GetCategoryEnabled, 59 &TraceEventImpl::AddTraceEvent, 60 &TraceEventImpl::SetThreadName, 61}; 62 63} // namespace ppapi 64 65} // namespace 66 67namespace ppapi { 68namespace thunk { 69 70const PPB_Trace_Event_Dev_0_1* GetPPB_Trace_Event_Dev_0_1_Thunk() { 71 return &g_ppb_trace_event_thunk; 72} 73 74} // namespace thunk 75} // namespace ppapi 76