1 // Copyright 2012 The ANGLE Project 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 "common/event_tracer.h"
6
7 #include "common/debug.h"
8
9 namespace angle
10 {
11
GetTraceCategoryEnabledFlag(PlatformMethods * platform,const char * name)12 const unsigned char *GetTraceCategoryEnabledFlag(PlatformMethods *platform, const char *name)
13 {
14 ASSERT(platform);
15
16 const unsigned char *categoryEnabledFlag =
17 platform->getTraceCategoryEnabledFlag(platform, name);
18 if (categoryEnabledFlag != nullptr)
19 {
20 return categoryEnabledFlag;
21 }
22
23 static unsigned char disabled = 0;
24 return &disabled;
25 }
26
AddTraceEvent(PlatformMethods * platform,char phase,const unsigned char * categoryGroupEnabled,const char * name,unsigned long long id,int numArgs,const char ** argNames,const unsigned char * argTypes,const unsigned long long * argValues,unsigned char flags)27 angle::TraceEventHandle AddTraceEvent(PlatformMethods *platform,
28 char phase,
29 const unsigned char *categoryGroupEnabled,
30 const char *name,
31 unsigned long long id,
32 int numArgs,
33 const char **argNames,
34 const unsigned char *argTypes,
35 const unsigned long long *argValues,
36 unsigned char flags)
37 {
38 ASSERT(platform);
39
40 #if defined(ANGLE_TRACE_EVENTS_IGNORE_TIMESTAMP)
41 double timestamp = 1.0; // Value doesn't matter, not used by the callback.
42 #else
43 double timestamp = platform->monotonicallyIncreasingTime(platform);
44 #endif
45
46 if (timestamp != 0)
47 {
48 angle::TraceEventHandle handle =
49 platform->addTraceEvent(platform, phase, categoryGroupEnabled, name, id, timestamp,
50 numArgs, argNames, argTypes, argValues, flags);
51 return handle;
52 }
53
54 return static_cast<angle::TraceEventHandle>(0);
55 }
56
57 } // namespace angle
58