update readme (#21797)
[mono-project.git] / mono / utils / mono-flight-recorder.h
blob092c8be2221b59ad5ec7e884e57ac2c036c17dab
1 /**
2 * \file
3 * A lightweight log storage medium with limited history
5 * Author:
6 * Alexander Kyte (alkyte@microsoft.com)
8 * (C) 2018 Microsoft, Inc.
11 #ifndef __MONO_FLIGHT_RECORDER__
12 #define __MONO_FLIGHT_RECORDER__
14 #include <glib.h>
15 #include <mono/utils/mono-coop-mutex.h>
17 typedef struct {
18 long counter; // The number of messages allocated thus far, acts like a global, monotonic clock
19 } MonoFlightRecorderHeader;
21 typedef struct {
22 MonoFlightRecorderHeader header;
23 gpointer payload [MONO_ZERO_LEN_ARRAY]; // We have a variably-sized payload
24 } MonoFlightRecorderItem;
26 typedef struct {
27 intptr_t cursor; // Signed, for sentinel value of -1
28 size_t max_count; // Maximum number of items in logger
29 size_t payload_size; // Size of data reserved for logging message
30 MonoCoopMutex mutex; // Not owned exclusively by us, used by api consumers too
31 MonoFlightRecorderItem *items [MONO_ZERO_LEN_ARRAY]; // The data of the history
32 } MonoFlightRecorder;
34 MonoCoopMutex *
35 mono_flight_recorder_mutex (MonoFlightRecorder *recorder);
37 MonoFlightRecorder *
38 mono_flight_recorder_init (size_t max_size, size_t payload_size);
40 void
41 mono_flight_recorder_free (MonoFlightRecorder *recorder);
43 void
44 mono_flight_recorder_append (MonoFlightRecorder *recorder, gpointer payload);
46 // Used to traverse the ring buffer in order of oldest to newest message
48 typedef struct {
49 intptr_t lowest_index;
50 intptr_t highest_index;
51 MonoFlightRecorder *recorder;
52 } MonoFlightRecorderIter;
54 // Mutex has to be held when called
55 void
56 mono_flight_recorder_iter_init (MonoFlightRecorder *recorder, MonoFlightRecorderIter *iter);
58 // Mutex has to be held when called
59 void
60 mono_flight_recorder_iter_destroy (MonoFlightRecorderIter *iter);
62 // Mutex has to be held when called
63 gboolean
64 mono_flight_recorder_iter_next (MonoFlightRecorderIter *iter, MonoFlightRecorderHeader *header, gpointer *payload);
66 #endif