Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Simple trace backend |
| 3 | * |
| 4 | * Copyright IBM, Corp. 2010 |
| 5 | * |
| 6 | * This work is licensed under the terms of the GNU GPL, version 2. See |
| 7 | * the COPYING file in the top-level directory. |
| 8 | * |
| 9 | */ |
| 10 | |
Lluís | edb47ec | 2011-08-31 20:30:57 +0200 | [diff] [blame] | 11 | #ifndef TRACE_SIMPLE_H |
| 12 | #define TRACE_SIMPLE_H |
Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 13 | |
| 14 | #include <stdint.h> |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 15 | #include <stdbool.h> |
| 16 | #include <stdio.h> |
Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 17 | |
| 18 | typedef uint64_t TraceEventID; |
| 19 | |
Prerna Saxena | 22890ab | 2010-06-24 17:04:53 +0530 | [diff] [blame] | 20 | typedef struct { |
| 21 | const char *tp_name; |
| 22 | bool state; |
| 23 | } TraceEvent; |
| 24 | |
Stefan Weil | 0b2c508 | 2010-11-15 21:17:06 +0100 | [diff] [blame] | 25 | void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf); |
Stefan Hajnoczi | c5ceb52 | 2010-07-13 09:26:33 +0100 | [diff] [blame] | 26 | void st_set_trace_file_enabled(bool enable); |
| 27 | bool st_set_trace_file(const char *file); |
| 28 | void st_flush_trace_buffer(void); |
Stefan Hajnoczi | 26f7227 | 2010-05-22 19:24:51 +0100 | [diff] [blame] | 29 | |
Harsh Prateek Bora | 62bab73 | 2012-07-18 15:15:59 +0530 | [diff] [blame] | 30 | typedef struct { |
| 31 | unsigned int tbuf_idx; |
Harsh Prateek Bora | 62bab73 | 2012-07-18 15:15:59 +0530 | [diff] [blame] | 32 | unsigned int rec_off; |
| 33 | } TraceBufferRecord; |
| 34 | |
| 35 | /* Note for hackers: Make sure MAX_TRACE_LEN < sizeof(uint32_t) */ |
| 36 | #define MAX_TRACE_STRLEN 512 |
| 37 | /** |
| 38 | * Initialize a trace record and claim space for it in the buffer |
| 39 | * |
| 40 | * @arglen number of bytes required for arguments |
| 41 | */ |
| 42 | int trace_record_start(TraceBufferRecord *rec, TraceEventID id, size_t arglen); |
| 43 | |
| 44 | /** |
| 45 | * Append a 64-bit argument to a trace record |
| 46 | */ |
| 47 | void trace_record_write_u64(TraceBufferRecord *rec, uint64_t val); |
| 48 | |
| 49 | /** |
| 50 | * Append a string argument to a trace record |
| 51 | */ |
| 52 | void trace_record_write_str(TraceBufferRecord *rec, const char *s, uint32_t slen); |
| 53 | |
| 54 | /** |
| 55 | * Mark a trace record completed |
| 56 | * |
| 57 | * Don't append any more arguments to the trace record after calling this. |
| 58 | */ |
| 59 | void trace_record_finish(TraceBufferRecord *rec); |
| 60 | |
Lluís | edb47ec | 2011-08-31 20:30:57 +0200 | [diff] [blame] | 61 | #endif /* TRACE_SIMPLE_H */ |