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