aboutsummaryrefslogtreecommitdiffstats
path: root/mps/code
diff options
context:
space:
mode:
authorRichard Brooksby2012-04-23 17:13:41 +0100
committerRichard Brooksby2012-04-23 17:13:41 +0100
commitdd4cefe55580a3268b64e901396fc46ff342fcab (patch)
tree17a0b46836a18917b224ef0f1413d1a39f9ca3f5 /mps/code
parent61890da12b3d0150f25b6edd783f320d957b223f (diff)
downloademacs-dd4cefe55580a3268b64e901396fc46ff342fcab.tar.gz
emacs-dd4cefe55580a3268b64e901396fc46ff342fcab.zip
Fixing unsigned longs in eventcnv but not column widths.
Copied from Perforce Change: 178026 ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code')
-rw-r--r--mps/code/eventcnv.c99
1 files changed, 56 insertions, 43 deletions
diff --git a/mps/code/eventcnv.c b/mps/code/eventcnv.c
index efc601c6507..a524fd56445 100644
--- a/mps/code/eventcnv.c
+++ b/mps/code/eventcnv.c
@@ -11,6 +11,7 @@
11#include "eventcom.h" 11#include "eventcom.h"
12#include "eventpro.h" 12#include "eventpro.h"
13#include "mpmtypes.h" 13#include "mpmtypes.h"
14#include "testlib.h" /* for ulongest_t and associated print formats */
14 15
15#include <stddef.h> /* for size_t */ 16#include <stddef.h> /* for size_t */
16#include <stdio.h> /* for printf */ 17#include <stdio.h> /* for printf */
@@ -60,14 +61,14 @@ static Bool partialLog = FALSE;
60static Word bucketSize = 0; 61static Word bucketSize = 0;
61 62
62 63
63/* error -- error signalling */ 64/* everror -- error signalling */
64 65
65static void error(const char *format, ...) 66static void everror(const char *format, ...)
66{ 67{
67 va_list args; 68 va_list args;
68 69
69 fflush(stdout); /* sync */ 70 fflush(stdout); /* sync */
70 fprintf(stderr, "%s: @%lu ", prog, (ulong)eventTime); 71 fprintf(stderr, "%s: @%"PRIuLONGEST" ", prog, (ulongest_t)eventTime);
71 va_start(args, format); 72 va_start(args, format);
72 vfprintf(stderr, format, args); 73 vfprintf(stderr, format, args);
73 fprintf(stderr, "\n"); 74 fprintf(stderr, "\n");
@@ -92,7 +93,7 @@ static void usage(void)
92static void usageError(void) 93static void usageError(void)
93{ 94{
94 usage(); 95 usage();
95 error("Bad usage"); 96 everror("Bad usage");
96} 97}
97 98
98 99
@@ -197,7 +198,7 @@ static void processEvent(EventProc proc, Event event, Word etime)
197 198
198 res = EventRecord(proc, event, etime); 199 res = EventRecord(proc, event, etime);
199 if (res != ResOK) 200 if (res != ResOK)
200 error("Can't record event: error %d.", res); 201 everror("Can't record event: error %d.", res);
201 switch(event->any.code) { 202 switch(event->any.code) {
202 default: 203 default:
203 break; 204 break;
@@ -239,11 +240,16 @@ static void printAddr(EventProc proc, Addr addr)
239 putchar(' '); 240 putchar(' ');
240 printStr(sym, (style == 'C')); 241 printStr(sym, (style == 'C'));
241 } else { 242 } else {
242 printf((style == '\0') ? " sym%05lX" : " \"sym %lX\"", 243 printf((style == '\0') ?
243 (ulong)label); 244 " sym%05"PRIXLONGEST :
245 " \"sym %"PRIXLONGEST"\"",
246 (ulongest_t)label);
244 } 247 }
245 } else 248 } else
246 printf((style != 'C') ? " %08lX" : " %lu", (ulong)addr); 249 printf(style != 'C' ?
250 " %0"PRIwLONGEST PRIXLONGEST :
251 " %"PRIuLONGEST,
252 (ulongest_t)addr);
247} 253}
248 254
249 255
@@ -289,13 +295,13 @@ static void reportBucketResults(Word bucketLimit)
289{ 295{
290 switch (style) { 296 switch (style) {
291 case '\0': 297 case '\0':
292 printf("%8lu:", (ulong)bucketLimit); 298 printf("%8"PRIuLONGEST":", (ulongest_t)bucketLimit);
293 break; 299 break;
294 case 'L': 300 case 'L':
295 printf("(%lX", (ulong)bucketLimit); 301 printf("(%"PRIXLONGEST, (ulongest_t)bucketLimit);
296 break; 302 break;
297 case 'C': 303 case 'C':
298 printf("%lu", (ulong)bucketLimit); 304 printf("%"PRIuLONGEST, (ulongest_t)bucketLimit);
299 break; 305 break;
300 } 306 }
301 if (reportEvents) { 307 if (reportEvents) {
@@ -333,16 +339,16 @@ static void printArg(EventProc proc,
333 if (style == 'C') putchar(','); 339 if (style == 'C') putchar(',');
334 printAddr(proc, *(Addr *)arg); 340 printAddr(proc, *(Addr *)arg);
335 } else 341 } else
336 printf(styleConv, (ulong)*(Addr *)arg); 342 printf(styleConv, (ulongest_t)*(Addr *)arg);
337 } break; 343 } break;
338 case 'P': { 344 case 'P': {
339 printf(styleConv, (ulong)*(void **)arg); 345 printf(styleConv, (ulongest_t)*(void **)arg);
340 } break; 346 } break;
341 case 'U': { 347 case 'U': {
342 printf(styleConv, (ulong)*(unsigned *)arg); 348 printf(styleConv, (ulongest_t)*(unsigned *)arg);
343 } break; 349 } break;
344 case 'W': { 350 case 'W': {
345 printf(styleConv, (ulong)*(Word *)arg); 351 printf(styleConv, (ulongest_t)*(Word *)arg);
346 } break; 352 } break;
347 case 'D': { 353 case 'D': {
348 switch (style) { 354 switch (style) {
@@ -359,7 +365,7 @@ static void printArg(EventProc proc,
359 putchar(' '); 365 putchar(' ');
360 printStr((EventStringStruct *)arg, (style == 'C' || style == 'L')); 366 printStr((EventStringStruct *)arg, (style == 'C' || style == 'L'));
361 } break; 367 } break;
362 default: error("Can't print format >%c<", argType); 368 default: everror("Can't print format >%c<", argType);
363 } 369 }
364} 370}
365 371
@@ -396,13 +402,13 @@ static void readLog(EventProc proc)
396 /* Init style. */ 402 /* Init style. */
397 switch (style) { 403 switch (style) {
398 case '\0': 404 case '\0':
399 styleConv = " %8lX"; break; 405 styleConv = " %8"PRIXLONGEST; break;
400 case 'C': 406 case 'C':
401 styleConv = ", %lu"; break; 407 styleConv = ", %"PRIuLONGEST; break;
402 case 'L': 408 case 'L':
403 styleConv = " %lX"; break; 409 styleConv = " %"PRIXLONGEST; break;
404 default: 410 default:
405 error("Unknown style code '%c'", style); 411 everror("Unknown style code '%c'", style);
406 } 412 }
407 413
408 while (TRUE) { /* loop for each event */ 414 while (TRUE) { /* loop for each event */
@@ -415,7 +421,7 @@ static void readLog(EventProc proc)
415 /* Read and parse event. */ 421 /* Read and parse event. */
416 res = EventRead(&event, proc); 422 res = EventRead(&event, proc);
417 if (res == ResFAIL) break; /* eof */ 423 if (res == ResFAIL) break; /* eof */
418 if (res != ResOK) error("Truncated log"); 424 if (res != ResOK) everror("Truncated log");
419 eventTime = event->any.clock; 425 eventTime = event->any.clock;
420 code = EventGetCode(event); 426 code = EventGetCode(event);
421 427
@@ -451,11 +457,11 @@ static void readLog(EventProc proc)
451 457
452 switch (style) { 458 switch (style) {
453 case '\0': 459 case '\0':
454 printf(" %8lu", (ulong)eventTime); break; 460 printf(" %8"PRIuLONGEST, (ulongest_t)eventTime); break;
455 case 'C': 461 case 'C':
456 printf(", %lu", (ulong)eventTime); break; 462 printf(", %"PRIuLONGEST, (ulongest_t)eventTime); break;
457 case 'L': 463 case 'L':
458 printf(" %lX", (ulong)eventTime); break; 464 printf(" %"PRIXLONGEST, (ulongest_t)eventTime); break;
459 } 465 }
460 466
461 switch (event->any.code) { 467 switch (event->any.code) {
@@ -463,17 +469,23 @@ static void readLog(EventProc proc)
463 switch (style) { 469 switch (style) {
464 case '\0': case 'C': { 470 case '\0': case 'C': {
465 EventString sym = LabelText(proc, event->aw.w1); 471 EventString sym = LabelText(proc, event->aw.w1);
466 printf((style == '\0') ? " %08lX " : ", %lu, ", 472 printf(style == '\0' ?
467 (ulong)event->aw.a0); 473 " %08"PRIXLONGEST" " :
474 ", %"PRIuLONGEST", ",
475 (ulongest_t)event->aw.a0);
468 if (sym != NULL) { 476 if (sym != NULL) {
469 printStr(sym, (style == 'C')); 477 printStr(sym, (style == 'C'));
470 } else { 478 } else {
471 printf((style == '\0') ? "sym %05lX" : "sym %lX\"", 479 printf(style == '\0' ?
472 (ulong)event->aw.w1); 480 "sym %05"PRIXLONGEST :
481 "sym %"PRIXLONGEST"\"",
482 (ulongest_t)event->aw.w1);
473 } 483 }
474 } break; 484 } break;
475 case 'L': { 485 case 'L': {
476 printf(" %lX %lX", (ulong)event->aw.a0, (ulong)event->aw.w1); 486 printf(" %"PRIXLONGEST" %"PRIXLONGEST,
487 (ulongest_t)event->aw.a0,
488 (ulongest_t)event->aw.w1);
477 } break; 489 } break;
478 } 490 }
479 } break; 491 } break;
@@ -481,16 +493,16 @@ static void readLog(EventProc proc)
481 switch (style) { 493 switch (style) {
482 case '\0': { 494 case '\0': {
483 if (event->pddwww.w3 == 0) { 495 if (event->pddwww.w3 == 0) {
484 printf(" %08lX 0 N/A N/A N/A N/A", 496 printf(" %08"PRIXLONGEST" 0 N/A N/A N/A N/A",
485 (ulong)event->pddwww.p0); 497 (ulongest_t)event->pddwww.p0);
486 } else { 498 } else {
487 double mean = event->pddwww.d1 / (double)event->pddwww.w3; 499 double mean = event->pddwww.d1 / (double)event->pddwww.w3;
488 /* .stddev: stddev = sqrt(meanSquared - mean^2), but see */ 500 /* .stddev: stddev = sqrt(meanSquared - mean^2), but see */
489 /* <code/meter.c#limitation.variance>. */ 501 /* <code/meter.c#limitation.variance>. */
490 double stddev = sqrt(fabs(event->pddwww.d2 502 double stddev = sqrt(fabs(event->pddwww.d2
491 - (mean * mean))); 503 - (mean * mean)));
492 printf(" %08lX %8u %8u %8u %#8.3g %#8.3g", 504 printf(" %08"PRIXLONGEST" %8u %8u %8u %#8.3g %#8.3g",
493 (ulong)event->pddwww.p0, (uint)event->pddwww.w3, 505 (ulongest_t)event->pddwww.p0, (uint)event->pddwww.w3,
494 (uint)event->pddwww.w4, (uint)event->pddwww.w5, 506 (uint)event->pddwww.w4, (uint)event->pddwww.w5,
495 mean, stddev); 507 mean, stddev);
496 } 508 }
@@ -505,7 +517,8 @@ static void readLog(EventProc proc)
505 (uint)event->pddwww.w5); 517 (uint)event->pddwww.w5);
506 } break; 518 } break;
507 case 'L': { 519 case 'L': {
508 printf(" %lX %#.10G %#.10G %X %X %X", (ulong)event->pddwww.p0, 520 printf(" %"PRIXLONGEST" %#.10G %#.10G %X %X %X",
521 (ulongest_t)event->pddwww.p0,
509 event->pddwww.d1, event->pddwww.d2, 522 event->pddwww.d1, event->pddwww.d2,
510 (uint)event->pddwww.w3, (uint)event->pddwww.w4, 523 (uint)event->pddwww.w3, (uint)event->pddwww.w4,
511 (uint)event->pddwww.w5); 524 (uint)event->pddwww.w5);
@@ -513,14 +526,14 @@ static void readLog(EventProc proc)
513 } 526 }
514 } break; 527 } break;
515 case EventPoolInit: { /* pool, arena, class */ 528 case EventPoolInit: { /* pool, arena, class */
516 printf(styleConv, (ulong)event->ppp.p0); 529 printf(styleConv, (ulongest_t)event->ppp.p0);
517 printf(styleConv, (ulong)event->ppp.p1); 530 printf(styleConv, (ulongest_t)event->ppp.p1);
518 /* class is a Pointer, but we label them, so call printAddr */ 531 /* class is a Pointer, but we label them, so call printAddr */
519 if (style != 'L') { 532 if (style != 'L') {
520 if (style == 'C') putchar(','); 533 if (style == 'C') putchar(',');
521 printAddr(proc, (Addr)event->ppp.p2); 534 printAddr(proc, (Addr)event->ppp.p2);
522 } else 535 } else
523 printf(styleConv, (ulong)event->ppp.p2); 536 printf(styleConv, (ulongest_t)event->ppp.p2);
524 } break; 537 } break;
525 default: 538 default:
526 for (i = 0; i < argCount; ++i) { 539 for (i = 0; i < argCount; ++i) {
@@ -565,7 +578,7 @@ static void readLog(EventProc proc)
565 if (eventEnabled[c]) 578 if (eventEnabled[c])
566 printf(" %04X %s\n", (unsigned)c, EventCode2Name(c)); 579 printf(" %04X %s\n", (unsigned)c, EventCode2Name(c));
567 if (bucketSize == 0) 580 if (bucketSize == 0)
568 printf("\nevent clock stopped at %lu\n", (ulong)eventTime); 581 printf("\nevent clock stopped at %"PRIuLONGEST"\n", (ulongest_t)eventTime);
569 } 582 }
570 } 583 }
571} 584}
@@ -602,9 +615,9 @@ int main(int argc, char *argv[])
602 /* GCC -ansi -pedantic -Werror on FreeBSD will fail here 615 /* GCC -ansi -pedantic -Werror on FreeBSD will fail here
603 * with the warning "statement with no effect". */ 616 * with the warning "statement with no effect". */
604 617
605 assert(CHECKCONV(ulong, Word)); 618 assert(CHECKCONV(ulongest_t, Word));
606 assert(CHECKCONV(ulong, Addr)); 619 assert(CHECKCONV(ulongest_t, Addr));
607 assert(CHECKCONV(ulong, void *)); 620 assert(CHECKCONV(ulongest_t, void *));
608 assert(CHECKCONV(unsigned, EventCode)); 621 assert(CHECKCONV(unsigned, EventCode));
609 assert(CHECKCONV(Addr, void *)); /* for labelled pointers */ 622 assert(CHECKCONV(Addr, void *)); /* for labelled pointers */
610#endif 623#endif
@@ -616,12 +629,12 @@ int main(int argc, char *argv[])
616 else { 629 else {
617 input = fopen(filename, "rb"); 630 input = fopen(filename, "rb");
618 if (input == NULL) 631 if (input == NULL)
619 error("unable to open \"%s\"\n", filename); 632 everror("unable to open \"%s\"\n", filename);
620 } 633 }
621 634
622 res = EventProcCreate(&proc, partialLog, logReader, (void *)input); 635 res = EventProcCreate(&proc, partialLog, logReader, (void *)input);
623 if (res != ResOK) 636 if (res != ResOK)
624 error("Can't init EventProc module: error %d.", res); 637 everror("Can't init EventProc module: error %d.", res);
625 638
626 readLog(proc); 639 readLog(proc);
627 640