benchmark.h revision e4eec20f6263f4a42ae462456f60ea6c4518bb0a
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 (currently in dreamos/system/core/applications), 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. 30static inline void Btrace(const char* name, int64_t nanoseconds_monotonic); 31static inline void Btrace(const char* name); 32static inline void Btrace(FILE* file, const char* name, 33 int64_t nanoseconds_monotonic); 34static inline void Btrace(FILE* file, const char* name); 35 36// Btrace with data payload. 37static inline void BtraceData(const char* name, int64_t nanoseconds_monotonic, 38 int64_t data); 39static inline void BtraceData(const char* name, int64_t data); 40static inline void BtraceData(FILE* file, const char* name, 41 int64_t nanoseconds_monotonic, int64_t data); 42static inline void BtraceData(FILE* file, const char* name, int64_t data); 43 44static 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 51static inline void Btrace(const char* name) { 52 Btrace(name, android::dvr::GetSystemClockNs()); 53} 54 55static 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 60static inline void Btrace(FILE* file, const char* name) { 61 Btrace(file, name, android::dvr::GetSystemClockNs()); 62} 63 64static 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 72static inline void BtraceData(const char* name, int64_t data) { 73 BtraceData(name, android::dvr::GetSystemClockNs(), data); 74} 75 76static 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 82static 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