1/* Copyright (c) 2013 The Chromium 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/* XRay -- a simple profiler for Native Client */
6
7
8#ifndef LIBRARIES_XRAY_XRAY_H_
9#define LIBRARIES_XRAY_XRAY_H_
10
11#include <stdint.h>
12
13#ifndef XRAY_DISABLE_BROWSER_INTEGRATION
14#include "ppapi/c/ppb.h"
15#endif
16
17#if defined(__arm__)
18#undef XRAY
19#endif
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#define XRAY_NO_INSTRUMENT  __attribute__((no_instrument_function))
26#define XRAY_INLINE __attribute__((always_inline, no_instrument_function))
27
28#if defined(XRAY)
29
30/* Do not call __XRayAnnotate* directly; instead use the */
31/* XRayAnnotate() macros below. */
32XRAY_NO_INSTRUMENT void __XRayAnnotate(const char* str, ...)
33  __attribute__ ((format(printf, 1, 2)));
34XRAY_NO_INSTRUMENT void __XRayAnnotateFiltered(const uint32_t filter,
35  const char* str, ...) __attribute__ ((format(printf, 2, 3)));
36
37/* This is the beginning of the public XRay API */
38
39/* Ok if mapfilename is NULL, no symbols will be loaded.  On glibc builds,
40 * XRay will also attempt to populate the symbol table with dladdr()
41 */
42XRAY_NO_INSTRUMENT struct XRayTraceCapture* XRayInit(int stack_size,
43                                                     int buffer_size,
44                                                     int frame_count,
45                                                     const char* mapfilename);
46XRAY_NO_INSTRUMENT void XRayShutdown(struct XRayTraceCapture* capture);
47XRAY_NO_INSTRUMENT void XRayStartFrame(struct XRayTraceCapture* capture);
48XRAY_NO_INSTRUMENT void XRayEndFrame(struct XRayTraceCapture* capture);
49XRAY_NO_INSTRUMENT void XRaySetAnnotationFilter(
50    struct XRayTraceCapture* capture, uint32_t filter);
51XRAY_NO_INSTRUMENT void XRaySaveReport(struct XRayTraceCapture* capture,
52                                       const char* filename,
53                                       float percent_cutoff,
54                                       int cycle_cutoff);
55XRAY_NO_INSTRUMENT void XRayReport(struct XRayTraceCapture* capture,
56                                   FILE* f,
57                                   float percent_cutoff,
58                                   int ticks_cutoff);
59
60#ifndef XRAY_DISABLE_BROWSER_INTEGRATION
61XRAY_NO_INSTRUMENT void XRayBrowserTraceReport(
62    struct XRayTraceCapture* capture);
63XRAY_NO_INSTRUMENT void XRayRegisterBrowserInterface(
64    PPB_GetInterface get_browser_interface);
65#endif  /* XRAY_DISABLE_BROWSER_INTEGRATION */
66
67
68#if defined(XRAY_ANNOTATE)
69#define XRayAnnotate(...) __XRayAnnotate(__VA_ARGS__)
70#define XRayAnnotateFiltered(...) __XRayAnnotateFiltered(__VA_ARGS__)
71#else
72#define XRayAnnotate(...)
73#define XRayAnnotateFiltered(...)
74#endif
75/* This is the end of the public XRay API */
76
77#else  /* defined(XRAY) */
78
79/* Builds that don't define XRAY will use these 'null' functions instead. */
80
81#define XRayAnnotate(...)
82#define XRayAnnotateFiltered(...)
83
84inline struct XRayTraceCapture* XRayInit(int stack_size,
85                                         int buffer_size,
86                                         int frame_count,
87                                         const char* mapfilename) {
88  return NULL;
89}
90inline void XRayShutdown(struct XRayTraceCapture* capture) {}
91inline void XRayStartFrame(struct XRayTraceCapture* capture) {}
92inline void XRayEndFrame(struct XRayTraceCapture* capture) {}
93inline void XRaySetAnnotationFilter(struct XRayTraceCapture* capture,
94                                    uint32_t filter) {}
95inline void XRaySaveReport(struct XRayTraceCapture* capture,
96                           const char* filename,
97                           float percent_cutoff,
98                           int cycle_cutoff) {}
99inline void XRayReport(struct XRayTraceCapture* capture,
100                       FILE* f,
101                       float percent_cutoff,
102                       int ticks_cutoff) {}
103
104#ifndef XRAY_DISABLE_BROWSER_INTEGRATION
105inline void XRayBrowserTraceReport(struct XRayTraceCapture* capture) {}
106inline void XRayRegisterBrowserInterface(
107    PPB_GetInterface get_browser_interface) {}
108#endif  /* XRAY_DISABLE_BROWSER_INTEGRATION */
109
110
111#endif  /* defined(XRAY) */
112
113#ifdef __cplusplus
114}
115#endif
116
117#endif  /* LIBRARIES_XRAY_XRAY_H_ */
118