Annotation of parser3/src/targets/cgi/pa_pool.C, revision 1.7

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.7     ! parser      8:        $Id: pa_pool.C,v 1.6 2001/05/15 11:36:15 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.7     ! parser     17: #include <typeinfo.h>
        !            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.6       parser     67: #define MALLOC_STAT_MAXSIZE (0x400*0x400)
1.7     ! parser     68: #define MALLOC_STAT_PLACES 10
        !            69: 
        !            70: int malloc_times[MALLOC_STAT_PLACES][MALLOC_STAT_MAXSIZE];
        !            71: int malloc_places[MALLOC_STAT_PLACES];
1.6       parser     72: 
                     73: void log_pool_stats(Pool& pool) {
1.7     ! parser     74:        #define ST(type_name) \
        !            75:                SAPI::log(pool, \
        !            76:                        "%4d %s", \
        !            77:                        sizeof(type_name), #type_name);
        !            78:        ST(Value);
        !            79: ST( Array);
        !            80: ST(Exception);
        !            81: ST(ffblk);
        !            82: ST(Hash);
        !            83: ST(Junction);
        !            84: ST(Method);
        !            85: ST(Methoded);
        !            86: ST(Methoded_array);
        !            87: ST(MethodParams);
        !            88: ST(Operation);
        !            89: ST(Origin);
        !            90: ST(Pool);
        !            91: ST(Pooled);
        !            92: ST(Request);
        !            93: ST(SAPI);
        !            94: ST(SQL_Connection);
        !            95: ST(SQL_Driver);
        !            96: ST(SQL_Driver_manager);
        !            97: ST(SQL_Driver_services);
        !            98: ST(Stack);
        !            99: ST(String);
        !           100: ST(Table);
        !           101: ST(Temp_alias);
        !           102: ST(Temp_exception);
        !           103: ST(Temp_lang);
        !           104: ST(Temp_method);
        !           105: ST(VAliased);
        !           106: ST(Value);
        !           107: ST(VBool);
        !           108: ST(VClass);
        !           109: ST(VCodeFrame);
        !           110: ST(VCookie);
        !           111: ST(VDouble);
        !           112: ST(VEnv);
        !           113: ST(VFile);
        !           114: ST(VForm);
        !           115: ST(VHash);
        !           116: ST(VImage);
        !           117: ST(VInt);
        !           118: ST(VJunction);
        !           119: ST(VMethodFrame);
        !           120: ST(VObject);
        !           121: ST(VRequest);
        !           122: ST(VResponse);
        !           123: ST(VStateless_class);
        !           124: ST(VStateless_object);
        !           125: ST(VString);
        !           126: ST(VTable);
        !           127: ST(VUnknown);
        !           128: ST(WContext);
        !           129: ST(WWrapper);
        !           130: 
        !           131: 
        !           132:        for(int place=0; place<MALLOC_STAT_PLACES; place++)
        !           133:                if(malloc_places[place]) {
        !           134:                        SAPI::log(pool, 
        !           135:                                "place:times %10d:%10d", 
        !           136:                                place, 
        !           137:                                malloc_places[place]);
        !           138:                        int total_size=0, total_times=0;
        !           139:                        for(int i=0; i<MALLOC_STAT_MAXSIZE; i++)
        !           140:                                if(malloc_times[place][i]) {
        !           141:                                        total_size+=i*malloc_times[place][i];
        !           142:                                        total_times+=malloc_times[place][i];
        !           143:                                        SAPI::log(pool, 
        !           144:                                                "%10d*%10d=%10d", 
        !           145:                                                i, 
        !           146:                                                malloc_times[place][i], 
        !           147:                                                i*malloc_times[place][i]);
        !           148:                                }
1.6       parser    149:                        SAPI::log(pool, 
1.7     ! parser    150:                                "total %d/%d", 
        !           151:                                total_size, 
        !           152:                                total_times);
        !           153:                }               
1.6       parser    154: }
1.5       parser    155: 
1.7     ! parser    156: void *Pool::real_malloc(size_t size, int place) {
        !           157:        int index=min(MALLOC_STAT_MAXSIZE-1, size);
        !           158:        /*if(size==132 && type_name)
        !           159:                SAPI::log(*this, "type_name:%s", type_name);*/
        !           160:        malloc_times[place][index]++;
        !           161:        malloc_places[place]++;
1.1       paf       162:        return ::malloc(size);
                    163: }
                    164: 
                    165: void *Pool::real_calloc(size_t size) {
                    166:        return ::calloc(size, 1);
                    167: }

E-mail: