From bf36f61bb4e9d2d942abde9d12525a0610033f13 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Fri, 31 Aug 2012 15:37:29 +0100 Subject: Avoid creating the telemetry output stream until there are events to log. Copied from Perforce Change: 179134 ServerID: perforce.ravenbrook.com --- mps/code/event.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'mps/code') diff --git a/mps/code/event.c b/mps/code/event.c index 29c38febcd0..7657e71cc37 100644 --- a/mps/code/event.c +++ b/mps/code/event.c @@ -32,6 +32,7 @@ SRCID(event, "$Id$"); static Bool eventInited = FALSE; +static Bool eventIOInited = FALSE; static mps_io_t eventIO; static Count eventUserCount; static Serial EventInternSerial; @@ -54,6 +55,19 @@ Res EventFlush(void) AVER(EventLast <= EventBuffer + EventBufferSIZE); size = (size_t)(EventBuffer + EventBufferSIZE - EventLast); + /* Checking the size avoids creating the event stream when the arena is + destroyed and no events have been logged. */ + if (size == 0) + return ResOK; + + /* Ensure the IO stream is open. We do this late so that no stream is + created if no events are enabled by telemetry control. */ + if (!eventIOInited) { + res = (Res)mps_io_create(&eventIO); + if(res != ResOK) return res; + eventIOInited = TRUE; + } + /* 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. */ @@ -84,8 +98,6 @@ Res EventSync(void) Res EventInit(void) { - Res res; - /* Make local enums for all event params in order to check that the indexes in the parameter definition macros are in order, and that parameter idents are unique. */ @@ -141,8 +153,6 @@ Res EventInit(void) /* Only if this is the first call. */ if(!eventInited) { /* See .trans.log */ AVER(EventLast == NULL); - res = (Res)mps_io_create(&eventIO); - if(res != ResOK) return res; EventLast = EventBuffer + EventBufferSIZE; eventUserCount = (Count)1; eventInited = TRUE; -- cgit v1.2.1