1 #ifndef ANDROID_DVR_BENCHMARK_H_
2 #define ANDROID_DVR_BENCHMARK_H_
3
4 #include <stdio.h>
5 #include <time.h>
6
7 #include <cutils/trace.h>
8
9 #include <private/dvr/clock_ns.h>
10
11 // Set benchmark traces, using Android systrace.
12 //
13 // The simplest one-parameter version of btrace automatically sets the
14 // timestamp with the system clock. The other versions can optionally set the
15 // timestamp manually, or pass additional data to be written to the log line.
16 //
17 // Example:
18 // Btrace("Start execution");
19 // ... code to benchmark ...
20 // Btrace("End execution");
21 //
22 // Use compute_benchmarks.py
23 // with the trace path "Start execution,End execution",
24 // to report the elapsed time between the two calls.
25 //
26 // Btrace will either output to standard atrace, or to a file if specified.
27 // The versions BtraceData also allow an int64_t to be included in the trace.
28
29 // Btrace without data payload.
30 static inline void Btrace(const char* name, int64_t nanoseconds_monotonic);
31 static inline void Btrace(const char* name);
32 static inline void Btrace(FILE* file, const char* name,
33 int64_t nanoseconds_monotonic);
34 static inline void Btrace(FILE* file, const char* name);
35
36 // Btrace with data payload.
37 static inline void BtraceData(const char* name, int64_t nanoseconds_monotonic,
38 int64_t data);
39 static inline void BtraceData(const char* name, int64_t data);
40 static inline void BtraceData(FILE* file, const char* name,
41 int64_t nanoseconds_monotonic, int64_t data);
42 static inline void BtraceData(FILE* file, const char* name, int64_t data);
43
Btrace(const char * name,int64_t nanoseconds_monotonic)44 static inline void Btrace(const char* name, int64_t nanoseconds_monotonic) {
45 const int kLogMessageLength = 256;
46 char log_message[kLogMessageLength];
47 snprintf(log_message, kLogMessageLength, "#btrace#%s", name);
48 atrace_int64(ATRACE_TAG_WEBVIEW, log_message, nanoseconds_monotonic);
49 }
50
Btrace(const char * name)51 static inline void Btrace(const char* name) {
52 Btrace(name, android::dvr::GetSystemClockNs());
53 }
54
Btrace(FILE * file,const char * name,int64_t nanoseconds_monotonic)55 static inline void Btrace(FILE* file, const char* name,
56 int64_t nanoseconds_monotonic) {
57 fprintf(file, "#btrace#%s|%" PRId64 "\n", name, nanoseconds_monotonic);
58 }
59
Btrace(FILE * file,const char * name)60 static inline void Btrace(FILE* file, const char* name) {
61 Btrace(file, name, android::dvr::GetSystemClockNs());
62 }
63
BtraceData(const char * name,int64_t nanoseconds_monotonic,int64_t data)64 static inline void BtraceData(const char* name, int64_t nanoseconds_monotonic,
65 int64_t data) {
66 const int kLogMessageLength = 256;
67 char log_message[kLogMessageLength];
68 snprintf(log_message, kLogMessageLength, "#btrace#%s|%" PRId64, name, data);
69 atrace_int64(ATRACE_TAG_WEBVIEW, log_message, nanoseconds_monotonic);
70 }
71
BtraceData(const char * name,int64_t data)72 static inline void BtraceData(const char* name, int64_t data) {
73 BtraceData(name, android::dvr::GetSystemClockNs(), data);
74 }
75
BtraceData(FILE * file,const char * name,int64_t nanoseconds_monotonic,int64_t data)76 static inline void BtraceData(FILE* file, const char* name,
77 int64_t nanoseconds_monotonic, int64_t data) {
78 fprintf(file, "#btrace#%s|%" PRId64 "|%" PRId64 "\n", name, data,
79 nanoseconds_monotonic);
80 }
81
BtraceData(FILE * file,const char * name,int64_t data)82 static inline void BtraceData(FILE* file, const char* name, int64_t data) {
83 BtraceData(file, name, android::dvr::GetSystemClockNs(), data);
84 }
85
86 #endif // ANDROID_DVR_BENCHMARK_H_
87