File: done.c

package info (click to toggle)
mlton 20130715-3
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 60,900 kB
  • ctags: 69,386
  • sloc: xml: 34,418; ansic: 17,399; lisp: 2,879; makefile: 1,605; sh: 1,254; pascal: 256; python: 143; asm: 97
file content (97 lines) | stat: -rw-r--r-- 3,585 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* Copyright (C) 2012 Matthew Fluet.
 * Copyright (C) 1999-2008 Henry Cejtin, Matthew Fluet, Suresh
 *    Jagannathan, and Stephen Weeks.
 * Copyright (C) 1997-2000 NEC Research Institute.
 *
 * MLton is released under a BSD-style license.
 * See the file MLton-LICENSE for details.
 */

static void displayCol (FILE *out, size_t width, const char *s) {
  size_t extra;
  size_t i;
  size_t len;

  len = strlen (s);
  if (len < width) {
    extra = width - len;
    for (i = 0; i < extra; i++)
      fprintf (out, " ");
  }
  fprintf (out, "%s\t", s);
}

static void displayCollectionStats (FILE *out, const char *name, struct rusage *ru, 
                                    uintmax_t num, uintmax_t bytes) {
  uintmax_t ms;

  ms = rusageTime (ru);
  fprintf (out, "%s", name);
  displayCol (out, 7, uintmaxToCommaString (ms));
  displayCol (out, 7, uintmaxToCommaString (num));
  displayCol (out, 15, uintmaxToCommaString (bytes));
  displayCol (out, 15, 
              (ms > 0)
              ? uintmaxToCommaString ((uintmax_t)(1000.0 * (float)bytes/(float)ms))
              : "-");
  fprintf (out, "\n");
}

void GC_done (GC_state s) {
  FILE *out;

  enter (s);
  minorGC (s);
  out = stderr;
  if (s->controls.summary) {
    struct rusage ru_total;
    uintmax_t gcTime;
    uintmax_t totalTime;

    getrusage (RUSAGE_SELF, &ru_total);
    totalTime = rusageTime (&ru_total);
    gcTime = rusageTime (&s->cumulativeStatistics.ru_gc);
    fprintf (out, "GC type\t\ttime ms\t number\t\t  bytes\t      bytes/sec\n");
    fprintf (out, "-------------\t-------\t-------\t---------------\t---------------\n");
    displayCollectionStats
      (out, "copying\t\t", 
       &s->cumulativeStatistics.ru_gcCopying, 
       s->cumulativeStatistics.numCopyingGCs, 
       s->cumulativeStatistics.bytesCopied);
    displayCollectionStats
      (out, "mark-compact\t", 
       &s->cumulativeStatistics.ru_gcMarkCompact, 
       s->cumulativeStatistics.numMarkCompactGCs, 
       s->cumulativeStatistics.bytesMarkCompacted);
    displayCollectionStats
      (out, "minor\t\t",
       &s->cumulativeStatistics.ru_gcMinor, 
       s->cumulativeStatistics.numMinorGCs, 
       s->cumulativeStatistics.bytesCopiedMinor);
    fprintf (out, "total time: %s ms\n",
             uintmaxToCommaString (totalTime));
    fprintf (out, "total GC time: %s ms (%.1f%%)\n",
             uintmaxToCommaString (gcTime), 
             (0 == totalTime) 
             ? 0.0 
             : 100.0 * ((double) gcTime) / (double)totalTime);
    fprintf (out, "max pause time: %s ms\n",
             uintmaxToCommaString (s->cumulativeStatistics.maxPauseTime));
    fprintf (out, "total bytes allocated: %s bytes\n",
             uintmaxToCommaString (s->cumulativeStatistics.bytesAllocated));
    fprintf (out, "max bytes live: %s bytes\n",
             uintmaxToCommaString (s->cumulativeStatistics.maxBytesLive));
    fprintf (out, "max heap size: %s bytes\n", 
             uintmaxToCommaString (s->cumulativeStatistics.maxHeapSize));
    fprintf (out, "max stack size: %s bytes\n", 
             uintmaxToCommaString (s->cumulativeStatistics.maxStackSize));
    fprintf (out, "num cards marked: %s\n", 
             uintmaxToCommaString (s->cumulativeStatistics.numCardsMarked));
    fprintf (out, "bytes scanned: %s bytes\n",
             uintmaxToCommaString (s->cumulativeStatistics.bytesScannedMinor));
    fprintf (out, "bytes hash consed: %s bytes\n",
             uintmaxToCommaString (s->cumulativeStatistics.bytesHashConsed));
  }
  releaseHeap (s, &s->heap);
  releaseHeap (s, &s->secondaryHeap);
}