OslMemory.c
资源名称:mmi.rar [点击查看]
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:19k
源码类别:
MTK
开发平台:
C/C++
- /*****************************************************************************
- * Copyright Statement:
- * --------------------
- * This software is protected by Copyright and the information contained
- * herein is confidential. The software may not be copied and the information
- * contained herein may not be used or disclosed except with the written
- * permission of MediaTek Inc. (C) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*******************************************************************************
- * Filename:
- * ---------
- * OslMemory.c
- *
- * Project:
- * --------
- * MAUI
- *
- * Description:
- * ------------
- *
- *
- * Author:
- * -------
- *
- *
- *==============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- * removed!
- * removed!
- * removed!
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *==============================================================================
- *******************************************************************************/
- /**
- * Copyright Notice
- * ?2002 - 2003, Pixtel Communications, Inc., 1489 43rd Ave. W.,
- * Vancouver, B.C. V6M 4K8 Canada. All Rights Reserved.
- * (It is illegal to remove this copyright notice from this software or any
- * portion of it)
- */
- /**************************************************************
- FILENAME : OslMemory.c
- PURPOSE : Memory Wrapper
- REMARKS : nil
- AUTHOR : Neeraj Sharma, Amit Kumar
- DATE : Jan' 21, 2003
- **************************************************************/
- /* Include: MMI header file */
- #include "oslmemory.h"
- #include "DateTimeType.h"
- #include "DateTimeGprot.h"
- #include "PixtelDataTypes.h"
- #include "StdC.h"
- #include "DebugInitDef.h"
- #ifdef OSL_MEMORY_DUMP /* if OSL_MEMORY_DUMP is not enabled then don't compile */
- #define BUFFER_POOLS 16
- #define MEMORY_LIST_LENGTH 50
- /*--------------------------------------------------------------------
- Data Structure Declerations
- -----------------------------------------------------------------------*/
- typedef struct oslmemalloc
- { /* info */
- S8 fileName[20];
- S32 lineNumber;
- S32 bytes;
- void *ptr;
- U8 isAllocated;
- } OSLMEMALLOC;
- S32 goslMemCount = 0; /* Total Allocated heap mem */
- S32 MAX_BUFF = 0;
- S32 MaxDynamicMemUsed = 0;
- static OSLMEMALLOC memoryList[MEMORY_LIST_LENGTH];
- static U16 bufferCount[BUFFER_POOLS];
- static U8 memoryListCount = 0;
- static U8 MallocFirstTime = 1;
- /*--------------------------------------------------------------------
- Function Declerations
- -----------------------------------------------------------------------*/
- void *OslMallocCHK(long nob, char *fileName, int lineNumber, ...);
- void OslMfreeCHK(void *frp);
- void OslIntMemoryStart();
- void OslIntDumpDataInFile(void);
- long OslIntMemCounter(void);
- /*-------------------------------------------------------------------
- Function Name : ByteCounter
- Description : This inline function keeps track of heap memory
- allocations in bytes
- Input : Pointer
- Flag : 1 to add no. of bytes
- -1 to delete no. of bytes
- Output : None
- --------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * ByteCounter
- * DESCRIPTION
- *
- * PARAMETERS
- * ptr [?]
- * flag [IN]
- * size [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void ByteCounter(void *ptr, int flag, int size) /* -1 free, +1 alloc */
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- goslMemCount += (long)(size * flag);
- if (MaxDynamicMemUsed < goslMemCount)
- {
- MaxDynamicMemUsed = goslMemCount;
- }
- return;
- }
- /*-------------------------------------------------------------------
- Function Name : OslMallocCHK
- Description : This function allocates memory and maintain the
- link list info of file name and line number
- Input : no of bytes
- file name
- line number
- Output : void pointer
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * OslMallocCHK
- * DESCRIPTION
- *
- * PARAMETERS
- * nob [IN]
- * fileName [?]
- * lineNumber [IN]
- * RETURNS
- * void
- *****************************************************************************/
- void *OslMallocCHK(S32 nob, char *fileName, int lineNumber, ...)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- void *ptr = NULL;
- U8 j, i;
- S32 nob1; /* =nob; */
- void *ptrAct;
- U16 maskingByte;
- OSLMEMALLOC *memData;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- if (MallocFirstTime)
- {
- OslIntMemoryStart();
- MallocFirstTime = 0;
- }
- if (!nob)
- {
- return NULL;
- }
- if (nob < 8)
- {
- nob = 8;
- }
- nob1 = nob;
- maskingByte = 1;
- i = 0;
- for (j = 0; j < 16; j++)
- {
- if (nob1 & maskingByte)
- {
- i++;
- }
- if (!(nob1 & 0xfffe))
- {
- break;
- }
- nob1 >>= 1;
- }
- if (i > 1)
- {
- nob1 = 1;
- nob1 <<= ++j;
- }
- else
- {
- nob1 = nob;
- }
- bufferCount[j - 3]++;
- #ifdef MMI_ON_WIN32
- ptrAct = (void*)malloc(nob1);
- #else
- ptrAct = (void*)get_ctrl_buffer(nob1);
- #endif
- if (memoryListCount < MEMORY_LIST_LENGTH)
- {
- for (j = 0; memoryList[j].isAllocated; j++);
- memData = &memoryList[j];
- memoryListCount++;
- for (j = strlen(fileName); j > 1; j--)
- {
- if (fileName[j - 1] == '\')
- {
- break;
- }
- }
- memcpy(memData->fileName, &fileName[j], strlen(fileName) - j + 1);
- /* strcpy(memData.fileName, (char *)fileName); */
- memData->lineNumber = lineNumber;
- memData->bytes = nob1;
- memData->ptr = ptrAct;
- memData->isAllocated = 1;
- ByteCounter(ptr, 1, nob1);
- }
- else
- {
- PRINT_INFORMATION(("File size exceeded"));
- }
- if (MAX_BUFF < nob1)
- {
- MAX_BUFF = nob1;
- }
- return ptrAct;
- }
- /*-------------------------------------------------------------------
- Function Name : osl_Mfree
- Description : This osl_Mfree's the poinetr along with node from the link
- list if present.
- Input : Ponter to be freed
- Output : None
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * OslMfreeCHK
- * DESCRIPTION
- *
- * PARAMETERS
- * frp [?]
- * RETURNS
- * void
- *****************************************************************************/
- void OslMfreeCHK(void *frp)
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- U8 i = 0, j = 0, k = 0;
- U16 maskingByte;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- for (j = 0; memoryList[j].ptr != frp && j <= MEMORY_LIST_LENGTH; j++);
- if (j != MEMORY_LIST_LENGTH)
- {
- maskingByte = 1;
- for (i = 0; i < 16; i++)
- {
- if (memoryList[j].bytes & maskingByte)
- {
- break;
- }
- maskingByte <<= 1;
- }
- if (i < 16)
- {
- bufferCount[i - 3]--;
- }
- ByteCounter(frp, -1, memoryList[j].bytes);
- memset(&memoryList[j], 0, sizeof(OSLMEMALLOC));
- memoryListCount--;
- }
- #ifdef MMI_ON_WIN32
- free(frp);
- #else
- free_ctrl_buffer(frp);
- #endif
- return;
- }
- /*-------------------------------------------------------------------
- Function Name : osl_MemoryCHK
- Description : This flag starts / stops building of the Memory
- link list
- Output : None
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * OslIntMemoryStart
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void OslIntMemoryStart()
- {
- #ifdef OSL_MEMORY_DUMP
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- memset(&memoryList, 0, sizeof(memoryList));
- memset(&bufferCount, 0, sizeof(bufferCount));
- memoryListCount = 0;
- #endif /* OSL_MEMORY_DUMP */
- return;
- }
- /*-------------------------------------------------------------------
- Function Name : OslMemCounter
- Description : This flag starts / stops building of the Memory
- link list
- Input : TRUE : TO start Mem link list
- FALSE : To stop Mem link list
- Output : None
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * OslIntMemCounter
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- *
- *****************************************************************************/
- long OslIntMemCounter()
- {
- #ifdef OSL_MEMORY_DUMP
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- return goslMemCount;
- #else /* OSL_MEMORY_DUMP */
- return 0;
- #endif /* OSL_MEMORY_DUMP */
- }
- /*-------------------------------------------------------------------
- Function Name : OslDumpDataInFile
- Description : This Dumps memory link list data in the file
- C:oslMemoryDump
- Input : None
- Output : None
- -------------------------------------------------------------------*/
- /*****************************************************************************
- * FUNCTION
- * OslIntDumpDataInFile
- * DESCRIPTION
- *
- * PARAMETERS
- * void
- * RETURNS
- * void
- *****************************************************************************/
- void OslIntDumpDataInFile()
- {
- /*----------------------------------------------------------------*/
- /* Local Variables */
- /*----------------------------------------------------------------*/
- MYTIME t;
- char fileName[128];
- U8 i;
- #ifdef MMI_ON_WIN32
- FILE *fp;
- #endif
- OSLMEMALLOC *ptr = NULL;
- /*----------------------------------------------------------------*/
- /* Code Body */
- /*----------------------------------------------------------------*/
- strcpy(fileName, "C:\oslMemoryDump.txt");
- #ifdef MMI_ON_WIN32
- if ((fp = fopen(fileName, "a+")) == NULL)
- {
- return;
- }
- GetDateTime(&t);
- fprintf(
- fp,
- "____________________________________________________________________________________________________________________________n");
- fprintf(fp, "Memory Dump at time %d:%d:%d on %d-%d-%dn", t.nHour, t.nMin, t.nSec, t.nDay, t.nMonth, t.nYear);
- fprintf(fp, "Maximum Buffer Allocated %ldn", MAX_BUFF);
- fprintf(fp, "Maximum Dynamic Memory used %ldn", MaxDynamicMemUsed);
- fprintf(fp, "Total Memory In Use %ldn", goslMemCount);
- #endif /* MMI_ON_WIN32 */
- PRINT_INFORMATION(("____________________________________________________________________________________________________________________________"));
- PRINT_INFORMATION(("Memory Dump at time %d:%d:%d on %d-%d-%d n n", t.nHour, t.nMin, t.nSec, t.nDay, t.nMonth,
- t.nYear));
- PRINT_INFORMATION(("Maximum Buffer Allocated %ld", MAX_BUFF));
- PRINT_INFORMATION(("Maximum Dynamic Memory used %ld", MaxDynamicMemUsed));
- PRINT_INFORMATION(("Total Memory In Use %ld", goslMemCount));
- for (i = 0; i < MEMORY_LIST_LENGTH; i++)
- {
- ptr = &memoryList[i];
- if (!ptr->isAllocated)
- {
- continue;
- }
- #ifdef MMI_ON_WIN32
- fprintf(fp, "File: [%s] Line: [%d] Size: [%d]n", ptr->fileName, ptr->lineNumber, ptr->bytes);
- #endif
- PRINT_INFORMATION(("File: [%s] Line: [%d] Size: [%d]", ptr->fileName, ptr->lineNumber,
- ptr->bytes));
- }
- #ifdef MMI_ON_WIN32
- fprintf(fp, "BUFFER VISE ALLOCATIONn");
- fprintf(fp, "Number of buffers of size 8: [%d]n", bufferCount[0]);
- fprintf(fp, "Number of buffers of size 16: [%d]n", bufferCount[1]);
- fprintf(fp, "Number of buffers of size 32: [%d]n", bufferCount[2]);
- fprintf(fp, "Number of buffers of size 64: [%d]n", bufferCount[3]);
- fprintf(fp, "Number of buffers of size 128: [%d]n", bufferCount[4]);
- fprintf(fp, "Number of buffers of size 256: [%d]n", bufferCount[5]);
- fprintf(fp, "Number of buffers of size 512: [%d]n", bufferCount[6]);
- fprintf(fp, "Number of buffers of size 1024: [%d]n", bufferCount[7]);
- fprintf(fp, "Number of buffers of size 2048: [%d]n", bufferCount[8]);
- fprintf(fp, "Number of buffers of size 4096: [%d]n", bufferCount[9]);
- fprintf(fp, "Number of buffers of size 8192: [%d]n", bufferCount[10]);
- fprintf(fp, "Number of buffers of size 16384: [%d]n", bufferCount[11]);
- fprintf(fp, "Number of buffers of size 32768: [%d]n", bufferCount[12]);
- fprintf(fp, "Number of buffers of size 65536: [%d]n", bufferCount[13]);
- #endif /* MMI_ON_WIN32 */
- PRINT_INFORMATION(("Number of buffers of size 8: [%d]", bufferCount[0]));
- PRINT_INFORMATION(("Number of buffers of size 16: [%d]", bufferCount[1]));
- PRINT_INFORMATION(("Number of buffers of size 32: [%d]", bufferCount[2]));
- PRINT_INFORMATION(("Number of buffers of size 64: [%d]", bufferCount[3]));
- PRINT_INFORMATION(("Number of buffers of size 128: [%d]", bufferCount[4]));
- PRINT_INFORMATION(("Number of buffers of size 256: [%d]", bufferCount[5]));
- PRINT_INFORMATION(("Number of buffers of size 512: [%d]", bufferCount[6]));
- PRINT_INFORMATION(("Number of buffers of size 1024: [%d]", bufferCount[7]));
- PRINT_INFORMATION(("Number of buffers of size 2048: [%d]", bufferCount[8]));
- PRINT_INFORMATION(("Number of buffers of size 4096: [%d]", bufferCount[9]));
- PRINT_INFORMATION(("Number of buffers of size 8192: [%d]", bufferCount[10]));
- PRINT_INFORMATION(("Number of buffers of size 16384: [%d]", bufferCount[11]));
- PRINT_INFORMATION(("Number of buffers of size 32768: [%d]", bufferCount[12]));
- PRINT_INFORMATION(("Number of buffers of size 65536: [%d]", bufferCount[13]));
- PRINT_INFORMATION(("____________________________________________________________________________________________________________________________"));
- #ifdef MMI_ON_WIN32
- fclose(fp);
- #endif
- return;
- }
- #endif /* OSL_MEMORY_DUMP */
- /*-------------------------------------------------------------------
- end of file OslMemory.C
- ---------------------------------------------------------------------*/