Add trace event Pepper API

This facilitates adding trace data to chrome://tracing from plugins.

- broke out trace_event.h into trace_event.h/trace_event_internal.h
  for easier transplanting to plugin code by eliminating dependence on base/.
- inlined trace_event.cc methods (4 total) so the trace_event_internal
  implementation is contained in headers.
- added new PPB_TraceEvent_Dev interface (implemented entirely on the plugin side)

BUG=none
TEST=base unittests, manual for plugin testing


Review URL: https://chromiumcodereview.appspot.com/11464005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175233 0039d316-1c4b-4281-b951-d872f2087c98
parent 266c0e0e
......@@ -122,11 +122,11 @@
'debug/stack_trace_ios.mm',
'debug/stack_trace_posix.cc',
'debug/stack_trace_win.cc',
'debug/trace_event.cc',
'debug/trace_event.h',
'debug/trace_event_android.cc',
'debug/trace_event_impl.cc',
'debug/trace_event_impl.h',
'debug/trace_event_internal.h',
'debug/trace_event_win.cc',
'environment.cc',
'environment.h',
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/debug/trace_event.h"
namespace trace_event_internal {
void TraceEndOnScopeClose::Initialize(const unsigned char* category_enabled,
const char* name) {
data_.category_enabled = category_enabled;
data_.name = name;
p_data_ = &data_;
}
void TraceEndOnScopeClose::AddEventIfEnabled() {
// Only called when p_data_ is non-null.
if (*p_data_->category_enabled) {
TRACE_EVENT_API_ADD_TRACE_EVENT(
TRACE_EVENT_PHASE_END,
p_data_->category_enabled,
p_data_->name, kNoEventId,
kZeroNumArgs, NULL, NULL, NULL,
TRACE_EVENT_FLAG_NONE);
}
}
} // namespace trace_event_internal
This diff is collapsed.
This diff is collapsed.
/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/**
* This file defines the <code>PPB_Trace_Event</code> interface. It is meant
* to be used in plugins as the API that trace macros from trace_event.h use.
*/
label Chrome {
M25 = 0.1
};
interface PPB_Trace_Event_Dev {
/**
* Gets a pointer to a character for identifying a category name in the
* tracing system as well as for being able to early exit in client-side
* tracing code.
*
* NB: This mem_t return value should technically be const, but return values
* for Pepper IDL of mem_t type are not const. The same is true for the arg
* |category_enabled| for AddTraceEvent.
*/
mem_t GetCategoryEnabled([in] cstr_t category_name);
/**
* Adds a trace event to the platform tracing system. This function call is
* usually the result of a TRACE_* macro from trace_event.h when tracing and
* the category of the particular trace are enabled. It is not advisable to
* call this function on its own; it is really only meant to be used by the
* trace macros.
*/
void AddTraceEvent(
[in] int8_t phase,
[in] mem_t category_enabled,
[in] cstr_t name,
[in] uint64_t id,
[in] uint32_t num_args,
[in, size_as=num_args] str_t[] arg_names,
[in, size_as=num_args] uint8_t[] arg_types,
[in, size_as=num_args] uint64_t[] arg_values,
[in] uint8_t flags);
/**
* Sets the thread name of the calling thread in the tracing system so it will
* show up properly in chrome://tracing.
*/
void SetThreadName([in] cstr_t thread_name);
};
/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/* From dev/ppb_trace_event_dev.idl modified Wed Jan 2 16:11:35 2013. */
#ifndef PPAPI_C_DEV_PPB_TRACE_EVENT_DEV_H_
#define PPAPI_C_DEV_PPB_TRACE_EVENT_DEV_H_
#include "ppapi/c/pp_macros.h"
#include "ppapi/c/pp_stdint.h"
#define PPB_TRACE_EVENT_DEV_INTERFACE_0_1 "PPB_Trace_Event(Dev);0.1"
#define PPB_TRACE_EVENT_DEV_INTERFACE PPB_TRACE_EVENT_DEV_INTERFACE_0_1
/**
* @file
* This file defines the <code>PPB_Trace_Event</code> interface. It is meant
* to be used in plugins as the API that trace macros from trace_event.h use.
*/
/**
* @addtogroup Interfaces
* @{
*/
struct PPB_Trace_Event_Dev_0_1 {
/**
* Gets a pointer to a character for identifying a category name in the
* tracing system as well as for being able to early exit in client-side
* tracing code.
*
* NB: This mem_t return value should technically be const, but return values
* for Pepper IDL of mem_t type are not const. The same is true for the arg
* |category_enabled| for AddTraceEvent.
*/
void* (*GetCategoryEnabled)(const char* category_name);
/**
* Adds a trace event to the platform tracing system. This function call is
* usually the result of a TRACE_* macro from trace_event.h when tracing and
* the category of the particular trace are enabled. It is not advisable to
* call this function on its own; it is really only meant to be used by the
* trace macros.
*/
void (*AddTraceEvent)(int8_t phase,
const void* category_enabled,
const char* name,
uint64_t id,
uint32_t num_args,
const char* arg_names[],
const uint8_t arg_types[],
const uint64_t arg_values[],
uint8_t flags);
/**
* Sets the thread name of the calling thread in the tracing system so it will
* show up properly in chrome://tracing.
*/
void (*SetThreadName)(const char* thread_name);
};
typedef struct PPB_Trace_Event_Dev_0_1 PPB_Trace_Event_Dev;
/**
* @}
*/
#endif /* PPAPI_C_DEV_PPB_TRACE_EVENT_DEV_H_ */
......@@ -25,6 +25,7 @@
#include "ppapi/c/dev/ppb_scrollbar_dev.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/dev/ppb_text_input_dev.h"
#include "ppapi/c/dev/ppb_trace_event_dev.h"
#include "ppapi/c/dev/ppb_url_util_dev.h"
#include "ppapi/c/dev/ppb_video_capture_dev.h"
#include "ppapi/c/dev/ppb_video_decoder_dev.h"
......@@ -196,6 +197,7 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Testing_Dev_0_9;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Testing_Dev_0_91;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_TextInput_Dev_0_1;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_TextInput_Dev_0_2;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Trace_Event_Dev_0_1;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_URLUtil_Dev_0_6;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_VideoCapture_Dev_0_2;
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_VideoCapture_Dev_0_3;
......@@ -1976,6 +1978,8 @@ uint32_t Pnacl_M18_PPB_Testing_Dev_GetLiveVars(struct PP_Var live_vars[], uint32
/* Not generating wrapper methods for PPB_TextInput_Dev_0_2 */
/* Not generating wrapper methods for PPB_Trace_Event_Dev_0_1 */
/* Begin wrapper methods for PPB_URLUtil_Dev_0_6 */
static __attribute__((pnaclcall))
......@@ -3969,6 +3973,8 @@ struct PPB_Testing_Dev_0_91 Pnacl_Wrappers_PPB_Testing_Dev_0_91 = {
/* Not generating wrapper interface for PPB_TextInput_Dev_0_2 */
/* Not generating wrapper interface for PPB_Trace_Event_Dev_0_1 */
struct PPB_URLUtil_Dev_0_6 Pnacl_Wrappers_PPB_URLUtil_Dev_0_6 = {
.Canonicalize = (struct PP_Var (*)(struct PP_Var url, struct PP_URLComponents_Dev* components))&Pnacl_M17_PPB_URLUtil_Dev_Canonicalize,
.ResolveRelativeToURL = (struct PP_Var (*)(struct PP_Var base_url, struct PP_Var relative_string, struct PP_URLComponents_Dev* components))&Pnacl_M17_PPB_URLUtil_Dev_ResolveRelativeToURL,
......@@ -4807,6 +4813,12 @@ static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_TextInput_Dev_0_2 = {
.real_iface = NULL
};
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_Trace_Event_Dev_0_1 = {
.iface_macro = PPB_TRACE_EVENT_DEV_INTERFACE_0_1,
.wrapped_iface = NULL /* Still need slot for real_iface */,
.real_iface = NULL
};
static struct __PnaclWrapperInfo Pnacl_WrapperInfo_PPB_URLUtil_Dev_0_6 = {
.iface_macro = PPB_URLUTIL_DEV_INTERFACE_0_6,
.wrapped_iface = (void *) &Pnacl_Wrappers_PPB_URLUtil_Dev_0_6,
......@@ -5227,6 +5239,7 @@ static struct __PnaclWrapperInfo *s_ppb_wrappers[] = {
&Pnacl_WrapperInfo_PPB_Testing_Dev_0_91,
&Pnacl_WrapperInfo_PPB_TextInput_Dev_0_1,
&Pnacl_WrapperInfo_PPB_TextInput_Dev_0_2,
&Pnacl_WrapperInfo_PPB_Trace_Event_Dev_0_1,
&Pnacl_WrapperInfo_PPB_URLUtil_Dev_0_6,
&Pnacl_WrapperInfo_PPB_VideoCapture_Dev_0_2,
&Pnacl_WrapperInfo_PPB_VideoCapture_Dev_0_3,
......
......@@ -74,6 +74,8 @@
'shared_impl/ppb_opengles2_shared.h',
'shared_impl/ppb_resource_array_shared.cc',
'shared_impl/ppb_resource_array_shared.h',
'shared_impl/ppb_trace_event_impl.cc',
'shared_impl/ppb_trace_event_impl.h',
'shared_impl/ppb_url_util_shared.cc',
'shared_impl/ppb_url_util_shared.h',
'shared_impl/ppb_var_shared.cc',
......
......@@ -23,6 +23,7 @@
#include "ppapi/c/dev/ppb_resource_array_dev.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/dev/ppb_text_input_dev.h"
#include "ppapi/c/dev/ppb_trace_event_dev.h"
#include "ppapi/c/dev/ppb_url_util_dev.h"
#include "ppapi/c/dev/ppb_var_deprecated.h"
#include "ppapi/c/dev/ppb_video_capture_dev.h"
......
......@@ -6,6 +6,8 @@
#include <string>
#include "base/debug/trace_event.h"
#include "base/threading/platform_thread.h"
#include "ppapi/c/pp_errors.h"
#include "ppapi/c/ppb_input_event.h"
#include "ppapi/shared_impl/ppapi_globals.h"
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ppapi/shared_impl/ppb_trace_event_impl.h"
#include "base/debug/trace_event.h"
#include "ppapi/thunk/thunk.h"
namespace ppapi {
// PPB_Trace_Event_Dev is a shared implementation because Trace Events can be
// sent from either the plugin process or renderer process depending on whether
// the plugin is in- or out-of-process. Also, for NaCl plugins these functions
// will be executed from untrusted code and handled appropriately by tracing
// functionality in the IRT.
// static
void* TraceEventImpl::GetCategoryEnabled(const char* category_name) {
// This casting is here because all mem_t return types in Pepper are void* and
// non-const. All mem_t parameters are const void* so there is no way to
// return a pointer type to the caller without some const_cast. The pointer
// type the tracing system works with is normally unsigned char*.
return const_cast<void*>(static_cast<const void*>(
base::debug::TraceLog::GetInstance()->GetCategoryEnabled(category_name)));
}
// static
void TraceEventImpl::AddTraceEvent(int8_t phase,
const void* category_enabled,
const char* name,
uint64_t id,
uint32_t num_args,
const char* arg_names[],
const uint8_t arg_types[],
const uint64_t arg_values[],
uint8_t flags) {
base::debug::TraceLog::GetInstance()->AddTraceEvent(phase,
static_cast<const unsigned char*>(category_enabled), name, id, num_args,
arg_names, arg_types,
// This cast is necessary for LP64 systems, where uint64_t is defined as
// an unsigned long int, but trace_event internals are hermetic and
// accepts an |unsigned long long*|. The pointer types are compatible but
// the compiler throws an error without an explicit cast.
reinterpret_cast<const unsigned long long*>(arg_values), flags);
}
// static
void TraceEventImpl::SetThreadName(const char* thread_name) {
base::PlatformThread::SetName(thread_name);
}
namespace {
const PPB_Trace_Event_Dev g_ppb_trace_event_thunk = {
&TraceEventImpl::GetCategoryEnabled,
&TraceEventImpl::AddTraceEvent,
&TraceEventImpl::SetThreadName,
};
} // namespace ppapi
} // namespace
namespace ppapi {
namespace thunk {
const PPB_Trace_Event_Dev_0_1* GetPPB_Trace_Event_Dev_0_1_Thunk() {
return &g_ppb_trace_event_thunk;
}
} // namespace thunk
} // namespace ppapi
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PPAPI_SHARED_IMPL_PPB_TRACE_EVENT_IMPL_H_
#define PPAPI_SHARED_IMPL_PPB_TRACE_EVENT_IMPL_H_
#include "ppapi/c/dev/ppb_trace_event_dev.h"
#include "ppapi/c/pp_bool.h"
#include "ppapi/shared_impl/ppapi_shared_export.h"
namespace ppapi {
// Contains the implementation of the PPB_Trace_Event_Dev functions. Since these
// functions are to be run from whatever plugin process/thread in which they
// originated, the implementation lives in shared_impl.
//
class PPAPI_SHARED_EXPORT TraceEventImpl {
public:
static void* GetCategoryEnabled(const char* category_name);
static void AddTraceEvent(int8_t phase,
const void* category_enabled,
const char* name,
uint64_t id,
uint32_t num_args,
const char* arg_names[],
const uint8_t arg_types[],
const uint64_t arg_values[],
uint8_t flags);
static void SetThreadName(const char* thread_name);
};
} // namespace ppapi
#endif // PPAPI_SHARED_IMPL_PPB_TRACE_EVENT_IMPL_H_
......@@ -28,9 +28,11 @@
#include "ppapi/c/dev/ppb_scrollbar_dev.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/dev/ppb_text_input_dev.h"
#include "ppapi/c/dev/ppb_trace_event_dev.h"
#include "ppapi/c/dev/ppb_url_util_dev.h"
#include "ppapi/c/dev/ppb_var_deprecated.h"
#include "ppapi/c/dev/ppb_video_decoder_dev.h"
#include "ppapi/c/dev/ppb_view_dev.h"
#include "ppapi/c/dev/ppb_widget_dev.h"
#include "ppapi/c/dev/ppb_zoom_dev.h"
#include "ppapi/c/dev/ppp_class_deprecated.h"
......@@ -40,7 +42,6 @@
#include "ppapi/c/dev/ppp_selection_dev.h"
#include "ppapi/c/dev/ppp_text_input_dev.h"
#include "ppapi/c/dev/ppp_video_decoder_dev.h"
#include "ppapi/c/dev/ppb_view_dev.h"
#include "ppapi/c/dev/ppp_widget_dev.h"
#include "ppapi/c/dev/ppp_zoom_dev.h"
#include "ppapi/c/pp_bool.h"
......@@ -108,8 +109,8 @@
#include "ppapi/c/private/ppb_udp_socket_private.h"
#include "ppapi/c/private/ppb_uma_private.h"
#include "ppapi/c/private/ppb_x509_certificate_private.h"
#include "ppapi/c/private/ppp_instance_private.h"
#include "ppapi/c/private/ppp_content_decryptor_private.h"
#include "ppapi/c/private/ppp_instance_private.h"
#include "ppapi/c/trusted/ppb_audio_trusted.h"
#include "ppapi/c/trusted/ppb_file_io_trusted.h"
#include "ppapi/c/trusted/ppb_graphics_3d_trusted.h"
......
......@@ -31,6 +31,8 @@ PROXIED_IFACE(PPB_Instance, PPB_TEXTINPUT_DEV_INTERFACE_0_2,
PROXIED_IFACE(NoAPIName, PPB_VIEW_DEV_INTERFACE_0_1,
PPB_View_Dev_0_1)
UNPROXIED_IFACE(PPB_Instance, PPB_ZOOM_DEV_INTERFACE_0_2, PPB_Zoom_Dev_0_2)
PROXIED_IFACE(PPB_Instance, PPB_TRACE_EVENT_DEV_INTERFACE_0_1,
PPB_Trace_Event_Dev_0_1)
#if !defined(OS_NACL)
PROXIED_API(PPB_Buffer)
......
......@@ -32,6 +32,7 @@
#include "ppapi/c/dev/ppb_scrollbar_dev.h"
#include "ppapi/c/dev/ppb_testing_dev.h"
#include "ppapi/c/dev/ppb_text_input_dev.h"
#include "ppapi/c/dev/ppb_trace_event_dev.h"
#include "ppapi/c/dev/ppb_url_util_dev.h"
#include "ppapi/c/dev/ppb_var_deprecated.h"
#include "ppapi/c/dev/ppb_video_capture_dev.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment