simple.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #ifndef TRACE_SIMPLE_H
  11. #define TRACE_SIMPLE_H
  12. #include <stdint.h>
  13. #include <stdbool.h>
  14. #include <stdio.h>
  15. typedef uint64_t TraceEventID;
  16. typedef struct {
  17. const char *tp_name;
  18. bool state;
  19. } TraceEvent;
  20. void st_print_trace_file_status(FILE *stream, fprintf_function stream_printf);
  21. void st_set_trace_file_enabled(bool enable);
  22. bool st_set_trace_file(const char *file);
  23. void st_flush_trace_buffer(void);
  24. typedef struct {
  25. unsigned int tbuf_idx;
  26. unsigned int rec_off;
  27. } TraceBufferRecord;
  28. /* Note for hackers: Make sure MAX_TRACE_LEN < sizeof(uint32_t) */
  29. #define MAX_TRACE_STRLEN 512
  30. /**
  31. * Initialize a trace record and claim space for it in the buffer
  32. *
  33. * @arglen number of bytes required for arguments
  34. */
  35. int trace_record_start(TraceBufferRecord *rec, TraceEventID id, size_t arglen);
  36. /**
  37. * Append a 64-bit argument to a trace record
  38. */
  39. void trace_record_write_u64(TraceBufferRecord *rec, uint64_t val);
  40. /**
  41. * Append a string argument to a trace record
  42. */
  43. void trace_record_write_str(TraceBufferRecord *rec, const char *s, uint32_t slen);
  44. /**
  45. * Mark a trace record completed
  46. *
  47. * Don't append any more arguments to the trace record after calling this.
  48. */
  49. void trace_record_finish(TraceBufferRecord *rec);
  50. #endif /* TRACE_SIMPLE_H */