Annotation of parser3/src/targets/cgi/pa_pool.C, revision 1.30
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.23 parser 5: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
1.4 paf 6:
1.30 ! paf 7: $Id: pa_pool.C,v 1.29 2001/10/29 16:29:08 paf Exp $
1.1 paf 8: */
9:
10: #include <stdlib.h>
11:
12: #include "pa_pool.h"
1.24 parser 13: #include "pool_storage.h"
1.1 paf 14:
1.30 ! paf 15: //#define DEBUG_POOL_MALLOC
1.14 parser 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"
1.17 parser 65: #include "pa_vvoid.h"
1.7 parser 66: #include "pa_wcontext.h"
67: #include "pa_wwrapper.h"
1.28 paf 68: #include "pa_dictionary.h"
1.10 parser 69:
1.6 parser 70: #define MALLOC_STAT_MAXSIZE (0x400*0x400)
1.25 paf 71: #define MALLOC_STAT_PLACES 20
1.7 parser 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_lang);
106: ST(Temp_method);
107: ST(VAliased);
108: ST(Value);
109: ST(VBool);
110: ST(VClass);
111: ST(VCodeFrame);
112: ST(VCookie);
113: ST(VDouble);
114: ST(VEnv);
115: ST(VFile);
116: ST(VForm);
117: ST(VHash);
118: ST(VImage);
119: ST(VInt);
120: ST(VJunction);
121: ST(VMethodFrame);
122: ST(VObject);
123: ST(VRequest);
124: ST(VResponse);
125: ST(VStateless_class);
126: ST(VStateless_object);
127: ST(VString);
128: ST(VTable);
1.17 parser 129: ST(VVoid);
1.7 parser 130: ST(WContext);
131: ST(WWrapper);
1.28 paf 132: ST(Dictionary);
1.7 parser 133:
134: for(int place=0; place<MALLOC_STAT_PLACES; place++)
135: if(malloc_places[place]) {
136: SAPI::log(pool,
137: "place:times %10d:%10d",
138: place,
139: malloc_places[place]);
140: int total_size=0, total_times=0;
141: for(int i=0; i<MALLOC_STAT_MAXSIZE; i++)
142: if(malloc_times[place][i]) {
143: total_size+=i*malloc_times[place][i];
144: total_times+=malloc_times[place][i];
145: SAPI::log(pool,
146: "%10d*%10d=%10d",
147: i,
148: malloc_times[place][i],
149: i*malloc_times[place][i]);
150: }
1.6 parser 151: SAPI::log(pool,
1.7 parser 152: "total %d/%d",
153: total_size,
154: total_times);
155: }
1.6 parser 156: }
1.10 parser 157: #endif
1.5 parser 158:
1.25 paf 159: void *Pool::real_malloc(size_t size, int place) {
1.10 parser 160: #ifdef DEBUG_POOL_MALLOC
1.27 paf 161: //place=0;
1.7 parser 162: int index=min(MALLOC_STAT_MAXSIZE-1, size);
163: malloc_times[place][index]++;
164: malloc_places[place]++;
1.29 paf 165: /* if(size==208 && place==10)
1.14 parser 166: __asm int 3;*/
1.10 parser 167: #endif
1.1 paf 168: return ::malloc(size);
169: }
170:
171: void *Pool::real_calloc(size_t size) {
172: return ::calloc(size, 1);
173: }
1.18 parser 174:
1.20 parser 175: bool Pool::real_register_cleanup(void (*cleanup) (void *), void *data) {
1.24 parser 176: return fstorage!=0 && static_cast<Pool_storage *>(fstorage)->register_cleanup(cleanup, data);
177: }
E-mail: