summaryrefslogtreecommitdiff
path: root/includes/rts/EventLogWriter.h
blob: 73a2aec64c316697383d65a651ace1b423574545 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* -----------------------------------------------------------------------------
 *
 * (c) The GHC Team, 2008-2017
 *
 * Support for fast binary event logging.
 *
 * Do not #include this file directly: #include "Rts.h" instead.
 *
 * To understand the structure of the RTS headers, see the wiki:
 *   https://gitlab.haskell.org/ghc/ghc/wikis/commentary/source-tree/includes
 *
 * ---------------------------------------------------------------------------*/

#pragma once

#include <stddef.h>
#include <stdbool.h>

/*
 *  Abstraction for writing eventlog data.
 */
typedef struct {
    // Initialize an EventLogWriter (may be NULL)
    void (* initEventLogWriter) (void);

    // Write a series of events returning true on success.
    // Note that this may be called by multiple threads simultaneously.
    // The writer is responsible for concurrency control.
    bool (* writeEventLog) (void *eventlog, size_t eventlog_size);

    // Flush possibly existing buffers (may be NULL)
    // Note that this may be called by multiple threads simultaneously.
    // The writer is responsible for concurrency control.
    void (* flushEventLog) (void);

    // Close an initialized EventLogOutput (may be NULL)
    void (* stopEventLogWriter) (void);
} EventLogWriter;

/*
 * An EventLogWriter which writes eventlogs to
 * a file `program.eventlog`.
 */
extern const EventLogWriter FileEventLogWriter;

enum EventLogStatus {
  /* The runtime system wasn't compiled with eventlog support. */
  EVENTLOG_NOT_SUPPORTED,
  /* An EventLogWriter has not yet been configured */
  EVENTLOG_NOT_CONFIGURED,
  /* An EventLogWriter has been configured and is running. */
  EVENTLOG_RUNNING,
};

/*
 * Query whether the current runtime system supports eventlogging.
 */
enum EventLogStatus eventLogStatus(void);

/*
 * Initialize event logging using the given EventLogWriter.
 * Returns true on success or false if an EventLogWriter is already configured
 * or eventlogging isn't supported by the runtime.
 */
bool startEventLogging(const EventLogWriter *writer);

/*
 * Stop event logging and destroy the current EventLogWriter.
 */
void endEventLogging(void);

/*
 * Flush the eventlog. cap can be NULL if one is not held.
 */
void flushEventLog(Capability **cap);