My Project
Loading...
Searching...
No Matches
omStats.c
Go to the documentation of this file.
1/*******************************************************************
2 * File: omStats.c
3 * Purpose: definitions of stats related stuff
4 * Author: obachman (Olaf Bachmann)
5 * Created: 11/99
6 *******************************************************************/
7#include <unistd.h>
8#include "omConfig.h"
9
10#ifdef HAVE_OMALLOC
11#include "omDefaultConfig.h"
12#include "omMalloc.h"
13#include "omalloc.h"
14
15
16omInfo_t om_Info = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
17
18unsigned long om_SbrkInit = 0;
19
21{
22#ifdef HAVE_SBRK
23 om_SbrkInit = (unsigned long) sbrk(0);
24#endif
25}
26
28{
29#ifdef OM_MALLOC_UPDATE_INFO
30 OM_MALLOC_UPDATE_INFO;
31#endif
32
33 /* this can happen, since sizes are added as requested, and
34 subtracted as the real size of the memory */
35 if (om_Info.CurrentBytesFromMalloc < 0)
36 om_Info.CurrentBytesFromMalloc = 0;
37
38 om_Info.UsedBytesFromValloc = omGetUsedBinBytes();
39 om_Info.AvailBytesFromValloc = om_Info.CurrentBytesFromValloc - om_Info.UsedBytesFromValloc;
40
41#ifdef OM_MALLOC_USED_BYTES
42 om_Info.UsedBytesMalloc = OM_MALLOC_USED_BYTES;
43#else
44 om_Info.UsedBytesMalloc = om_Info.CurrentBytesFromMalloc
45 -om_Info.InternalUsedBytesMalloc;
46#endif
47#ifdef OM_MALLOC_AVAIL_BYTES
48 om_Info.AvailBytesMalloc = OM_MALLOC_AVAIL_BYTES;
49#endif
50
51 om_Info.UsedBytes = om_Info.UsedBytesMalloc + om_Info.UsedBytesFromValloc;
52 om_Info.AvailBytes = om_Info.AvailBytesMalloc + om_Info.AvailBytesFromValloc;
53
54#ifdef OM_HAVE_VALLOC_MMAP
55 om_Info.CurrentBytesMmap = om_Info.CurrentBytesFromValloc;
56 om_Info.MaxBytesMmap = om_Info.MaxBytesFromValloc;
57#endif
58#ifdef OM_MALLOC_CURRENT_BYTES_MMAP
59 om_Info.CurrentBytesMmap += OM_MALLOC_CURRENT_BYTES_MMAP;
60#endif
61#ifdef OM_MALLOC_MAX_BYTES_MMAP
62 om_Info.MaxBytesMmap += OM_MALLOC_MAX_BYTES_MMAP;
63#endif
64
65#ifndef OM_MALLOC_CURRENT_BYTES_SBRK
66#ifdef HAVE_SBRK
67 if (om_SbrkInit)
68 {
69 om_Info.CurrentBytesSbrk = (unsigned long) sbrk(0) - om_SbrkInit;
70 if (om_Info.CurrentBytesSbrk > om_Info.MaxBytesSbrk)
71 om_Info.MaxBytesSbrk = om_Info.CurrentBytesSbrk;
72 }
73 else
74 {
75 om_SbrkInit = (unsigned long) sbrk(0);
76 }
77#endif
78#else
79 om_Info.CurrentBytesSbrk = OM_MALLOC_CURRENT_BYTES_SBRK;
80#ifdef OM_MALLOC_MAX_BYTES_SBRK
81 om_Info.MaxBytesSbrk = OM_MALLOC_MAX_BYTES_SBRK;
82#else
83 if (om_Info.CurrentBytesSbrk > om_Info.MaxBytesSbrk)
84 om_Info.MaxBytesSbrk = om_Info.CurrentBytesSbrk;
85#endif
86#endif
87
88#ifdef OM_MALLOC_CURRENT_BYTES_SYSTEM
89 om_Info.CurrentBytesSystem = OM_MALLOC_CURRENT_BYTES_SYSTEM;
90#else
91 om_Info.CurrentBytesSystem =
92 (om_Info.CurrentBytesSbrk > om_Info.UsedBytesMalloc ?
93 om_Info.CurrentBytesSbrk : om_Info.UsedBytesMalloc);
94#endif
95#ifdef OM_HAVE_VALLOC_MMAP
96 om_Info.CurrentBytesSystem += om_Info.CurrentBytesFromValloc;
97#endif
98
99#if ! (defined(OM_HAVE_VALLOC_MMAP) && defined(OM_MALLOC_MAX_BYTES_SYSTEM))
100#ifdef OM_MALLOC_MAX_BYTES_SYSTEM
101 om_Info.MaxBytesSystem = OM_MALLOC_MAX_BYTES_SYSTEM;
102#else
103 om_Info.MaxBytesSystem =
104 (om_Info.MaxBytesSbrk + om_Info.MaxBytesMmap >
105 om_Info.MaxBytesFromMalloc + om_Info.MaxBytesFromValloc ?
106 om_Info.MaxBytesSbrk + om_Info.MaxBytesMmap :
107 om_Info.MaxBytesFromMalloc + om_Info.MaxBytesFromValloc);
108#endif
109#endif
110}
111
112omInfo_t omGetInfo()
113{
114 omUpdateInfo();
115 return om_Info;
116}
117
118void omPrintStats(FILE* fd)
119{
120 omUpdateInfo();
121 fprintf(fd, "System %ldk:%ldk Appl %ldk/%ldk Malloc %ldk/%ldk Valloc %ldk/%ldk Pages %ld/%ld Regions %ld:%ld Internal: %ld\n",
122 om_Info.CurrentBytesSystem/1024, om_Info.MaxBytesSystem/1024,
123 om_Info.UsedBytes/1024, om_Info.AvailBytes/1024,
124 om_Info.UsedBytesMalloc/1024, om_Info.AvailBytesMalloc/1024,
125 om_Info.CurrentBytesFromValloc/1024, om_Info.AvailBytesFromValloc/1024,
126 om_Info.UsedPages, om_Info.AvailPages,
127 om_Info.CurrentRegionsAlloc, om_Info.MaxRegionsAlloc,
128 om_Info.InternalUsedBytesMalloc);
129}
130
131
132void omPrintInfo(FILE* fd)
133{
134 omUpdateInfo();
135 fputs(" Current: Max:\n",fd);
136 fprintf(fd, "BytesSystem: %8ldk %8ldk\n", om_Info.CurrentBytesSystem/1024, om_Info.MaxBytesSystem/1024);
137 fprintf(fd, "BytesSbrk: %8ldk %8ldk\n", om_Info.CurrentBytesSbrk/1024, om_Info.MaxBytesSbrk/1024);
138 fprintf(fd, "BytesMmap: %8ldk %8ldk\n", om_Info.CurrentBytesMmap/1024, om_Info.MaxBytesMmap/1024);
139 fprintf(fd, "BytesFromMalloc: %8ldk %8ldk\n", om_Info.CurrentBytesFromMalloc/1024, om_Info.MaxBytesFromMalloc/1024);
140 fprintf(fd, "BytesFromValloc: %8ldk %8ldk\n", om_Info.CurrentBytesFromValloc/1024, om_Info.MaxBytesFromValloc/1024);
141 fprintf(fd, "PagesAlloc: %8ld %8ld \n", om_Info.UsedPages, om_Info.MaxPages);
142 fprintf(fd, "RegionsAlloc: %8ld %8ld \n", om_Info.CurrentRegionsAlloc, om_Info.MaxRegionsAlloc);
143 fputs(" Used: Avail:\n",fd);
144 fprintf(fd, "BytesAppl: %8ldk %8ldk\n", om_Info.UsedBytes/1024, om_Info.AvailBytes/1024);
145 fprintf(fd, "BytesMalloc: %8ldk %8ldk\n", om_Info.UsedBytesMalloc/1024, om_Info.AvailBytesMalloc/1024);
146 fprintf(fd, "BytesValloc: %8ldk %8ldk\n", om_Info.UsedBytesFromValloc/1024, om_Info.AvailBytesFromValloc/1024);
147 fprintf(fd, "Pages: %8ld %8ld\n", om_Info.UsedPages, om_Info.AvailPages);
148}
149#else
150#include "omalloc/xalloc.h"
151int om_sing_opt_show_mem; /* dummy */
152struct omInfo_s om_Info; /* dummy */
153struct omOpts_s om_Opts; /* dummy */
154#endif
long omGetUsedBinBytes()
Definition: omBin.c:763
omOpts_t om_Opts
Definition: omOpts.c:13
unsigned long om_SbrkInit
Definition: omStats.c:18
void omUpdateInfo()
Definition: omStats.c:27
omInfo_t om_Info
Definition: omStats.c:16
void omInitInfo()
Definition: omStats.c:20
omInfo_t omGetInfo()
Definition: omStats.c:112
int om_sing_opt_show_mem
int status int fd
Definition: si_signals.h:59
#define omPrintStats(F)
Definition: xalloc.h:231
#define omPrintInfo(F)
Definition: xalloc.h:232