os/persistentdata/persistentstorage/sql/SRC/Server/SqlSrvResourceProfiler.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 #ifndef __SQLSRVRESOURCEPROFILER_H__
    17 #define __SQLSRVRESOURCEPROFILER_H__
    18 
    19 #include <e32cmn.h>
    20 #include "SqlUtil.h"
    21 
    22 #ifdef _SQLPROFILER
    23 
    24 ///////////////////////////////// Heap max alloc /////////////////////////////////////
    25 
    26 extern TBool TheSqlSrvProfilerMaxAllocEnabled;
    27 extern TInt  TheSqlSrvProfilerMaxAllocSize;
    28 
    29 #define SQLPROFILER_REPORT_ALLOC(size) 													\
    30 	do																					\
    31 		{																				\
    32 		if(TheSqlSrvProfilerMaxAllocEnabled && (size) > TheSqlSrvProfilerMaxAllocSize) 	\
    33 			{																			\
    34 			TheSqlSrvProfilerMaxAllocSize = (size);										\
    35 			}																			\
    36 		}																				\
    37 	while(0)
    38 
    39 ///////////////////////////////// IPC counters ///////////////////////////////////////
    40 
    41 enum TSqlIpcType
    42 		{
    43 		ESqlIpcRq,
    44 		ESqlIpcRead,
    45 		ESqlIpcWrite,
    46 		//	
    47 		ESqlIpcLast
    48 		};
    49 
    50 extern TBool TheSqlSrvProfilerIpcEnabled;
    51 extern TInt  TheSqlSrvProfilerIpc[];
    52 extern TInt64 TheSqlSrvProfilerIpcBytes[];
    53 
    54 #define SQLPROFILER_REPORT_IPC(type, bytes) 				\
    55 		do													\
    56 			{												\
    57 			if(TheSqlSrvProfilerIpcEnabled)					\
    58 				{											\
    59 				++TheSqlSrvProfilerIpc[type];				\
    60 				TheSqlSrvProfilerIpcBytes[type] += bytes;	\
    61 				}											\
    62 			}												\
    63 		while(0)
    64 
    65 ////////////////////////// IPC & SQL tracing related /////////////////////////////////
    66 
    67 //Level 1 IPC calls count. IPC calls types included:
    68 // ESqlSrvDbExec8, ESqlSrvDbExec16, ESqlSrvDbScalarFullSelect16, ESqlSrvStmtExec,
    69 // ESqlSrvStmtAsyncExec, ESqlSrvStmtBindExec, ESqlSrvStmtAsyncBindExec, ESqlSrvStmtNext,
    70 // ESqlSrvStmtBindNext;
    71 const TInt KIpcTraceTypeCount = 10; 
    72 
    73 //A TSqlIpcTraceData array of KIpcTraceTypeCount elements is a member of the CSqlSrvSession class.
    74 //During the tracing, if level 1 or level 2 is enabled, all relevant information is summarized there.
    75 struct TSqlSrvIpcTraceData
    76     {
    77     TInt64  iExecutionTime;     //The summary of the execution time spent in particular level 1 IPC call
    78     TInt    iCount;             //The IPC call count for particular level 1 call               
    79     };
    80 
    81 ///////////////////  IPC & SQL tracing functions and macros ///////////////////////////////
    82 
    83 void   SqlIpcStart(TUint& aIpcCounter, TUint32& aStartTicks, TUint aDbHandle);
    84 void   SqlIpcEnd(TUint aIpcCounter, TUint32 aStartTicks, TSqlSrvFunction aFuncCode, 
    85                  TUint aDbHandle, TSqlSrvIpcTraceData aIpcTraceData[], TInt aRetCode);
    86 void   SqlIpcError(TUint aIpcCounter, TSqlSrvFunction aFuncCode, TUint aDbHandle, TInt aError);
    87 void   SqlPrintSql16(TUint aDbHandle, const TDesC& aSql, TBool aPrepare);
    88 void   SqlPrintSql8(TUint aDbHandle, const TDesC8& aSql, TBool aPrepare);
    89 
    90 void   SqlPrintDbCreate(TUint aDbHandle, const TDesC& aDbName);
    91 void   SqlPrintDbOpen(TUint aDbHandle, const TDesC& aDbName);
    92 void   SqlPrintDbClose(TUint aDbHandle);
    93 
    94 void   SqlPrintServerStart();
    95 void   SqlPrintServerStop();
    96 
    97 #define SQLPROFILER_IPC_START(aIpcCounter, aDbHandle) \
    98     TUint32 startTicks = 0;\
    99     SqlIpcStart(aIpcCounter, startTicks, aDbHandle)
   100 
   101 #define SQLPROFILER_IPC_END(aIpcCounter, aFuncCode, aDbHandle, aIpcTraceData, aRetCode) \
   102     SqlIpcEnd(aIpcCounter, startTicks, aFuncCode, aDbHandle, aIpcTraceData, aRetCode)
   103 
   104 #define SQLPROFILER_IPC_ERROR(aIpcCounter, aFuncCode, aDbHandle, aError) \
   105     SqlIpcError(aIpcCounter, aFuncCode, aDbHandle, aError)
   106 
   107 #define SQLPROFILER_SQL16_PRINT(aDbHandle, aSql, aPrepare) \
   108     SqlPrintSql16(aDbHandle, aSql, aPrepare)
   109 
   110 #define SQLPROFILER_SQL8_PRINT(aDbHandle, aSql, aPrepare) \
   111     SqlPrintSql8(aDbHandle, aSql, aPrepare)
   112 
   113 #define SQLPROFILER_DB_CREATE(aDbHandle, aDbName) \
   114     SqlPrintDbCreate(aDbHandle, aDbName)
   115 
   116 #define SQLPROFILER_DB_OPEN(aDbHandle, aDbName) \
   117     SqlPrintDbOpen(aDbHandle, aDbName)
   118 
   119 #define SQLPROFILER_DB_CLOSE(aDbHandle) \
   120     SqlPrintDbClose(aDbHandle)
   121 
   122 #define SQLPROFILER_SERVER_START() \
   123     SqlPrintServerStart()
   124 
   125 #define SQLPROFILER_SERVER_STOP() \
   126     SqlPrintServerStop()
   127 
   128 ///////////////////////////////////////////////////////////////////////////////////////
   129 
   130 #else//_SQLPROFILER
   131 
   132 #define SQLPROFILER_REPORT_ALLOC(size) do {} while(0)
   133 #define SQLPROFILER_REPORT_IPC(type, bytes) do {} while(0)
   134 
   135 #define SQLPROFILER_IPC_START(aIpcCounter, aDbHandle) do {} while(0)
   136 #define SQLPROFILER_IPC_END(aIpcCounter, aFuncCode, aDbHandle, aIpcTraceData, aRetCode) do {} while(0)
   137 #define SQLPROFILER_IPC_ERROR(aIpcCounter, aFuncCode, aDbHandle, aError) do {} while(0)
   138 #define SQLPROFILER_SQL16_PRINT(aDbHandle, aSql, aPrepare) do {} while(0)
   139 #define SQLPROFILER_SQL8_PRINT(aDbHandle, aSql, aPrepare) do {} while(0)
   140 
   141 #define SQLPROFILER_DB_CREATE(aDbHandle, aDbName) do {} while(0)
   142 #define SQLPROFILER_DB_OPEN(aDbHandle, aDbName) do {} while(0)
   143 #define SQLPROFILER_DB_CLOSE(aDbHandle) do {} while(0)
   144 
   145 #define SQLPROFILER_SERVER_START() do {} while(0) 
   146 #define SQLPROFILER_SERVER_STOP() do {} while(0)
   147 
   148 #endif//_SQLPROFILER
   149 
   150 /**
   151 This class can be used for collecting information regarding the SQL server resources usage.
   152 
   153 @see TSqlResourceProfiler
   154 @internalComponent
   155 */
   156 NONSHARABLE_CLASS(TSqlSrvResourceProfiler)
   157 	{
   158 public:
   159 	static void StartL(const RMessage2&);
   160 	static void StopL(const RMessage2&);
   161 	static void ResetL(const RMessage2&);
   162 	static void QueryL(const RMessage2&);
   163 	
   164 	};
   165 	
   166 #endif//__SQLSRVRESOURCEPROFILER_H__