Android NTP: Most visited tile clicks should have PageTransition.AUTO_BOOKMARK
[chromium-blink-merge.git] / ppapi / shared_impl / ppb_trace_event_impl.cc
blobaabc4f255467f5da49147e8efa5efff077f4cbe8
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/threading/platform_thread.h"
9 #include "base/trace_event/trace_event.h"
10 #include "ppapi/thunk/thunk.h"
12 namespace ppapi {
14 // PPB_Trace_Event_Dev is a shared implementation because Trace Events can be
15 // sent from either the plugin process or renderer process depending on whether
16 // the plugin is in- or out-of-process. Also, for NaCl plugins these functions
17 // will be executed from untrusted code and handled appropriately by tracing
18 // functionality in the IRT.
20 // static
21 void* TraceEventImpl::GetCategoryEnabled(const char* category_name) {
22 // This casting is here because all mem_t return types in Pepper are void* and
23 // non-const. All mem_t parameters are const void* so there is no way to
24 // return a pointer type to the caller without some const_cast. The pointer
25 // type the tracing system works with is normally unsigned char*.
26 return const_cast<void*>(static_cast<const void*>(
27 base::trace_event::TraceLog::GetInstance()->GetCategoryGroupEnabled(
28 category_name)));
31 // static
32 void TraceEventImpl::AddTraceEvent(int8_t phase,
33 const void* category_enabled,
34 const char* name,
35 uint64_t id,
36 uint32_t num_args,
37 const char* arg_names[],
38 const uint8_t arg_types[],
39 const uint64_t arg_values[],
40 uint8_t flags) {
42 static_assert(sizeof(unsigned long long) == sizeof(uint64_t),
43 "unexpected data type sizes");
45 base::trace_event::TraceLog::GetInstance()->AddTraceEvent(
46 phase,
47 static_cast<const unsigned char*>(category_enabled),
48 name,
49 id,
50 num_args,
51 arg_names,
52 arg_types,
53 // This cast is necessary for LP64 systems, where uint64_t is defined as
54 // an unsigned long int, but trace_event internals are hermetic and
55 // accepts an |unsigned long long*|. The pointer types are compatible but
56 // the compiler throws an error without an explicit cast.
57 reinterpret_cast<const unsigned long long*>(arg_values),
58 NULL,
59 flags);
62 // static
63 void TraceEventImpl::AddTraceEventWithThreadIdAndTimestamp(
64 int8_t phase,
65 const void* category_enabled,
66 const char* name,
67 uint64_t id,
68 int32_t thread_id,
69 int64_t timestamp,
70 uint32_t num_args,
71 const char* arg_names[],
72 const uint8_t arg_types[],
73 const uint64_t arg_values[],
74 uint8_t flags) {
75 base::trace_event::TraceLog::GetInstance()
76 ->AddTraceEventWithThreadIdAndTimestamp(
77 phase,
78 static_cast<const unsigned char*>(category_enabled),
79 name,
80 id,
81 trace_event_internal::kNoId,
82 thread_id,
83 base::TraceTicks::FromInternalValue(timestamp),
84 num_args,
85 arg_names,
86 arg_types,
87 // This cast is necessary for LP64 systems, where uint64_t is defined as
88 // an unsigned long int, but trace_event internals are hermetic and
89 // accepts an |unsigned long long*|. The pointer types are compatible but
90 // the compiler throws an error without an explicit cast.
91 reinterpret_cast<const unsigned long long*>(arg_values),
92 NULL,
93 flags);
96 // static
97 int64_t TraceEventImpl::Now() {
98 return base::TraceTicks::Now().ToInternalValue();
101 // static
102 void TraceEventImpl::SetThreadName(const char* thread_name) {
103 base::PlatformThread::SetName(thread_name);
106 namespace {
108 const PPB_Trace_Event_Dev_0_1 g_ppb_trace_event_thunk_0_1 = {
109 &TraceEventImpl::GetCategoryEnabled, &TraceEventImpl::AddTraceEvent,
110 &TraceEventImpl::SetThreadName, };
112 const PPB_Trace_Event_Dev_0_2 g_ppb_trace_event_thunk_0_2 = {
113 &TraceEventImpl::GetCategoryEnabled,
114 &TraceEventImpl::AddTraceEvent,
115 &TraceEventImpl::AddTraceEventWithThreadIdAndTimestamp,
116 &TraceEventImpl::Now,
117 &TraceEventImpl::SetThreadName, };
119 } // namespace ppapi
121 } // namespace
123 namespace ppapi {
124 namespace thunk {
126 const PPB_Trace_Event_Dev_0_1* GetPPB_Trace_Event_Dev_0_1_Thunk() {
127 return &g_ppb_trace_event_thunk_0_1;
130 const PPB_Trace_Event_Dev_0_2* GetPPB_Trace_Event_Dev_0_2_Thunk() {
131 return &g_ppb_trace_event_thunk_0_2;
134 } // namespace thunk
135 } // namespace ppapi