aboutsummaryrefslogtreecommitdiffstats
path: root/mps/code
diff options
context:
space:
mode:
authorNick Barnes2012-10-30 14:15:27 +0000
committerNick Barnes2012-10-30 14:15:27 +0000
commitecd77595bbd6206a7f748623af299722d270c0bb (patch)
treec53b98961c7bbda0dbb76cf2b73c34f4142d5f73 /mps/code
parent1746c7583af93a392eb5ff566c41fc5a266f8ec2 (diff)
downloademacs-ecd77595bbd6206a7f748623af299722d270c0bb.tar.gz
emacs-ecd77595bbd6206a7f748623af299722d270c0bb.zip
Add mps_clocks_per_sec to the eventinit header, and put some header-checking code into eventcnv, so now we have at least a rudimentary check that a binary event log is readable.
Copied from Perforce Change: 180160 ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code')
-rw-r--r--mps/code/event.c5
-rw-r--r--mps/code/eventcnv.c65
-rw-r--r--mps/code/eventdef.h5
3 files changed, 64 insertions, 11 deletions
diff --git a/mps/code/event.c b/mps/code/event.c
index aeaeaba9c48..42c37d8113f 100644
--- a/mps/code/event.c
+++ b/mps/code/event.c
@@ -207,8 +207,9 @@ void EventInit(void)
207 EventKindControl = (Word)mps_lib_telemetry_control(); 207 EventKindControl = (Word)mps_lib_telemetry_control();
208 EventInternSerial = (Serial)1; /* 0 is reserved */ 208 EventInternSerial = (Serial)1; /* 0 is reserved */
209 (void)EventInternString(MPSVersion()); /* emit version */ 209 (void)EventInternString(MPSVersion()); /* emit version */
210 EVENT6(EventInit, EVENT_VERSION_MAJOR, EVENT_VERSION_MEDIAN, 210 EVENT7(EventInit, EVENT_VERSION_MAJOR, EVENT_VERSION_MEDIAN,
211 EVENT_VERSION_MINOR, EventCodeMAX, EventNameMAX, MPS_WORD_WIDTH); 211 EVENT_VERSION_MINOR, EventCodeMAX, EventNameMAX, MPS_WORD_WIDTH,
212 mps_clocks_per_sec());
212 /* flush these initial events to get the first ClockSync out. */ 213 /* flush these initial events to get the first ClockSync out. */
213 EventSync(); 214 EventSync();
214 } else { 215 } else {
diff --git a/mps/code/eventcnv.c b/mps/code/eventcnv.c
index d1c9de4d518..4ac57198b9c 100644
--- a/mps/code/eventcnv.c
+++ b/mps/code/eventcnv.c
@@ -46,18 +46,39 @@
46static EventClock eventTime; /* current event time */ 46static EventClock eventTime; /* current event time */
47static char *prog; /* program name */ 47static char *prog; /* program name */
48 48
49/* everror -- error signalling */ 49/* Errors and Warnings */
50 50
51static void everror(const char *format, ...) 51/* fevwarn -- flush stdout, write message to stderr */
52{
53 va_list args;
54 52
53static void fevwarn(const char *prefix, const char *format, va_list args)
54{
55 fflush(stdout); /* sync */ 55 fflush(stdout); /* sync */
56 fprintf(stderr, "%s: @", prog); 56 fprintf(stderr, "%s: %s @", prog, prefix);
57 EVENT_CLOCK_PRINT(stderr, eventTime); 57 EVENT_CLOCK_PRINT(stderr, eventTime);
58 va_start(args, format); 58 fprintf(stderr, " ");
59 vfprintf(stderr, format, args); 59 vfprintf(stderr, format, args);
60 fprintf(stderr, "\n"); 60 fprintf(stderr, "\n");
61}
62
63/* evwarn -- flush stdout, warn to stderr */
64
65static void evwarn(const char *format, ...)
66{
67 va_list args;
68
69 va_start(args, format);
70 fevwarn("Warning", format, args);
71 va_end(args);
72}
73
74/* everror -- flush stdout, mesage to stderr, exit */
75
76static void everror(const char *format, ...)
77{
78 va_list args;
79
80 va_start(args, format);
81 fevwarn("Error", format, args);
61 va_end(args); 82 va_end(args);
62 exit(EXIT_FAILURE); 83 exit(EXIT_FAILURE);
63} 84}
@@ -164,9 +185,37 @@ static void readLog(EventProc proc)
164 if (res != ResOK) everror("Truncated log"); 185 if (res != ResOK) everror("Truncated log");
165 eventTime = event->any.clock; 186 eventTime = event->any.clock;
166 code = event->any.code; 187 code = event->any.code;
188
189 /* Special handling for some events, prior to text output */
190
191 switch(code) {
192 case EventEventInitCode:
193 if ((event->EventInit.f0 != EVENT_VERSION_MAJOR) ||
194 (event->EventInit.f1 != EVENT_VERSION_MEDIAN) ||
195 (event->EventInit.f2 != EVENT_VERSION_MINOR))
196 evwarn("Event log version does not match: %d.%d.%d vs %d.%d.%d",
197 event->EventInit.f0,
198 event->EventInit.f1,
199 event->EventInit.f2,
200 EVENT_VERSION_MAJOR,
201 EVENT_VERSION_MEDIAN,
202 EVENT_VERSION_MINOR);
203
204 if (event->EventInit.f3 != EventCodeMAX)
205 evwarn("Event log may contain unknown events with codes from %d to %d",
206 EventCodeMAX+1, event->EventInit.f3);
207
208 if (event->EventInit.f5 != MPS_WORD_WIDTH)
209 /* This probably can't happen; other things will break
210 * before we get here */
211 evwarn("Event log has incompatible word width: %d instead of %d",
212 event->EventInit.f5,
213 MPS_WORD_WIDTH);
214 break;
215 }
167 216
168 EVENT_CLOCK_PRINT(stdout, eventTime); 217 EVENT_CLOCK_PRINT(stdout, eventTime);
169 printf(" %X", (unsigned)code); 218 printf(" %4X", (unsigned)code);
170 219
171 switch (code) { 220 switch (code) {
172#define EVENT_PARAM_PRINT(name, index, sort, ident) \ 221#define EVENT_PARAM_PRINT(name, index, sort, ident) \
@@ -176,6 +225,8 @@ static void readLog(EventProc proc)
176 EVENT_##name##_PARAMS(EVENT_PARAM_PRINT, name) \ 225 EVENT_##name##_PARAMS(EVENT_PARAM_PRINT, name) \
177 break; 226 break;
178 EVENT_LIST(EVENT_PRINT, X) 227 EVENT_LIST(EVENT_PRINT, X)
228 default:
229 evwarn("Unknown event code %d", code);
179 } 230 }
180 231
181 putchar('\n'); 232 putchar('\n');
diff --git a/mps/code/eventdef.h b/mps/code/eventdef.h
index 4e4fe899433..d2f8aeaf55f 100644
--- a/mps/code/eventdef.h
+++ b/mps/code/eventdef.h
@@ -37,7 +37,7 @@
37 */ 37 */
38 38
39#define EVENT_VERSION_MAJOR ((unsigned)1) 39#define EVENT_VERSION_MAJOR ((unsigned)1)
40#define EVENT_VERSION_MEDIAN ((unsigned)0) 40#define EVENT_VERSION_MEDIAN ((unsigned)1)
41#define EVENT_VERSION_MINOR ((unsigned)2) 41#define EVENT_VERSION_MINOR ((unsigned)2)
42 42
43 43
@@ -628,7 +628,8 @@
628 PARAM(X, 2, U, minor) /* EVENT_VERSION_MINOR */ \ 628 PARAM(X, 2, U, minor) /* EVENT_VERSION_MINOR */ \
629 PARAM(X, 3, U, maxCode) /* EventCodeMAX */ \ 629 PARAM(X, 3, U, maxCode) /* EventCodeMAX */ \
630 PARAM(X, 4, U, maxNameLen) /* EventNameMAX */ \ 630 PARAM(X, 4, U, maxNameLen) /* EventNameMAX */ \
631 PARAM(X, 5, U, wordWidth) /* MPS_WORD_WIDTH */ 631 PARAM(X, 5, U, wordWidth) /* MPS_WORD_WIDTH */ \
632 PARAM(X, 6, W, clocksPerSec) /* mps_clocks_per_sec() */
632 633
633#define EVENT_EventClockSync_PARAMS(PARAM, X) \ 634#define EVENT_EventClockSync_PARAMS(PARAM, X) \
634 PARAM(X, 0, W, clock) /* mps_clock() value */ 635 PARAM(X, 0, W, clock) /* mps_clock() value */