1 | // Report stats. |
---|
2 | |
---|
3 | #include <stdio.h> |
---|
4 | |
---|
5 | #include "timer.h" |
---|
6 | |
---|
7 | struct 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 |
---|
21 | extern "C" struct mallinfo dlmallinfo (void); |
---|
22 | #endif |
---|
23 | extern "C" void mstats (void); // for Kingsley malloc. |
---|
24 | extern "C" void dlmalloc_stats (void); // for Doug Lea malloc. |
---|
25 | extern "C" void * sbrk (long); |
---|
26 | extern "C" void malloc_stats (void); // for Doug Lea malloc. |
---|
27 | |
---|
28 | int masMem;// FIX ME |
---|
29 | |
---|
30 | |
---|
31 | int totalAllocated; |
---|
32 | int maxAllocated; |
---|
33 | int totalRequested; |
---|
34 | int maxRequested; |
---|
35 | |
---|
36 | class TimeItAll { |
---|
37 | public: |
---|
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 | } |
---|
75 | private: |
---|
76 | Timer t; |
---|
77 | #ifdef WIN32 |
---|
78 | long initSpace; |
---|
79 | #endif |
---|
80 | }; |
---|
81 | |
---|
82 | TimeItAll timer; |
---|