diff options
author | Duncan Coutts <duncan@well-typed.com> | 2011-05-26 18:44:41 +0100 |
---|---|---|
committer | Duncan Coutts <duncan@well-typed.com> | 2011-05-26 18:47:38 +0100 |
commit | e8832eb9f05ca46d9315250c3baf7010eb0630a4 (patch) | |
tree | be08e88284b463362f14673175aedca35bcfcb8c /rts/eventlog | |
parent | 43c7d555c8d7eea6ba0d76bce33be8d25a01c6fd (diff) | |
download | haskell-e8832eb9f05ca46d9315250c3baf7010eb0630a4.tar.gz |
Emit various bits of OS process info into the eventlog
The process ID, parent process ID, rts name and version
The program arguments and environment.
Diffstat (limited to 'rts/eventlog')
-rw-r--r-- | rts/eventlog/EventLog.c | 86 | ||||
-rw-r--r-- | rts/eventlog/EventLog.h | 15 |
2 files changed, 100 insertions, 1 deletions
diff --git a/rts/eventlog/EventLog.c b/rts/eventlog/EventLog.c index b5c2ef63bb..abfb4eb4d9 100644 --- a/rts/eventlog/EventLog.c +++ b/rts/eventlog/EventLog.c @@ -79,7 +79,12 @@ char *EventDesc[] = { [EVENT_CAPSET_CREATE] = "Create capability set", [EVENT_CAPSET_DELETE] = "Delete capability set", [EVENT_CAPSET_ASSIGN_CAP] = "Add capability to capability set", - [EVENT_CAPSET_REMOVE_CAP] = "Remove capability from capability set" + [EVENT_CAPSET_REMOVE_CAP] = "Remove capability from capability set", + [EVENT_RTS_IDENTIFIER] = "RTS name and version", + [EVENT_PROGRAM_ARGS] = "Program arguments", + [EVENT_PROGRAM_ENV] = "Program environment variables", + [EVENT_OSPROCESS_PID] = "Process ID", + [EVENT_OSPROCESS_PPID] = "Parent process ID" }; // Event type. @@ -284,6 +289,12 @@ initEventLogging(void) sizeof(EventCapsetID) + sizeof(EventCapNo); break; + case EVENT_OSPROCESS_PID: // (cap, pid) + case EVENT_OSPROCESS_PPID: + eventTypes[t].size = + sizeof(EventCapsetID) + sizeof(StgWord32); + break; + case EVENT_SHUTDOWN: // (cap) case EVENT_REQUEST_SEQ_GC: // (cap) case EVENT_REQUEST_PAR_GC: // (cap) @@ -297,6 +308,9 @@ initEventLogging(void) case EVENT_LOG_MSG: // (msg) case EVENT_USER_MSG: // (msg) + case EVENT_RTS_IDENTIFIER: // (capset, str) + case EVENT_PROGRAM_ARGS: // (capset, strvec) + case EVENT_PROGRAM_ENV: // (capset, strvec) eventTypes[t].size = 0xffff; break; @@ -496,6 +510,12 @@ void postCapsetModifyEvent (EventTypeNum tag, postCapNo(&eventBuf, other /* capno */); break; } + case EVENT_OSPROCESS_PID: // (capset, pid) + case EVENT_OSPROCESS_PPID: // (capset, parent_pid) + { + postWord32(&eventBuf, other); + break; + } default: barf("postCapsetModifyEvent: unknown event tag %d", tag); } @@ -503,6 +523,70 @@ void postCapsetModifyEvent (EventTypeNum tag, RELEASE_LOCK(&eventBufMutex); } +void postCapsetStrEvent (EventTypeNum tag, + EventCapsetID capset, + char *msg) +{ + int strsize = strlen(msg); + int size = strsize + sizeof(EventCapsetID) + + ACQUIRE_LOCK(&eventBufMutex); + + if (!hasRoomForVariableEvent(&eventBuf, size)){ + printAndClearEventBuf(&eventBuf); + + if (!hasRoomForVariableEvent(&eventBuf, size)){ + // Event size exceeds buffer size, bail out: + RELEASE_LOCK(&eventBufMutex); + return; + } + } + + postEventHeader(&eventBuf, tag); + postPayloadSize(&eventBuf, size); + postCapsetID(&eventBuf, capset); + + postBuf(&eventBuf, (StgWord8*) msg, strsize); + + RELEASE_LOCK(&eventBufMutex); +} + +void postCapsetVecEvent (EventTypeNum tag, + EventCapsetID capset, + int argc, + char *argv[]) +{ + int i, size = sizeof(EventCapsetID); + + for (i = 0; i < argc; i++) { + // 1 + strlen to account for the trailing \0, used as separator + size += 1 + strlen(argv[i]); + } + + ACQUIRE_LOCK(&eventBufMutex); + + if (!hasRoomForVariableEvent(&eventBuf, size)){ + printAndClearEventBuf(&eventBuf); + + if(!hasRoomForVariableEvent(&eventBuf, size)){ + // Event size exceeds buffer size, bail out: + RELEASE_LOCK(&eventBufMutex); + return; + } + } + + postEventHeader(&eventBuf, tag); + postPayloadSize(&eventBuf, size); + postCapsetID(&eventBuf, capset); + + for( i = 0; i < argc; i++ ) { + // again, 1 + to account for \0 + postBuf(&eventBuf, (StgWord8*) argv[i], 1 + strlen(argv[i])); + } + + RELEASE_LOCK(&eventBufMutex); +} + void postEvent (Capability *cap, EventTypeNum tag) { diff --git a/rts/eventlog/EventLog.h b/rts/eventlog/EventLog.h index 116b532c1f..602ac2c87b 100644 --- a/rts/eventlog/EventLog.h +++ b/rts/eventlog/EventLog.h @@ -54,6 +54,21 @@ void postCapsetModifyEvent (EventTypeNum tag, EventCapsetID capset, StgWord32 other); +/* + * Post a capability set event with a string payload + */ +void postCapsetStrEvent (EventTypeNum tag, + EventCapsetID capset, + char *msg); + +/* + * Post a capability set event with several strings payload + */ +void postCapsetVecEvent (EventTypeNum tag, + EventCapsetID capset, + int argc, + char *msg[]); + #else /* !TRACING */ INLINE_HEADER void postSchedEvent (Capability *cap STG_UNUSED, |