-
Notifications
You must be signed in to change notification settings - Fork 1
/
logger.c
86 lines (65 loc) · 1.58 KB
/
logger.c
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
76
77
78
79
80
81
82
83
84
85
86
#include "logger.h"
#include "timer.h"
#include <proto/exec.h>
#include <stdio.h>
#include <stdarg.h>
static BOOL paused = FALSE;
static BOOL verbose = FALSE;
static void logLineImpl(const char * fmt, va_list ap)
{
char buffer[16 * 1024];
char* ptr = buffer;
const int len = vsnprintf(buffer, sizeof(buffer), fmt, ap);
const double time = timer_get_elapsed_seconds();
while (TRUE) {
char serialBuffer[4 * 1024]; // Sashimi has 4k buffer
const size_t wantedToWrite = (size_t)snprintf(serialBuffer, sizeof(serialBuffer), "[%.6f] %s\n", time, ptr);
IExec->DebugPrintF("%s", serialBuffer);
if (wantedToWrite < sizeof(serialBuffer)) {
break;
}
ptr += sizeof(serialBuffer) - 1;
}
if (len >= (int)sizeof(buffer)) {
IExec->DebugPrintF("*** Line truncated: %d bytes buffer needed ***\n", len);
}
}
void logLine(const char * fmt, ...)
{
if (!paused) {
va_list ap;
va_start(ap, fmt);
logLineImpl(fmt, ap);
va_end(ap);
}
}
void logAlways(const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
logLineImpl(fmt, ap);
va_end(ap);
}
void logDebug(const char * fmt, ...)
{
if (verbose) {
va_list ap;
va_start(ap, fmt);
logLineImpl(fmt, ap);
va_end(ap);
}
}
void pause_log(void)
{
if (!paused) {
paused = TRUE;
IExec->DebugPrintF("glSnoop: tracing paused\n");
}
}
void resume_log(void)
{
if (paused) {
IExec->DebugPrintF("glSnoop: tracing resumed\n");
paused = FALSE;
}
}