summaryrefslogtreecommitdiff
path: root/rts/eventlog
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2015-08-31 22:00:10 +0200
committerBen Gamari <ben@smart-cactus.org>2015-09-05 10:54:44 +0200
commit96b986b669410cf4b6945d1039f9e16e54f4e53f (patch)
tree271f7417f6f02047b6403c16679fcbc99acae1a9 /rts/eventlog
parentc60c462f4cf4c25274e4fe13c313deb52f092c47 (diff)
downloadhaskell-96b986b669410cf4b6945d1039f9e16e54f4e53f.tar.gz
EventLog: Factor out ensureRoomFor*Event
Diffstat (limited to 'rts/eventlog')
-rw-r--r--rts/eventlog/EventLog.c124
1 files changed, 41 insertions, 83 deletions
diff --git a/rts/eventlog/EventLog.c b/rts/eventlog/EventLog.c
index 5f021a68b6..c55ac2c644 100644
--- a/rts/eventlog/EventLog.c
+++ b/rts/eventlog/EventLog.c
@@ -133,6 +133,9 @@ static void closeBlockMarker(EventsBuf *ebuf);
static StgBool hasRoomForEvent(EventsBuf *eb, EventTypeNum eNum);
static StgBool hasRoomForVariableEvent(EventsBuf *eb, nat payload_bytes);
+static void ensureRoomForEvent(EventsBuf *eb, EventTypeNum tag);
+static int ensureRoomForVariableEvent(EventsBuf *eb, StgWord16 size);
+
static inline void postWord8(EventsBuf *eb, StgWord8 i)
{
*(eb->pos++) = i;
@@ -546,6 +549,7 @@ abortEventLogging(void)
fclose(event_log_file);
}
}
+
/*
* Post an event message to the capability's eventlog buffer.
* If the buffer is full, prints out the buffer and clears it.
@@ -560,11 +564,7 @@ postSchedEvent (Capability *cap,
EventsBuf *eb;
eb = &capEventBuf[cap->no];
-
- if (!hasRoomForEvent(eb, tag)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(eb);
- }
+ ensureRoomForEvent(eb, tag);
postEventHeader(eb, tag);
@@ -612,11 +612,7 @@ postSparkEvent (Capability *cap,
EventsBuf *eb;
eb = &capEventBuf[cap->no];
-
- if (!hasRoomForEvent(eb, tag)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(eb);
- }
+ ensureRoomForEvent(eb, tag);
postEventHeader(eb, tag);
@@ -656,11 +652,7 @@ postSparkCountersEvent (Capability *cap,
EventsBuf *eb;
eb = &capEventBuf[cap->no];
-
- if (!hasRoomForEvent(eb, EVENT_SPARK_COUNTERS)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(eb);
- }
+ ensureRoomForEvent(eb, EVENT_SPARK_COUNTERS);
postEventHeader(eb, EVENT_SPARK_COUNTERS);
/* EVENT_SPARK_COUNTERS (crt,dud,ovf,cnv,gcd,fiz,rem) */
@@ -678,11 +670,7 @@ postCapEvent (EventTypeNum tag,
EventCapNo capno)
{
ACQUIRE_LOCK(&eventBufMutex);
-
- if (!hasRoomForEvent(&eventBuf, tag)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(&eventBuf);
- }
+ ensureRoomForEvent(&eventBuf, tag);
postEventHeader(&eventBuf, tag);
@@ -708,11 +696,7 @@ void postCapsetEvent (EventTypeNum tag,
StgWord info)
{
ACQUIRE_LOCK(&eventBufMutex);
-
- if (!hasRoomForEvent(&eventBuf, tag)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(&eventBuf);
- }
+ ensureRoomForEvent(&eventBuf, tag);
postEventHeader(&eventBuf, tag);
postCapsetID(&eventBuf, capset);
@@ -838,11 +822,7 @@ void postWallClockTime (EventCapsetID capset)
getUnixEpochTime(&sec, &nsec); /* Get the wall clock time */
ts = time_ns(); /* Get the eventlog timestamp */
-
- if (!hasRoomForEvent(&eventBuf, EVENT_WALL_CLOCK_TIME)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(&eventBuf);
- }
+ ensureRoomForEvent(&eventBuf, EVENT_WALL_CLOCK_TIME);
/* Normally we'd call postEventHeader(), but that generates its own
timestamp, so we go one level lower so we can write out the
@@ -869,11 +849,7 @@ void postHeapEvent (Capability *cap,
EventsBuf *eb;
eb = &capEventBuf[cap->no];
-
- if (!hasRoomForEvent(eb, tag)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(eb);
- }
+ ensureRoomForEvent(eb, tag);
postEventHeader(eb, tag);
@@ -900,11 +876,7 @@ void postEventHeapInfo (EventCapsetID heap_capset,
W_ blockSize)
{
ACQUIRE_LOCK(&eventBufMutex);
-
- if (!hasRoomForEvent(&eventBuf, EVENT_HEAP_INFO_GHC)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(&eventBuf);
- }
+ ensureRoomForEvent(&eventBuf, EVENT_HEAP_INFO_GHC);
postEventHeader(&eventBuf, EVENT_HEAP_INFO_GHC);
/* EVENT_HEAP_INFO_GHC (heap_capset, n_generations,
@@ -933,11 +905,7 @@ void postEventGcStats (Capability *cap,
EventsBuf *eb;
eb = &capEventBuf[cap->no];
-
- if (!hasRoomForEvent(eb, EVENT_GC_STATS_GHC)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(eb);
- }
+ ensureRoomForEvent(eb, EVENT_GC_STATS_GHC);
postEventHeader(eb, EVENT_GC_STATS_GHC);
/* EVENT_GC_STATS_GHC (heap_capset, generation,
@@ -958,11 +926,7 @@ void postTaskCreateEvent (EventTaskId taskId,
EventKernelThreadId tid)
{
ACQUIRE_LOCK(&eventBufMutex);
-
- if (!hasRoomForEvent(&eventBuf, EVENT_TASK_CREATE)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(&eventBuf);
- }
+ ensureRoomForEvent(&eventBuf, EVENT_TASK_CREATE);
postEventHeader(&eventBuf, EVENT_TASK_CREATE);
/* EVENT_TASK_CREATE (taskID, cap, tid) */
@@ -978,11 +942,7 @@ void postTaskMigrateEvent (EventTaskId taskId,
EventCapNo new_capno)
{
ACQUIRE_LOCK(&eventBufMutex);
-
- if (!hasRoomForEvent(&eventBuf, EVENT_TASK_MIGRATE)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(&eventBuf);
- }
+ ensureRoomForEvent(&eventBuf, EVENT_TASK_MIGRATE);
postEventHeader(&eventBuf, EVENT_TASK_MIGRATE);
/* EVENT_TASK_MIGRATE (taskID, cap, new_cap) */
@@ -996,11 +956,7 @@ void postTaskMigrateEvent (EventTaskId taskId,
void postTaskDeleteEvent (EventTaskId taskId)
{
ACQUIRE_LOCK(&eventBufMutex);
-
- if (!hasRoomForEvent(&eventBuf, EVENT_TASK_DELETE)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(&eventBuf);
- }
+ ensureRoomForEvent(&eventBuf, EVENT_TASK_DELETE);
postEventHeader(&eventBuf, EVENT_TASK_DELETE);
/* EVENT_TASK_DELETE (taskID) */
@@ -1015,12 +971,7 @@ postEvent (Capability *cap, EventTypeNum tag)
EventsBuf *eb;
eb = &capEventBuf[cap->no];
-
- if (!hasRoomForEvent(eb, tag)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(eb);
- }
-
+ ensureRoomForEvent(eb, tag);
postEventHeader(eb, tag);
}
@@ -1030,11 +981,7 @@ postEventAtTimestamp (Capability *cap, EventTimestamp ts, EventTypeNum tag)
EventsBuf *eb;
eb = &capEventBuf[cap->no];
-
- if (!hasRoomForEvent(eb, tag)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(eb);
- }
+ ensureRoomForEvent(eb, tag);
/* Normally we'd call postEventHeader(), but that generates its own
timestamp, so we go one level lower so we can write out
@@ -1056,10 +1003,7 @@ void postLogMsg(EventsBuf *eb, EventTypeNum type, char *msg, va_list ap)
size = BUF;
}
- if (!hasRoomForVariableEvent(eb, size)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(eb);
- }
+ ensureRoomForVariableEvent(eb, size);
postEventHeader(eb, type);
postPayloadSize(eb, size);
@@ -1081,11 +1025,7 @@ void postCapMsg(Capability *cap, char *msg, va_list ap)
void postEventStartup(EventCapNo n_caps)
{
ACQUIRE_LOCK(&eventBufMutex);
-
- if (!hasRoomForEvent(&eventBuf, EVENT_STARTUP)) {
- // Flush event buffer to make room for new event.
- printAndClearEventBuf(&eventBuf);
- }
+ ensureRoomForEvent(&eventBuf, EVENT_STARTUP);
// Post a STARTUP event with the number of capabilities
postEventHeader(&eventBuf, EVENT_STARTUP);
@@ -1161,9 +1101,7 @@ void closeBlockMarker (EventsBuf *ebuf)
void postBlockMarker (EventsBuf *eb)
{
- if (!hasRoomForEvent(eb, EVENT_BLOCK_MARKER)) {
- printAndClearEventBuf(eb);
- }
+ ensureRoomForEvent(eb, EVENT_BLOCK_MARKER);
closeBlockMarker(eb);
@@ -1240,6 +1178,26 @@ StgBool hasRoomForVariableEvent(EventsBuf *eb, nat payload_bytes)
}
}
+void ensureRoomForEvent(EventsBuf *eb, EventTypeNum tag)
+{
+ if (!hasRoomForEvent(eb, tag)) {
+ // Flush event buffer to make room for new event.
+ printAndClearEventBuf(eb);
+ }
+}
+
+int ensureRoomForVariableEvent(EventsBuf *eb, StgWord16 size)
+{
+ if (!hasRoomForVariableEvent(eb, size)) {
+ // Flush event buffer to make room for new event.
+ printAndClearEventBuf(eb);
+ if (!hasRoomForVariableEvent(eb, size))
+ return 1; // Not enough space
+ }
+ return 0;
+}
+
+
void postEventType(EventsBuf *eb, EventType *et)
{
StgWord8 d;