sl@0: // Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #ifndef __SQLSRVRESOURCEPROFILER_H__
sl@0: #define __SQLSRVRESOURCEPROFILER_H__
sl@0: 
sl@0: #include <e32cmn.h>
sl@0: #include "SqlUtil.h"
sl@0: 
sl@0: #ifdef _SQLPROFILER
sl@0: 
sl@0: ///////////////////////////////// Heap max alloc /////////////////////////////////////
sl@0: 
sl@0: extern TBool TheSqlSrvProfilerMaxAllocEnabled;
sl@0: extern TInt  TheSqlSrvProfilerMaxAllocSize;
sl@0: 
sl@0: #define SQLPROFILER_REPORT_ALLOC(size) 													\
sl@0: 	do																					\
sl@0: 		{																				\
sl@0: 		if(TheSqlSrvProfilerMaxAllocEnabled && (size) > TheSqlSrvProfilerMaxAllocSize) 	\
sl@0: 			{																			\
sl@0: 			TheSqlSrvProfilerMaxAllocSize = (size);										\
sl@0: 			}																			\
sl@0: 		}																				\
sl@0: 	while(0)
sl@0: 
sl@0: ///////////////////////////////// IPC counters ///////////////////////////////////////
sl@0: 
sl@0: enum TSqlIpcType
sl@0: 		{
sl@0: 		ESqlIpcRq,
sl@0: 		ESqlIpcRead,
sl@0: 		ESqlIpcWrite,
sl@0: 		//	
sl@0: 		ESqlIpcLast
sl@0: 		};
sl@0: 
sl@0: extern TBool TheSqlSrvProfilerIpcEnabled;
sl@0: extern TInt  TheSqlSrvProfilerIpc[];
sl@0: extern TInt64 TheSqlSrvProfilerIpcBytes[];
sl@0: 
sl@0: #define SQLPROFILER_REPORT_IPC(type, bytes) 				\
sl@0: 		do													\
sl@0: 			{												\
sl@0: 			if(TheSqlSrvProfilerIpcEnabled)					\
sl@0: 				{											\
sl@0: 				++TheSqlSrvProfilerIpc[type];				\
sl@0: 				TheSqlSrvProfilerIpcBytes[type] += bytes;	\
sl@0: 				}											\
sl@0: 			}												\
sl@0: 		while(0)
sl@0: 
sl@0: ////////////////////////// IPC & SQL tracing related /////////////////////////////////
sl@0: 
sl@0: //Level 1 IPC calls count. IPC calls types included:
sl@0: // ESqlSrvDbExec8, ESqlSrvDbExec16, ESqlSrvDbScalarFullSelect16, ESqlSrvStmtExec,
sl@0: // ESqlSrvStmtAsyncExec, ESqlSrvStmtBindExec, ESqlSrvStmtAsyncBindExec, ESqlSrvStmtNext,
sl@0: // ESqlSrvStmtBindNext;
sl@0: const TInt KIpcTraceTypeCount = 10; 
sl@0: 
sl@0: //A TSqlIpcTraceData array of KIpcTraceTypeCount elements is a member of the CSqlSrvSession class.
sl@0: //During the tracing, if level 1 or level 2 is enabled, all relevant information is summarized there.
sl@0: struct TSqlSrvIpcTraceData
sl@0:     {
sl@0:     TInt64  iExecutionTime;     //The summary of the execution time spent in particular level 1 IPC call
sl@0:     TInt    iCount;             //The IPC call count for particular level 1 call               
sl@0:     };
sl@0: 
sl@0: ///////////////////  IPC & SQL tracing functions and macros ///////////////////////////////
sl@0: 
sl@0: void   SqlIpcStart(TUint& aIpcCounter, TUint32& aStartTicks, TUint aDbHandle);
sl@0: void   SqlIpcEnd(TUint aIpcCounter, TUint32 aStartTicks, TSqlSrvFunction aFuncCode, 
sl@0:                  TUint aDbHandle, TSqlSrvIpcTraceData aIpcTraceData[], TInt aRetCode);
sl@0: void   SqlIpcError(TUint aIpcCounter, TSqlSrvFunction aFuncCode, TUint aDbHandle, TInt aError);
sl@0: void   SqlPrintSql16(TUint aDbHandle, const TDesC& aSql, TBool aPrepare);
sl@0: void   SqlPrintSql8(TUint aDbHandle, const TDesC8& aSql, TBool aPrepare);
sl@0: 
sl@0: void   SqlPrintDbCreate(TUint aDbHandle, const TDesC& aDbName);
sl@0: void   SqlPrintDbOpen(TUint aDbHandle, const TDesC& aDbName);
sl@0: void   SqlPrintDbClose(TUint aDbHandle);
sl@0: 
sl@0: void   SqlPrintServerStart();
sl@0: void   SqlPrintServerStop();
sl@0: 
sl@0: #define SQLPROFILER_IPC_START(aIpcCounter, aDbHandle) \
sl@0:     TUint32 startTicks = 0;\
sl@0:     SqlIpcStart(aIpcCounter, startTicks, aDbHandle)
sl@0: 
sl@0: #define SQLPROFILER_IPC_END(aIpcCounter, aFuncCode, aDbHandle, aIpcTraceData, aRetCode) \
sl@0:     SqlIpcEnd(aIpcCounter, startTicks, aFuncCode, aDbHandle, aIpcTraceData, aRetCode)
sl@0: 
sl@0: #define SQLPROFILER_IPC_ERROR(aIpcCounter, aFuncCode, aDbHandle, aError) \
sl@0:     SqlIpcError(aIpcCounter, aFuncCode, aDbHandle, aError)
sl@0: 
sl@0: #define SQLPROFILER_SQL16_PRINT(aDbHandle, aSql, aPrepare) \
sl@0:     SqlPrintSql16(aDbHandle, aSql, aPrepare)
sl@0: 
sl@0: #define SQLPROFILER_SQL8_PRINT(aDbHandle, aSql, aPrepare) \
sl@0:     SqlPrintSql8(aDbHandle, aSql, aPrepare)
sl@0: 
sl@0: #define SQLPROFILER_DB_CREATE(aDbHandle, aDbName) \
sl@0:     SqlPrintDbCreate(aDbHandle, aDbName)
sl@0: 
sl@0: #define SQLPROFILER_DB_OPEN(aDbHandle, aDbName) \
sl@0:     SqlPrintDbOpen(aDbHandle, aDbName)
sl@0: 
sl@0: #define SQLPROFILER_DB_CLOSE(aDbHandle) \
sl@0:     SqlPrintDbClose(aDbHandle)
sl@0: 
sl@0: #define SQLPROFILER_SERVER_START() \
sl@0:     SqlPrintServerStart()
sl@0: 
sl@0: #define SQLPROFILER_SERVER_STOP() \
sl@0:     SqlPrintServerStop()
sl@0: 
sl@0: ///////////////////////////////////////////////////////////////////////////////////////
sl@0: 
sl@0: #else//_SQLPROFILER
sl@0: 
sl@0: #define SQLPROFILER_REPORT_ALLOC(size) do {} while(0)
sl@0: #define SQLPROFILER_REPORT_IPC(type, bytes) do {} while(0)
sl@0: 
sl@0: #define SQLPROFILER_IPC_START(aIpcCounter, aDbHandle) do {} while(0)
sl@0: #define SQLPROFILER_IPC_END(aIpcCounter, aFuncCode, aDbHandle, aIpcTraceData, aRetCode) do {} while(0)
sl@0: #define SQLPROFILER_IPC_ERROR(aIpcCounter, aFuncCode, aDbHandle, aError) do {} while(0)
sl@0: #define SQLPROFILER_SQL16_PRINT(aDbHandle, aSql, aPrepare) do {} while(0)
sl@0: #define SQLPROFILER_SQL8_PRINT(aDbHandle, aSql, aPrepare) do {} while(0)
sl@0: 
sl@0: #define SQLPROFILER_DB_CREATE(aDbHandle, aDbName) do {} while(0)
sl@0: #define SQLPROFILER_DB_OPEN(aDbHandle, aDbName) do {} while(0)
sl@0: #define SQLPROFILER_DB_CLOSE(aDbHandle) do {} while(0)
sl@0: 
sl@0: #define SQLPROFILER_SERVER_START() do {} while(0) 
sl@0: #define SQLPROFILER_SERVER_STOP() do {} while(0)
sl@0: 
sl@0: #endif//_SQLPROFILER
sl@0: 
sl@0: /**
sl@0: This class can be used for collecting information regarding the SQL server resources usage.
sl@0: 
sl@0: @see TSqlResourceProfiler
sl@0: @internalComponent
sl@0: */
sl@0: NONSHARABLE_CLASS(TSqlSrvResourceProfiler)
sl@0: 	{
sl@0: public:
sl@0: 	static void StartL(const RMessage2&);
sl@0: 	static void StopL(const RMessage2&);
sl@0: 	static void ResetL(const RMessage2&);
sl@0: 	static void QueryL(const RMessage2&);
sl@0: 	
sl@0: 	};
sl@0: 	
sl@0: #endif//__SQLSRVRESOURCEPROFILER_H__