From 1746c7583af93a392eb5ff566c41fc5a266f8ec2 Mon Sep 17 00:00:00 2001 From: Nick Barnes Date: Tue, 30 Oct 2012 09:36:30 +0000 Subject: Make eventclocksync events, and output them once per buffer flush. Copied from Perforce Change: 180152 ServerID: perforce.ravenbrook.com --- mps/code/event.c | 37 ++++++++++++++++++++++++++++++++++--- mps/code/eventdef.h | 9 ++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) (limited to 'mps/code') diff --git a/mps/code/event.c b/mps/code/event.c index f88600df7e7..aeaeaba9c48 100644 --- a/mps/code/event.c +++ b/mps/code/event.c @@ -46,6 +46,31 @@ char *EventLast[EventKindLIMIT]; EventControlSet EventKindControl; /* Bit set used to control output. */ +/* A single event structure output once per buffer flush. */ +EventEventClockSyncStruct eventClockSyncStruct; + + +/* eventClockSync -- Populate and write the clock sync event. */ + +static Res eventClockSync(void) +{ + Res res; + size_t size; + + size= size_tAlignUp(sizeof(eventClockSyncStruct), MPS_PF_ALIGN); + eventClockSyncStruct.code = EventEventClockSyncCode; + eventClockSyncStruct.size = (EventSize)size; + EVENT_CLOCK(eventClockSyncStruct.clock); + eventClockSyncStruct.f0 = (Word)mps_clock(); + res = (Res)mps_io_write(eventIO, (void *)&eventClockSyncStruct, size); + if (res != ResOK) + goto failWrite; + + res = ResOK; +failWrite: + return res; +} + /* EventFlush -- flush event buffer to the event stream */ Res EventFlush(EventKind kind) @@ -78,7 +103,12 @@ Res EventFlush(EventKind kind) goto failCreate; eventIOInited = TRUE; } - + + /* Send an EventClockSync event */ + res = eventClockSync(); + if (res != ResOK) + goto failClockSync; + /* Writing might be faster if the size is aligned to a multiple of the C library or kernel's buffer size. We could pad out the buffer with a marker for this purpose. */ @@ -88,9 +118,8 @@ Res EventFlush(EventKind kind) goto failWrite; } - - res = ResOK; +failClockSync: failWrite: failCreate: @@ -180,6 +209,8 @@ void EventInit(void) (void)EventInternString(MPSVersion()); /* emit version */ EVENT6(EventInit, EVENT_VERSION_MAJOR, EVENT_VERSION_MEDIAN, EVENT_VERSION_MINOR, EventCodeMAX, EventNameMAX, MPS_WORD_WIDTH); + /* flush these initial events to get the first ClockSync out. */ + EventSync(); } else { ++eventUserCount; } diff --git a/mps/code/eventdef.h b/mps/code/eventdef.h index 456d230d8f8..4e4fe899433 100644 --- a/mps/code/eventdef.h +++ b/mps/code/eventdef.h @@ -38,7 +38,7 @@ #define EVENT_VERSION_MAJOR ((unsigned)1) #define EVENT_VERSION_MEDIAN ((unsigned)0) -#define EVENT_VERSION_MINOR ((unsigned)1) +#define EVENT_VERSION_MINOR ((unsigned)2) /* EVENT_LIST -- list of event types and general properties @@ -68,7 +68,7 @@ */ #define EventNameMAX ((size_t)19) -#define EventCodeMAX ((EventCode)0x0074) +#define EventCodeMAX ((EventCode)0x0075) #define EVENT_LIST(EVENT, X) \ /* 0123456789012345678 <- don't exceed without changing EventNameMAX */ \ @@ -180,7 +180,8 @@ EVENT(X, TraceBandAdvance , 0x0071, TRUE, Trace) \ EVENT(X, AWLDeclineTotal , 0x0072, TRUE, Trace) \ EVENT(X, AWLDeclineSeg , 0x0073, TRUE, Trace) \ - EVENT(X, EventInit , 0x0074, TRUE, Arena) + EVENT(X, EventInit , 0x0074, TRUE, Arena) \ + EVENT(X, EventClockSync , 0x0075, TRUE, Arena) /* Remember to update EventNameMAX and EventCodeMAX in eventcom.h! @@ -629,6 +630,8 @@ PARAM(X, 4, U, maxNameLen) /* EventNameMAX */ \ PARAM(X, 5, U, wordWidth) /* MPS_WORD_WIDTH */ +#define EVENT_EventClockSync_PARAMS(PARAM, X) \ + PARAM(X, 0, W, clock) /* mps_clock() value */ #endif /* eventdef_h */ -- cgit v1.2.1