1 // Copyright (c) 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(const char * name)12 const unsigned char *GetTraceCategoryEnabledFlag(const char *name)
13 {
14     auto *platform = ANGLEPlatformCurrent();
15     ASSERT(platform);
16 
17     const unsigned char *categoryEnabledFlag =
18         platform->getTraceCategoryEnabledFlag(platform, name);
19     if (categoryEnabledFlag != nullptr)
20     {
21         return categoryEnabledFlag;
22     }
23 
24     static unsigned char disabled = 0;
25     return &disabled;
26 }
27 
AddTraceEvent(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)28 angle::TraceEventHandle AddTraceEvent(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     auto *platform = ANGLEPlatformCurrent();
39     ASSERT(platform);
40 
41     double timestamp = platform->monotonicallyIncreasingTime(platform);
42 
43     if (timestamp != 0)
44     {
45         angle::TraceEventHandle handle =
46             platform->addTraceEvent(platform, phase, categoryGroupEnabled, name, id, timestamp,
47                                     numArgs, argNames, argTypes, argValues, flags);
48         ASSERT(handle != 0);
49         return handle;
50     }
51 
52     return static_cast<angle::TraceEventHandle>(0);
53 }
54 
55 }  // namespace angle
56