Annotation of parser3/src/targets/cgi/pa_pool.C, revision 1.11
1.4 paf 1: /** @file
2: Parser: CGI memory manager impl.
3:
1.1 paf 4: Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
1.4 paf 5:
1.1 paf 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
7:
1.11 ! parser 8: $Id: pa_pool.C,v 1.10 2001/05/16 17:10:34 parser Exp $
1.1 paf 9: */
10:
11: #include <stdlib.h>
12:
13: #include "pa_pool.h"
14:
1.6 parser 15: #include "pa_sapi.h"
16: #include "pa_common.h"
1.11 ! parser 17: //#include <typeinfo.h>
1.7 parser 18: #include "pa_value.h"
19:
20: #include "pa_array.h"
21: #include "pa_common.h"
22: #include "pa_dir.h"
23: #include "pa_exception.h"
24: #include "pa_exec.h"
25: #include "pa_globals.h"
26: #include "pa_hash.h"
27: #include "pa_opcode.h"
28: #include "pa_pool.h"
29: #include "pa_request.h"
30: #include "pa_sapi.h"
31: #include "pa_socks.h"
32: #include "pa_sql_connection.h"
33: #include "pa_sql_driver_manager.h"
34: #include "pa_stack.h"
35: #include "pa_string.h"
36: #include "pa_table.h"
37: #include "pa_threads.h"
38: #include "pa_types.h"
39: #include "pa_version.h"
40:
41: #include "pa_valiased.h"
42: #include "pa_value.h"
43: #include "pa_vbool.h"
44: #include "pa_vclass.h"
45: #include "pa_vcode_frame.h"
46: #include "pa_vcookie.h"
47: #include "pa_vdouble.h"
48: #include "pa_venv.h"
49: #include "pa_vfile.h"
50: #include "pa_vform.h"
51: #include "pa_vhash.h"
52: #include "pa_vimage.h"
53: #include "pa_vint.h"
54: #include "pa_vjunction.h"
55: #include "pa_vmethod_frame.h"
56: #include "pa_vobject.h"
57: #include "pa_vrequest.h"
58: #include "pa_vresponse.h"
59: #include "pa_vstateless_class.h"
60: #include "pa_vstateless_object.h"
61: #include "pa_vstring.h"
62: #include "pa_vtable.h"
63: #include "pa_vunknown.h"
64: #include "pa_wcontext.h"
65: #include "pa_wwrapper.h"
66:
1.10 parser 67:
68: //#define DEBUG_POOL_MALLOC
69:
70: #ifdef DEBUG_POOL_MALLOC
1.6 parser 71: #define MALLOC_STAT_MAXSIZE (0x400*0x400)
1.7 parser 72: #define MALLOC_STAT_PLACES 10
73:
74: int malloc_times[MALLOC_STAT_PLACES][MALLOC_STAT_MAXSIZE];
75: int malloc_places[MALLOC_STAT_PLACES];
1.6 parser 76:
77: void log_pool_stats(Pool& pool) {
1.7 parser 78: #define ST(type_name) \
79: SAPI::log(pool, \
80: "%4d %s", \
81: sizeof(type_name), #type_name);
82: ST(Value);
83: ST( Array);
84: ST(Exception);
85: ST(ffblk);
86: ST(Hash);
87: ST(Junction);
88: ST(Method);
89: ST(Methoded);
90: ST(Methoded_array);
91: ST(MethodParams);
92: ST(Operation);
93: ST(Origin);
94: ST(Pool);
95: ST(Pooled);
96: ST(Request);
97: ST(SAPI);
98: ST(SQL_Connection);
99: ST(SQL_Driver);
100: ST(SQL_Driver_manager);
101: ST(SQL_Driver_services);
102: ST(Stack);
103: ST(String);
104: ST(Table);
105: ST(Temp_alias);
106: ST(Temp_exception);
107: ST(Temp_lang);
108: ST(Temp_method);
109: ST(VAliased);
110: ST(Value);
111: ST(VBool);
112: ST(VClass);
113: ST(VCodeFrame);
114: ST(VCookie);
115: ST(VDouble);
116: ST(VEnv);
117: ST(VFile);
118: ST(VForm);
119: ST(VHash);
120: ST(VImage);
121: ST(VInt);
122: ST(VJunction);
123: ST(VMethodFrame);
124: ST(VObject);
125: ST(VRequest);
126: ST(VResponse);
127: ST(VStateless_class);
128: ST(VStateless_object);
129: ST(VString);
130: ST(VTable);
131: ST(VUnknown);
132: ST(WContext);
133: ST(WWrapper);
134:
135:
136: for(int place=0; place<MALLOC_STAT_PLACES; place++)
137: if(malloc_places[place]) {
138: SAPI::log(pool,
139: "place:times %10d:%10d",
140: place,
141: malloc_places[place]);
142: int total_size=0, total_times=0;
143: for(int i=0; i<MALLOC_STAT_MAXSIZE; i++)
144: if(malloc_times[place][i]) {
145: total_size+=i*malloc_times[place][i];
146: total_times+=malloc_times[place][i];
147: SAPI::log(pool,
148: "%10d*%10d=%10d",
149: i,
150: malloc_times[place][i],
151: i*malloc_times[place][i]);
152: }
1.6 parser 153: SAPI::log(pool,
1.7 parser 154: "total %d/%d",
155: total_size,
156: total_times);
157: }
1.6 parser 158: }
1.10 parser 159: #endif
1.5 parser 160:
1.10 parser 161: void *Pool::real_malloc(size_t size/*, int place*/) {
162: #ifdef DEBUG_POOL_MALLOC
1.7 parser 163: int index=min(MALLOC_STAT_MAXSIZE-1, size);
1.9 parser 164: /* if(size==88) {
1.8 parser 165: _asm {
166: int 3;
167: };
168: }*/
1.7 parser 169: malloc_times[place][index]++;
170: malloc_places[place]++;
1.10 parser 171: #endif
1.1 paf 172: return ::malloc(size);
173: }
174:
175: void *Pool::real_calloc(size_t size) {
176: return ::calloc(size, 1);
177: }
E-mail: