X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=rts%2Feventlog%2FEventLog.c;h=fec34b9647ece0f4b7122a84a6d039182bcf1c24;hb=a201afd3d2c4bef07e4e7682b129f60dbdde0e8a;hp=ede1615139e03926895b55b622a113d12670c446;hpb=015d3d46b6de2f95386a515a7d166d996a0416db;p=ghc-hetmet.git diff --git a/rts/eventlog/EventLog.c b/rts/eventlog/EventLog.c index ede1615..fec34b9 100644 --- a/rts/eventlog/EventLog.c +++ b/rts/eventlog/EventLog.c @@ -17,8 +17,17 @@ #include "Stats.h" #include "EventLog.h" -#include +#include #include +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_UNISTD_H +#include +#endif + +// PID of the process that writes to event_log_filename (#4512) +static pid_t event_log_pid = -1; static char *event_log_filename = NULL; @@ -165,15 +174,26 @@ initEventLogging(void) StgWord8 t, c; nat n_caps; - event_log_filename = stgMallocBytes(strlen(prog_name) + 10, + event_log_filename = stgMallocBytes(strlen(prog_name) + + 10 /* .%d */ + + 10 /* .eventlog */, "initEventLogging"); if (sizeof(EventDesc) / sizeof(char*) != NUM_EVENT_TAGS) { barf("EventDesc array has the wrong number of elements"); } - - sprintf(event_log_filename, "%s.eventlog", prog_name); - + + if (event_log_pid == -1) { // #4512 + // Single process + sprintf(event_log_filename, "%s.eventlog", prog_name); + event_log_pid = getpid(); + } else { + // Forked process, eventlog already started by the parent + // before fork + event_log_pid = getpid(); + sprintf(event_log_filename, "%s.%d.eventlog", prog_name, event_log_pid); + } + /* Open event log file for writing. */ if ((event_log_file = fopen(event_log_filename, "wb")) == NULL) { sysErrorBelch("initEventLogging: can't open %s", event_log_filename); @@ -235,12 +255,15 @@ initEventLogging(void) sizeof(EventThreadID) + sizeof(StgWord16); break; + case EVENT_STARTUP: // (cap count) + eventTypes[t].size = sizeof(EventCapNo); + break; + case EVENT_SHUTDOWN: // (cap) case EVENT_REQUEST_SEQ_GC: // (cap) case EVENT_REQUEST_PAR_GC: // (cap) case EVENT_GC_START: // (cap) case EVENT_GC_END: // (cap) - case EVENT_STARTUP: case EVENT_GC_IDLE: case EVENT_GC_WORK: case EVENT_GC_DONE: @@ -288,6 +311,10 @@ initEventLogging(void) for (c = 0; c < n_caps; ++c) { postBlockMarker(&capEventBuf[c]); } + +#ifdef THREADED_RTS + initMutex(&eventBufMutex); +#endif } void @@ -331,6 +358,22 @@ freeEventLogging(void) } } +void +flushEventLog(void) +{ + if (event_log_file != NULL) { + fflush(event_log_file); + } +} + +void +abortEventLogging(void) +{ + freeEventLogging(); + if (event_log_file != NULL) { + 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. @@ -448,9 +491,9 @@ void postCapMsg(Capability *cap, char *msg, va_list ap) postLogMsg(&capEventBuf[cap->no], EVENT_LOG_MSG, msg, ap); } -void postUserMsg(Capability *cap, char *msg) +void postUserMsg(Capability *cap, char *msg, va_list ap) { - postLogMsg(&capEventBuf[cap->no], EVENT_USER_MSG, msg, NULL); + postLogMsg(&capEventBuf[cap->no], EVENT_USER_MSG, msg, ap); } void closeBlockMarker (EventsBuf *ebuf)