Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
trace.h
Go to the documentation of this file.
1 
18 #ifndef ION_PORT_ANDROID_TRACE_H_
19 #define ION_PORT_ANDROID_TRACE_H_
20 
21 #include <errno.h>
22 #include <fcntl.h>
23 #include <stdint.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <sys/stat.h>
27 #include <sys/types.h>
28 #include <unistd.h>
29 
30 #include <android/log.h>
31 
48 #define ION_ATRACE_TAG_NEVER 0 // The "never" tag is never
49 #define ION_ATRACE_TAG_ALWAYS (1<<0) // The "always" tag is always
51 #define ION_ATRACE_TAG_GRAPHICS (1<<1)
53 #define ION_ATRACE_TAG_INPUT (1<<2)
54 #define ION_ATRACE_TAG_VIEW (1<<3)
55 #define ION_ATRACE_TAG_WEBVIEW (1<<4)
56 #define ION_ATRACE_TAG_WINDOW_MANAGER (1<<5)
57 #define ION_ATRACE_TAG_ACTIVITY_MANAGER (1<<6)
58 #define ION_ATRACE_TAG_SYNC_MANAGER (1<<7)
59 #define ION_ATRACE_TAG_AUDIO (1<<8)
60 #define ION_ATRACE_TAG_VIDEO (1<<9)
61 #define ION_ATRACE_TAG_CAMERA (1<<10)
62 #define ION_ATRACE_TAG_HAL (1<<11)
63 #define ION_ATRACE_TAG_APP (1<<12)
64 #define ION_ATRACE_TAG_RESOURCES (1<<13)
65 #define ION_ATRACE_TAG_DALVIK (1<<14)
66 #define ION_ATRACE_TAG_RS (1<<15)
67 #define ION_ATRACE_TAG_BIONIC (1<<16)
68 #define ION_ATRACE_TAG_POWER (1<<17)
69 #define ION_ATRACE_TAG_PACKAGE_MANAGER (1<<18)
70 #define ION_ATRACE_TAG_SYSTEM_SERVER (1<<19)
71 #define ION_ATRACE_TAG_LAST ION_ATRACE_TAG_SYSTEM_SERVER
72 
73 #define ION_ATRACE_TAG_NOT_READY (1LL << 63) // Reserved for use during
74 
76 #define ION_ATRACE_TAG_VALID_MASK \
77  ((ION_ATRACE_TAG_LAST - 1) | ION_ATRACE_TAG_LAST)
78 
79 #ifndef ION_ATRACE_TAG
80 #define ION_ATRACE_TAG ION_ATRACE_TAG_NEVER
81 #elif ION_ATRACE_TAG > ION_ATRACE_TAG_LAST
82 #error ION_ATRACE_TAG must be defined to be one of the tags defined in \
83  utils/Trace.h
84 #endif
85 
89 #define ION_ATRACE_CALL() \
90  ion::port::android::ScopedTrace ___tracer(ION_ATRACE_TAG, __FUNCTION__)
91 
95 #define ION_ATRACE_NAME(name) \
96  ion::port::android::ScopedTrace ___tracer(ION_ATRACE_TAG, name)
97 
100 #define ION_ATRACE_INT(name, value) \
101  ion::port::android::Tracer::traceCounter(ION_ATRACE_TAG, name, value)
102 
105 #define ION_ATRACE_ENABLED() \
106  ion::port::android::Tracer::isTagEnabled(ION_ATRACE_TAG)
107 
108 namespace ion {
109 namespace port {
110 namespace android {
111 
112 class Tracer {
113  public:
114  static uint64_t getEnabledTags() {
115  initIfNeeded();
116  return sEnabledTags;
117  }
118 
119  static inline bool isTagEnabled(uint64_t tag) {
120  initIfNeeded();
121  return true; // sEnabledTags & tag;
122  }
123 
124  static inline void traceCounter(uint64_t tag, const char* name,
125  int32_t value) {
126  if (isTagEnabled(tag)) {
127  char buf[1024];
128  snprintf(buf, 1024, "C|%d|%s|%d", getpid(), name, value); // NOLINT
129  write(sTraceFD, buf, strlen(buf));
130  }
131  }
132 
133  static inline void traceBegin(uint64_t tag, const char* name) {
134  if (isTagEnabled(tag)) {
135  char buf[1024];
136  size_t len = snprintf(buf, 1024, "B|%d|%s", getpid(), name); // NOLINT
137  write(sTraceFD, buf, len);
138  }
139  }
140 
141  static inline void traceEnd(uint64_t tag) {
142  if (isTagEnabled(tag)) {
143  char buf = 'E';
144  write(sTraceFD, &buf, 1);
145  }
146  }
147 
148  private:
149  static inline void initIfNeeded() {
150  init();
151  }
152 
153  static void changeCallback();
154 
158  static void init();
159 
161  static void loadSystemProperty();
162 
171  static volatile int32_t sIsReady;
172 
179  static int sTraceFD;
180 
191  static uint64_t sEnabledTags;
192 };
193 
194 class ScopedTrace {
195  public:
196  inline ScopedTrace(uint64_t tag, const char* name)
197  : mTag(tag) {
198  Tracer::traceBegin(mTag, name);
199  }
200 
201  inline virtual ~ScopedTrace() {
202  Tracer::traceEnd(mTag);
203  }
204 
205  private:
206  uint64_t mTag;
207 };
208 
209 }; // namespace android
210 }; // namespace port
211 }; // namespace ion
212 
213 #endif // ION_PORT_ANDROID_TRACE_H_
static void traceCounter(uint64_t tag, const char *name, int32_t value)
Definition: trace.h:124
double value
ScopedTrace(uint64_t tag, const char *name)
Definition: trace.h:196
std::string name
Definition: printer.cc:324
static bool isTagEnabled(uint64_t tag)
Definition: trace.h:119
static void traceEnd(uint64_t tag)
Definition: trace.h:141
static uint64_t getEnabledTags()
Definition: trace.h:114
static void traceBegin(uint64_t tag, const char *name)
Definition: trace.h:133