2 * Copyright (c) 2009, 2010 Aggelos Economopoulos. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
14 * 3. Neither the name of The DragonFly Project nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific, prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 EVTR_TYPE_PROBE
= 0x1,
45 EVTR_TYPE_SYSINFO
= 0x4,
46 EVTR_TYPE_CPUINFO
= 0x5,
50 RB_ENTRY(evtr_thread
) rb_node
;
53 /* available for the user of the library, NULL if not set */
58 * This structure is used for interchange of data with
59 * the user of the library
61 typedef struct evtr_event
{
64 /* timestamp. Must be nondecreasing */
66 uint16_t ncpus
; /* EVTR_TYPE_SYSINFO */
67 struct evtr_cpuinfo
{ /* EVTR_TYPE_CPUINFO */
72 * Pointer to filename. NULL if n/a.
73 * For an event returned by the library,
74 * it is a pointer to storage allocated
75 * by the library that will be around
76 * until the call to evtr_close.
81 /* line number. 0 if n/a */
84 * Format string, also used to identify
85 * the event. Ownership rules are the same
90 * Data corresponding to the format string.
91 * For an event returned by the library,
92 * it is a pointer to an internal buffer
93 * that becomes invalid when the next record
94 * is returned. If the user wants to keep this
95 * data around, they must copy it.
98 /* Length of fmtdata */
100 /* Cpu on which the event occured */
103 * Thread, which generated the event (if applicable). The
104 * storage pointed to belongs to the library and may (even
105 * though it's highly unlikely) point to a different thread
106 * in the future. The user needs to copy it if they want
109 struct evtr_thread
*td
;
113 * Specifies which conditions to filter query results
114 * with. It is modified by the library and should
115 * not be touched after initialization.
117 typedef struct evtr_filter
{
118 int flags
; /* must be initialized to 0 */
120 * Which cpu we are interested in. -1 means
121 * any cpu. XXX: use mask? (note we could just
122 * do that internally)
126 * If the user sets fmt, only events with a format
127 * string identical to the one specified will be
128 * returned. This field is modified by the library.
138 typedef struct evtr
*evtr_t
;
140 int evtr_next_event(evtr_t
, evtr_event_t
);
141 evtr_t
evtr_open_read(FILE *);
142 evtr_t
evtr_open_write(FILE *);
143 void evtr_close(evtr_t
);
144 int evtr_dump_event(evtr_t
, evtr_event_t
);
145 int evtr_error(evtr_t
);
146 const char * evtr_errmsg(evtr_t
);
147 void evtr_event_data(evtr_event_t
, char *, size_t);
148 struct evtr_query
* evtr_query_init(evtr_t
, evtr_filter_t
, int);
149 void evtr_query_destroy(struct evtr_query
*);
150 int evtr_query_next(struct evtr_query
*, evtr_event_t
);
151 int evtr_last_event(evtr_t
, evtr_event_t
);
152 int evtr_rewind(evtr_t
);
154 int evtr_ncpus(evtr_t
);
155 int evtr_cpufreqs(evtr_t
, double *);
156 void evtr_set_debug(const char *);