Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | /* Copyright (C) 2012,2017 Matthew Fluet. |
2 | * Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh | |
3 | * Jagannathan, and Stephen Weeks. | |
4 | * Copyright (C) 1997-2000 NEC Research Institute. | |
5 | * | |
6 | * MLton is released under a BSD-style license. | |
7 | * See the file MLton-LICENSE for details. | |
8 | */ | |
9 | ||
10 | static void displayCol (FILE *out, size_t width, const char *s) { | |
11 | size_t extra; | |
12 | size_t i; | |
13 | size_t len; | |
14 | ||
15 | len = strlen (s); | |
16 | if (len < width) { | |
17 | extra = width - len; | |
18 | for (i = 0; i < extra; i++) | |
19 | fprintf (out, " "); | |
20 | } | |
21 | fprintf (out, "%s\t", s); | |
22 | } | |
23 | ||
24 | static void displayCollectionStats (FILE *out, const char *name, struct rusage *ru, | |
25 | uintmax_t num, uintmax_t bytes) { | |
26 | uintmax_t ms; | |
27 | ||
28 | ms = rusageTime (ru); | |
29 | fprintf (out, "%s", name); | |
30 | displayCol (out, 7, uintmaxToCommaString (ms)); | |
31 | displayCol (out, 7, uintmaxToCommaString (num)); | |
32 | displayCol (out, 15, uintmaxToCommaString (bytes)); | |
33 | displayCol (out, 15, | |
34 | (ms > 0) | |
35 | ? uintmaxToCommaString ((uintmax_t)(1000.0 * (float)bytes/(float)ms)) | |
36 | : "-"); | |
37 | fprintf (out, "\n"); | |
38 | } | |
39 | ||
40 | void GC_done (GC_state s) { | |
41 | FILE *out; | |
42 | ||
43 | enter (s); | |
44 | minorGC (s); | |
45 | out = s->controls.summaryFile; | |
46 | if (s->controls.summary) { | |
47 | struct rusage ru_total; | |
48 | uintmax_t gcTime; | |
49 | uintmax_t totalTime; | |
50 | ||
51 | getrusage (RUSAGE_SELF, &ru_total); | |
52 | totalTime = rusageTime (&ru_total); | |
53 | gcTime = rusageTime (&s->cumulativeStatistics.ru_gc); | |
54 | fprintf (out, "GC type\t\ttime ms\t number\t\t bytes\t bytes/sec\n"); | |
55 | fprintf (out, "-------------\t-------\t-------\t---------------\t---------------\n"); | |
56 | displayCollectionStats | |
57 | (out, "copying\t\t", | |
58 | &s->cumulativeStatistics.ru_gcCopying, | |
59 | s->cumulativeStatistics.numCopyingGCs, | |
60 | s->cumulativeStatistics.bytesCopied); | |
61 | displayCollectionStats | |
62 | (out, "mark-compact\t", | |
63 | &s->cumulativeStatistics.ru_gcMarkCompact, | |
64 | s->cumulativeStatistics.numMarkCompactGCs, | |
65 | s->cumulativeStatistics.bytesMarkCompacted); | |
66 | displayCollectionStats | |
67 | (out, "minor\t\t", | |
68 | &s->cumulativeStatistics.ru_gcMinor, | |
69 | s->cumulativeStatistics.numMinorGCs, | |
70 | s->cumulativeStatistics.bytesCopiedMinor); | |
71 | fprintf (out, "total time: %s ms\n", | |
72 | uintmaxToCommaString (totalTime)); | |
73 | fprintf (out, "total GC time: %s ms (%.1f%%)\n", | |
74 | uintmaxToCommaString (gcTime), | |
75 | (0 == totalTime) | |
76 | ? 0.0 | |
77 | : 100.0 * ((double) gcTime) / (double)totalTime); | |
78 | fprintf (out, "max pause time: %s ms\n", | |
79 | uintmaxToCommaString (s->cumulativeStatistics.maxPauseTime)); | |
80 | fprintf (out, "total bytes allocated: %s bytes\n", | |
81 | uintmaxToCommaString (s->cumulativeStatistics.bytesAllocated)); | |
82 | fprintf (out, "max bytes live: %s bytes\n", | |
83 | uintmaxToCommaString (s->cumulativeStatistics.maxBytesLive)); | |
84 | fprintf (out, "max heap size: %s bytes\n", | |
85 | uintmaxToCommaString (s->cumulativeStatistics.maxHeapSize)); | |
86 | fprintf (out, "max stack size: %s bytes\n", | |
87 | uintmaxToCommaString (s->cumulativeStatistics.maxStackSize)); | |
88 | fprintf (out, "num cards marked: %s\n", | |
89 | uintmaxToCommaString (s->cumulativeStatistics.numCardsMarked)); | |
90 | fprintf (out, "bytes scanned: %s bytes\n", | |
91 | uintmaxToCommaString (s->cumulativeStatistics.bytesScannedMinor)); | |
92 | fprintf (out, "bytes hash consed: %s bytes\n", | |
93 | uintmaxToCommaString (s->cumulativeStatistics.bytesHashConsed)); | |
94 | } | |
95 | releaseHeap (s, &s->heap); | |
96 | releaseHeap (s, &s->secondaryHeap); | |
97 | } |