Remove redundant deinitialization code from HttpCache::Transaction.
[chromium-blink-merge.git] / ppapi / shared_impl / ppb_trace_event_impl.cc
blob80037d693c4d0279fb577f31e3e18acd0b5375a6
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"
13 namespace ppapi {
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.
21 // static
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(
29 category_name)));
32 // static
33 void TraceEventImpl::AddTraceEvent(
34 int8_t phase,
35 const void* category_enabled,
36 const char* name,
37 uint64_t id,
38 uint32_t num_args,
39 const char* arg_names[],
40 const uint8_t arg_types[],
41 const uint64_t arg_values[],
42 uint8_t flags) {
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,
48 arg_names, arg_types,
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);
56 // static
57 void TraceEventImpl::AddTraceEventWithThreadIdAndTimestamp(
58 int8_t phase,
59 const void* category_enabled,
60 const char* name,
61 uint64_t id,
62 int32_t thread_id,
63 int64_t timestamp,
64 uint32_t num_args,
65 const char* arg_names[],
66 const uint8_t arg_types[],
67 const uint64_t arg_values[],
68 uint8_t flags) {
69 base::debug::TraceLog::GetInstance()->AddTraceEventWithThreadIdAndTimestamp(
70 phase,
71 static_cast<const unsigned char*>(category_enabled), name, id,
72 thread_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);
82 // static
83 int64_t TraceEventImpl::Now() {
84 return base::TimeTicks::NowFromSystemTraceTime().ToInternalValue();
87 // static
88 void TraceEventImpl::SetThreadName(const char* thread_name) {
89 base::PlatformThread::SetName(thread_name);
92 namespace {
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,
108 } // namespace ppapi
110 } // namespace
112 namespace ppapi {
113 namespace thunk {
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;
123 } // namespace thunk
124 } // namespace ppapi