source: proiecte/swift/trunk/lib/hoard-371/src/heaplayers/stats.cpp @ 176

Last change on this file since 176 was 176, checked in by (none), 14 years ago
  • imported repo from "guagal"
File size: 2.0 KB
Line 
1// Report stats.
2
3#include <stdio.h>
4
5#include "timer.h"
6
7struct mallinfo {
8  int arena;    /* non-mmapped space allocated from system */
9  int ordblks;  /* number of free chunks */
10  int smblks;   /* number of fastbin blocks */
11  int hblks;    /* number of mmapped regions */
12  int hblkhd;   /* space in mmapped regions */
13  int usmblks;  /* maximum total allocated space */
14  int fsmblks;  /* space available in freed fastbin blocks */
15  int uordblks; /* total allocated space */
16  int fordblks; /* total free space */
17  int keepcost; /* top-most, releasable (via malloc_trim) space */
18};
19
20#if 1
21extern "C" struct mallinfo dlmallinfo (void);
22#endif
23extern "C" void mstats (void); // for Kingsley malloc.
24extern "C" void dlmalloc_stats (void); // for Doug Lea malloc.
25extern "C" void * sbrk (long);
26extern "C" void malloc_stats (void); // for Doug Lea malloc.
27
28int masMem;// FIX ME
29
30
31int totalAllocated;
32int maxAllocated;
33int totalRequested;
34int maxRequested;
35
36class TimeItAll {
37public:
38        TimeItAll (void) {
39                totalAllocated = 0;
40                maxAllocated = 0;
41                t.start();
42                // FIX ME
43                masMem = 0;
44#ifdef WIN32
45                initSpace = (long) sbrk(0);
46                //initSpace = CommittedSpace();
47#endif
48        }
49
50        ~TimeItAll (void) {
51                t.stop();
52#if 0
53                struct mallinfo mi = dlmallinfo();
54                printf ("Doug Lea Memory allocated = {total} %d, {non-mmapped} %d\n", mi.usmblks, mi.arena);
55#endif
56                double elapsed = (double) t;
57                printf ("Time elapsed = %f\n", elapsed);
58                printf ("Max allocated = %d\n", maxAllocated);
59                printf ("Max requested = %d\n", maxRequested);
60                printf ("Frag = %lf\n", (double) maxAllocated / (double) maxRequested);
61#ifdef WIN32
62                printf ("init space = %ld\n",  initSpace);
63                printf ("Sbrk report: %ld\n", (long) sbrk(0));
64#if 0
65                size_t diff = (size_t) wsbrk(8);
66                cout << "diff1 = " << diff << endl;
67                diff -= initSpace - 8;
68                cout << "diff = " << diff << endl;
69#endif
70#endif
71                malloc_stats();
72                fflush (stdout);
73//              dlmalloc_stats();
74        }
75private:
76        Timer t;
77#ifdef WIN32
78        long initSpace;
79#endif
80};
81
82TimeItAll timer;
Note: See TracBrowser for help on using the repository browser.