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: #include sl@0: #include "SqlAssert.h" sl@0: #include "SqlSrvResourceProfiler.h" sl@0: #include "SqlResourceProfiler.h" sl@0: #include "SqliteSymbian.h" sl@0: #include sl@0: sl@0: #ifdef _SQLPROFILER sl@0: sl@0: ///////////////////////////////// Heap max alloc ///////////////////////////////////// sl@0: sl@0: /** sl@0: If true the max alloc profiling is enabled. sl@0: @internalComponent sl@0: */ sl@0: TBool TheSqlSrvProfilerMaxAllocEnabled = EFalse; sl@0: /** sl@0: The size of the biggest memory block ever allocated by the SQL server. sl@0: Set only if compiled with _SQLPROFILER macro. sl@0: @internalComponent sl@0: */ sl@0: TInt TheSqlSrvProfilerMaxAllocSize = 0; sl@0: sl@0: ////////////////////////// IPC & SQL tracing related ////////////////////////////////// sl@0: sl@0: /** sl@0: If true the tracing is enabled (IPC calls & SQL statements). sl@0: @internalComponent sl@0: */ sl@0: static TBool TheSqlSrvProfilerTraceEnabled = EFalse; sl@0: /** sl@0: Trace level: sl@0: - 0: no IPC calls traced (default); sl@0: - 1: only the 10 most important IPC calls traced - SQL statement execution, .... sl@0: - 2: all IPC calls traced; sl@0: @internalComponent sl@0: */ sl@0: static TInt TheSqlSrvProfilerTraceLevel = 0; sl@0: /** sl@0: If true the SQL statement tracing is enabled. sl@0: @internalComponent sl@0: */ sl@0: static TBool TheSqlSrvProfilerSqlTraceEnabled = EFalse; sl@0: sl@0: /** sl@0: When KSqlSrvProfilerDbName is with non-zero length, then only traces coming from database identified by sl@0: KSqlSrvProfilerDbName name are printed out. sl@0: @internalComponent sl@0: */ sl@0: //_LIT(KSqlSrvProfilerDbName, "default_avacon.dbSQL"); sl@0: _LIT(KSqlSrvProfilerDbName, ""); sl@0: static TUint TheSqlSrvProfilerHandle = 0; sl@0: sl@0: //File "read", "write", "sync" and "set size" counters, incremented inside the OS porting layer. sl@0: TInt TheSqlSrvProfilerFileRead = 0; sl@0: TInt TheSqlSrvProfilerFileWrite = 0; sl@0: TInt TheSqlSrvProfilerFileSync = 0; sl@0: TInt TheSqlSrvProfilerFileSetSize = 0; sl@0: sl@0: //Set it to true if you want traces to be stored into a file. sl@0: static TBool TheSqlSrvProfilerTraceToFile = EFalse; sl@0: sl@0: //"Prepared" and "Executed" SQL statement counters sl@0: static TInt TheSqlSrvProfilerPreparedCnt8 = 0; sl@0: static TInt TheSqlSrvProfilerPreparedCnt16 = 0; sl@0: static TInt TheSqlSrvProfilerExecutedCnt8 = 0; sl@0: static TInt TheSqlSrvProfilerExecutedCnt16 = 0; sl@0: sl@0: ///////////////////////////////// IPC counters /////////////////////////////////////// sl@0: sl@0: /** sl@0: If true the IPC profiling is enabled. sl@0: @internalComponent sl@0: */ sl@0: TBool TheSqlSrvProfilerIpcEnabled = EFalse; sl@0: /** sl@0: IPC requests, read and write counters. sl@0: @internalComponent sl@0: */ sl@0: TInt TheSqlSrvProfilerIpc[ESqlIpcLast] = {0}; sl@0: /** sl@0: IPC read and write - bytes. sl@0: @internalComponent sl@0: */ sl@0: TInt64 TheSqlSrvProfilerIpcBytes[ESqlIpcLast] = {0}; sl@0: sl@0: ////////////////////////////////////////////////////////////////////////////////////// sl@0: sl@0: /** sl@0: Starts the specified profiling counter. sl@0: sl@0: @leave KErrNotSupported, The requested profiling type is not supported; sl@0: The function may also leave with some other system-wide error codes. sl@0: sl@0: Usage of the IPC call arguments: sl@0: - Arg 0: [in] profiling counter type, one of the TSqlResourceProfiler::TSqlCounter enum item values. sl@0: - Arg 1: [in] the length of the additional profiling parameters. sl@0: - Arg 2: [in] additional profiling parameters. sl@0: */ sl@0: void TSqlSrvResourceProfiler::StartL(const RMessage2& aMessage) sl@0: { sl@0: const TSqlResourceProfiler::TSqlCounter KCounterType = static_cast (aMessage.Int0()); sl@0: TInt err = KErrNone; sl@0: switch(KCounterType) sl@0: { sl@0: case TSqlResourceProfiler::ESqlCounterFileIO: sl@0: case TSqlResourceProfiler::ESqlCounterOsCall: sl@0: case TSqlResourceProfiler::ESqlCounterOsCallTime: sl@0: case TSqlResourceProfiler::ESqlCounterOsCallDetails: sl@0: err = sqlite3SymbianProfilerStart(KCounterType); sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterIpc: sl@0: TheSqlSrvProfilerIpcEnabled = ETrue; sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterMemory: sl@0: err = sqlite3SymbianProfilerStart(KCounterType); sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterMaxAlloc: sl@0: TheSqlSrvProfilerMaxAllocEnabled = ETrue; sl@0: err = sqlite3SymbianProfilerStart(KCounterType); sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterTrace: sl@0: { sl@0: TheSqlSrvProfilerTraceEnabled = ETrue; sl@0: TInt len = aMessage.Int1(); sl@0: __SQLPANIC_CLIENT2((TUint)len < 64, aMessage, ESqlPanicBadArgument); sl@0: if(len > 0) sl@0: { sl@0: TBuf8<64> prmBuf; sl@0: aMessage.ReadL(2, prmBuf); sl@0: prmBuf.UpperCase(); sl@0: TPtrC8 ptr(prmBuf); sl@0: _LIT8(KLevel0, "L0"); sl@0: _LIT8(KLevel1, "L1"); sl@0: _LIT8(KLevel2, "L2"); sl@0: _LIT8(KSqlStmtTraceOff, "S0"); sl@0: _LIT8(KSqlStmtTraceOn, "S1"); sl@0: while(ptr.Length() > 0) sl@0: { sl@0: TInt pos = ptr.Locate(TChar(';')); sl@0: TPtrC8 str = ptr; sl@0: if(pos >= 0) sl@0: { sl@0: str.Set(ptr.Left(pos)); sl@0: } sl@0: if(str == KLevel0) sl@0: { sl@0: TheSqlSrvProfilerTraceLevel = 0; sl@0: } sl@0: else if(str == KLevel1) sl@0: { sl@0: TheSqlSrvProfilerTraceLevel = 1; sl@0: } sl@0: else if(str == KLevel2) sl@0: { sl@0: TheSqlSrvProfilerTraceLevel = 2; sl@0: } sl@0: else if(str == KSqlStmtTraceOff) sl@0: { sl@0: TheSqlSrvProfilerSqlTraceEnabled = EFalse; sl@0: } sl@0: else if(str == KSqlStmtTraceOn) sl@0: { sl@0: TheSqlSrvProfilerSqlTraceEnabled = ETrue; sl@0: } sl@0: if((TUint)pos > (ptr.Length() - 1)) sl@0: { sl@0: break; sl@0: } sl@0: ptr.Set(ptr.Mid(pos + 1)); sl@0: } sl@0: } sl@0: } sl@0: break; sl@0: default: sl@0: err = KErrNotSupported; sl@0: break; sl@0: } sl@0: __SQLLEAVE_IF_ERROR2(err); sl@0: } sl@0: sl@0: /** sl@0: Stops the specified profiling counter. sl@0: sl@0: @leave KErrNotSupported, The requested profiling type is not supported; sl@0: The function may also leave with some other system-wide error codes. sl@0: sl@0: Usage of the IPC call arguments: sl@0: - Arg 0: [in] profiling counter type, one of the TSqlResourceProfiler::TSqlCounter enum item values. sl@0: */ sl@0: void TSqlSrvResourceProfiler::StopL(const RMessage2& aMessage) sl@0: { sl@0: const TSqlResourceProfiler::TSqlCounter KCounterType = static_cast (aMessage.Int0()); sl@0: TInt err = KErrNone; sl@0: switch(KCounterType) sl@0: { sl@0: case TSqlResourceProfiler::ESqlCounterFileIO: sl@0: case TSqlResourceProfiler::ESqlCounterOsCall: sl@0: case TSqlResourceProfiler::ESqlCounterOsCallTime: sl@0: case TSqlResourceProfiler::ESqlCounterOsCallDetails: sl@0: err = sqlite3SymbianProfilerStop(KCounterType); sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterIpc: sl@0: TheSqlSrvProfilerIpcEnabled = EFalse; sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterMemory: sl@0: err = sqlite3SymbianProfilerStop(KCounterType); sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterMaxAlloc: sl@0: TheSqlSrvProfilerMaxAllocEnabled = EFalse; sl@0: err = sqlite3SymbianProfilerStop(KCounterType); sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterTrace: sl@0: TheSqlSrvProfilerTraceEnabled = EFalse; sl@0: TheSqlSrvProfilerSqlTraceEnabled = EFalse; sl@0: TheSqlSrvProfilerTraceLevel = 0; sl@0: TheSqlSrvProfilerHandle = 0; sl@0: break; sl@0: default: sl@0: err = KErrNotSupported; sl@0: break; sl@0: } sl@0: __SQLLEAVE_IF_ERROR2(err); sl@0: } sl@0: sl@0: /** sl@0: Resets the specified profiling counter. sl@0: sl@0: @leave KErrNotSupported, The requested profiling type is not supported; sl@0: The function may also leave with some other system-wide error codes. sl@0: sl@0: Usage of the IPC call arguments: sl@0: - Arg 0: [in] profiling counter type, one of the TSqlResourceProfiler::TSqlCounter enum item values. sl@0: */ sl@0: void TSqlSrvResourceProfiler::ResetL(const RMessage2& aMessage) sl@0: { sl@0: const TSqlResourceProfiler::TSqlCounter KCounterType = static_cast (aMessage.Int0()); sl@0: TInt err = KErrNone; sl@0: switch(KCounterType) sl@0: { sl@0: case TSqlResourceProfiler::ESqlCounterFileIO: sl@0: case TSqlResourceProfiler::ESqlCounterOsCall: sl@0: case TSqlResourceProfiler::ESqlCounterOsCallTime: sl@0: case TSqlResourceProfiler::ESqlCounterOsCallDetails: sl@0: err = sqlite3SymbianProfilerReset(KCounterType); sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterIpc: sl@0: Mem::FillZ(TheSqlSrvProfilerIpc, sizeof(TheSqlSrvProfilerIpc)); sl@0: Mem::FillZ(TheSqlSrvProfilerIpcBytes, sizeof(TheSqlSrvProfilerIpcBytes)); sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterMemory: sl@0: err = sqlite3SymbianProfilerReset(KCounterType); sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterMaxAlloc: sl@0: TheSqlSrvProfilerMaxAllocSize = 0; sl@0: err = sqlite3SymbianProfilerReset(KCounterType); sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterTrace: sl@0: break; sl@0: default: sl@0: err = KErrNotSupported; sl@0: break; sl@0: } sl@0: __SQLLEAVE_IF_ERROR2(err); sl@0: } sl@0: sl@0: /** sl@0: Retrieves the counter values for the specified profiling counter. sl@0: sl@0: @leave KErrNotSupported, The requested profiling type is not supported; sl@0: The function may also leave with some other system-wide error codes. sl@0: sl@0: @see TSqlResourceProfiler sl@0: sl@0: Usage of the IPC call arguments: sl@0: - Arg 0: [in] profiling counter type, one of the TSqlResourceProfiler::TSqlCounter enum item values. sl@0: - Arg 1: [in] the size of the buffer for the profiling counter values. sl@0: - Arg 2: [out] the buffer for the profiling counter values. sl@0: */ sl@0: void TSqlSrvResourceProfiler::QueryL(const RMessage2& aMessage) sl@0: { sl@0: const TSqlResourceProfiler::TSqlCounter KCounterType = static_cast (aMessage.Int0()); sl@0: const TInt KIpcBufLen = 300; sl@0: TBuf8 ipcBuf; sl@0: TInt err = KErrNone; sl@0: switch(KCounterType) sl@0: { sl@0: case TSqlResourceProfiler::ESqlCounterFileIO: sl@0: case TSqlResourceProfiler::ESqlCounterOsCall: sl@0: case TSqlResourceProfiler::ESqlCounterOsCallTime: sl@0: case TSqlResourceProfiler::ESqlCounterOsCallDetails: sl@0: err = sqlite3SymbianProfilerQuery(KCounterType, ipcBuf); sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterIpc: sl@0: ipcBuf.AppendNum(TheSqlSrvProfilerIpc[ESqlIpcRq]); sl@0: ipcBuf.Append(TChar(';')); sl@0: ipcBuf.AppendNum(TheSqlSrvProfilerIpc[ESqlIpcRead]); sl@0: ipcBuf.Append(TChar(';')); sl@0: ipcBuf.AppendNum(TheSqlSrvProfilerIpc[ESqlIpcWrite]); sl@0: ipcBuf.Append(TChar(';')); sl@0: ipcBuf.AppendNum(TheSqlSrvProfilerIpcBytes[ESqlIpcRead]); sl@0: ipcBuf.Append(TChar(';')); sl@0: ipcBuf.AppendNum(TheSqlSrvProfilerIpcBytes[ESqlIpcWrite]); sl@0: ipcBuf.Append(TChar(';')); sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterMemory: sl@0: { sl@0: TInt totalAllocCells = 0; sl@0: TInt totalAllocSize = 0; sl@0: TInt totalFreeSpace = 0; sl@0: TInt biggestBlockSize = 0; sl@0: RHeap& heap = User::Heap();; sl@0: totalAllocCells = heap.AllocSize(totalAllocSize); sl@0: totalFreeSpace = heap.Available(biggestBlockSize); sl@0: ipcBuf.AppendNum(totalAllocCells); sl@0: ipcBuf.Append(TChar(';')); sl@0: ipcBuf.AppendNum(totalAllocSize); sl@0: ipcBuf.Append(TChar(';')); sl@0: ipcBuf.AppendNum(totalFreeSpace); sl@0: ipcBuf.Append(TChar(';')); sl@0: ipcBuf.AppendNum(biggestBlockSize); sl@0: ipcBuf.Append(TChar(';')); sl@0: err = sqlite3SymbianProfilerQuery(KCounterType, ipcBuf); sl@0: } sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterMaxAlloc: sl@0: ipcBuf.AppendNum(TheSqlSrvProfilerMaxAllocSize); sl@0: ipcBuf.Append(TChar(';')); sl@0: err = sqlite3SymbianProfilerQuery(KCounterType, ipcBuf); sl@0: break; sl@0: case TSqlResourceProfiler::ESqlCounterTrace: sl@0: break; sl@0: default: sl@0: err = KErrNotSupported; sl@0: break; sl@0: } sl@0: __SQLLEAVE_IF_ERROR2(err); sl@0: aMessage.WriteL(2, ipcBuf); sl@0: } sl@0: sl@0: ////////////////////////// IPC tracing related //////////////////////////////////////// sl@0: sl@0: //Max trace line length sl@0: const TInt KSqlTraceMaxLength = 220; sl@0: //Trace buffer. sl@0: static TBuf TheSqlTraceBuf; sl@0: sl@0: //IPC calls names - begin sl@0: _LIT(KSqlSrvDbCreate, "DbCreate"); sl@0: _LIT(KSqlSrvDbCreateSecure, "DbCreateSecure"); sl@0: _LIT(KSqlSrvDbOpen, "DbOpen"); sl@0: _LIT(KSqlSrvDbOpenFromHandle, "DbOpenFromHandle"); sl@0: _LIT(KSqlSrvDbClose, "DbClose"); sl@0: _LIT(KSqlSrvDbCopy, "DbCopy"); sl@0: _LIT(KSqlSrvDbDelete, "DbDelete"); sl@0: _LIT(KSqlSrvLastErrorMsg, "LastErrorMsg"); sl@0: _LIT(KSqlSrvDbExec8, "DbExec8"); sl@0: _LIT(KSqlSrvDbExec16, "DbExec16"); sl@0: _LIT(KSqlSrvDbSetIsolationLevel, "DbSetIsolationLevel"); sl@0: _LIT(KSqlSrvDbGetSecurityPolicy, "DbGetSecurityPolicy"); sl@0: _LIT(KSqlSrvDbAttach, "DbAttach"); sl@0: _LIT(KSqlSrvDbAttachFromHandle, "DbAttachFromHandle"); sl@0: _LIT(KSqlSrvDbDetach, "DbDetach"); sl@0: _LIT(KSqlSrvDbScalarFullSelect8, "DbScalarFullSelect8"); sl@0: _LIT(KSqlSrvDbScalarFullSelect16, "DbScalarFullSelect16"); sl@0: _LIT(KSqlSrvDbInTransaction, "DbInTransaction"); sl@0: _LIT(KSqlSrvDbSize, "DbSize"); sl@0: _LIT(KSqlSrvDbSize2, "DbSize2"); sl@0: _LIT(KSqlSrvDbBlobSource, "DbBlobSource"); sl@0: _LIT(KSqlSrvDbLastInsertedRowId, "DbLastInsertedRowId"); sl@0: _LIT(KSqlSrvDbCompact, "DbCompact"); sl@0: _LIT(KSqlSrvDbReserveDriveSpace, "DbReserveDriveSpace"); sl@0: _LIT(KSqlSrvDbFreeReservedSpace, "DbFreeReservedSpace"); sl@0: _LIT(KSqlSrvDbGetReserveAccess, "DbGetReserveAccess"); sl@0: _LIT(KSqlSrvDbReleaseReserveAccess, "DbReleaseReserveAccess"); sl@0: _LIT(KSqlSrvStmtPrepare8, "StmtPrepare8"); sl@0: _LIT(KSqlSrvStmtPrepare16, "StmtPrepare16"); sl@0: _LIT(KSqlSrvStmtClose, "StmtClose"); sl@0: _LIT(KSqlSrvStmtReset, "StmtReset"); sl@0: _LIT(KSqlSrvStmtExec, "StmtExec"); sl@0: _LIT(KSqlSrvStmtAsyncExec, "StmtAsyncExec"); sl@0: _LIT(KSqlSrvStmtBindExec, "StmtBindExec"); sl@0: _LIT(KSqlSrvStmtAsyncBindExec, "StmtAsyncBindExec"); sl@0: _LIT(KSqlSrvStmtNext, "StmtNext"); sl@0: _LIT(KSqlSrvStmtBindNext, "StmtBindNext"); sl@0: _LIT(KSqlSrvStmtColumnNames, "StmtColumnNames"); sl@0: _LIT(KSqlSrvStmtParamNames, "StmtParamNames"); sl@0: _LIT(KSqlSrvStmtColumnSource, "StmtColumnSource"); sl@0: _LIT(KSqlSrvStmtBinParamSink, "StmtBinParamSink"); sl@0: _LIT(KSqlSrvStmtTxtParamSink16, "StmtTxtParamSink16"); sl@0: _LIT(KSqlSrvStmtBufFlat, "StmtBufFlat"); sl@0: _LIT(KSqlSrvStmtColumnValue, "StmtColumnValue"); sl@0: _LIT(KSqlSrvStmtDeclColumnTypes, "StmtDeclColumnTypes"); sl@0: _LIT(KSqlSrvStreamRead, "StreamRead"); sl@0: _LIT(KSqlSrvStreamWrite, "StreamWrite"); sl@0: _LIT(KSqlSrvStreamSize, "StreamSize"); sl@0: _LIT(KSqlSrvStreamSynch, "StreamSynch"); sl@0: _LIT(KSqlSrvStreamClose, "StreamClose"); sl@0: //IPC calls names - end sl@0: sl@0: //Gets as an argument the IPC call type in "aCode" parameter. sl@0: //Returns: sl@0: // 0 or positive integer: the IPC call is one of the 10 most important IPC calls (trace level 0). sl@0: // KErrNotFound : the IPC call is some of the other possible call types (trace level 1). sl@0: // KErrNotSupported : unknown IPC call type. sl@0: // sl@0: // aIpcCallName will always be set to IPC call name descriptor. sl@0: static TInt SqlIpcTraceIdxAndName(TSqlSrvFunction aCode, TPtrC& aIpcCallName) sl@0: { sl@0: TInt rc = KErrNotFound; sl@0: switch(aCode) sl@0: { sl@0: case ESqlSrvDbCreate: sl@0: aIpcCallName.Set(KSqlSrvDbCreate); sl@0: break; sl@0: case ESqlSrvDbCreateSecure: sl@0: aIpcCallName.Set(KSqlSrvDbCreateSecure); sl@0: break; sl@0: case ESqlSrvDbOpen: sl@0: aIpcCallName.Set(KSqlSrvDbOpen); sl@0: break; sl@0: case ESqlSrvDbOpenFromHandle: sl@0: aIpcCallName.Set(KSqlSrvDbOpenFromHandle); sl@0: break; sl@0: case ESqlSrvDbClose: sl@0: aIpcCallName.Set(KSqlSrvDbClose); sl@0: break; sl@0: case ESqlSrvDbCopy: sl@0: aIpcCallName.Set(KSqlSrvDbCopy); sl@0: break; sl@0: case ESqlSrvDbDelete: sl@0: aIpcCallName.Set(KSqlSrvDbDelete); sl@0: break; sl@0: case ESqlSrvLastErrorMsg: sl@0: aIpcCallName.Set(KSqlSrvLastErrorMsg); sl@0: break; sl@0: case ESqlSrvDbExec8: sl@0: aIpcCallName.Set(KSqlSrvDbExec8); sl@0: rc = 0; sl@0: break; sl@0: case ESqlSrvDbExec16: sl@0: aIpcCallName.Set(KSqlSrvDbExec16); sl@0: rc = 1; sl@0: break; sl@0: case ESqlSrvDbSetIsolationLevel: sl@0: aIpcCallName.Set(KSqlSrvDbSetIsolationLevel); sl@0: break; sl@0: case ESqlSrvDbGetSecurityPolicy: sl@0: aIpcCallName.Set(KSqlSrvDbGetSecurityPolicy); sl@0: break; sl@0: case ESqlSrvDbAttach: sl@0: aIpcCallName.Set(KSqlSrvDbAttach); sl@0: break; sl@0: case ESqlSrvDbAttachFromHandle: sl@0: aIpcCallName.Set(KSqlSrvDbAttachFromHandle); sl@0: break; sl@0: case ESqlSrvDbDetach: sl@0: aIpcCallName.Set(KSqlSrvDbDetach); sl@0: break; sl@0: case ESqlSrvDbScalarFullSelect8: sl@0: aIpcCallName.Set(KSqlSrvDbScalarFullSelect8); sl@0: rc = 2; sl@0: break; sl@0: case ESqlSrvDbScalarFullSelect16: sl@0: aIpcCallName.Set(KSqlSrvDbScalarFullSelect16); sl@0: rc = 3; sl@0: break; sl@0: case ESqlSrvDbInTransaction: sl@0: aIpcCallName.Set(KSqlSrvDbInTransaction); sl@0: break; sl@0: case ESqlSrvDbSize: sl@0: aIpcCallName.Set(KSqlSrvDbSize); sl@0: break; sl@0: case ESqlSrvDbSize2: sl@0: aIpcCallName.Set(KSqlSrvDbSize2); sl@0: break; sl@0: case ESqlSrvDbBlobSource: sl@0: aIpcCallName.Set(KSqlSrvDbBlobSource); sl@0: break; sl@0: case ESqlSrvDbLastInsertedRowId: sl@0: aIpcCallName.Set(KSqlSrvDbLastInsertedRowId); sl@0: break; sl@0: case ESqlSrvDbCompact: sl@0: aIpcCallName.Set(KSqlSrvDbCompact); sl@0: break; sl@0: case ESqlSrvDbReserveDriveSpace: sl@0: aIpcCallName.Set(KSqlSrvDbReserveDriveSpace); sl@0: break; sl@0: case ESqlSrvDbFreeReservedSpace: sl@0: aIpcCallName.Set(KSqlSrvDbFreeReservedSpace); sl@0: break; sl@0: case ESqlSrvDbGetReserveAccess: sl@0: aIpcCallName.Set(KSqlSrvDbGetReserveAccess); sl@0: break; sl@0: case ESqlSrvDbReleaseReserveAccess: sl@0: aIpcCallName.Set(KSqlSrvDbReleaseReserveAccess); sl@0: break; sl@0: case ESqlSrvStmtPrepare8: sl@0: aIpcCallName.Set(KSqlSrvStmtPrepare8); sl@0: break; sl@0: case ESqlSrvStmtPrepare16: sl@0: aIpcCallName.Set(KSqlSrvStmtPrepare16); sl@0: break; sl@0: case ESqlSrvStmtClose: sl@0: aIpcCallName.Set(KSqlSrvStmtClose); sl@0: break; sl@0: case ESqlSrvStmtReset: sl@0: aIpcCallName.Set(KSqlSrvStmtReset); sl@0: break; sl@0: case ESqlSrvStmtExec: sl@0: aIpcCallName.Set(KSqlSrvStmtExec); sl@0: rc = 4; sl@0: break; sl@0: case ESqlSrvStmtAsyncExec: sl@0: aIpcCallName.Set(KSqlSrvStmtAsyncExec); sl@0: rc = 5; sl@0: break; sl@0: case ESqlSrvStmtBindExec: sl@0: aIpcCallName.Set(KSqlSrvStmtBindExec); sl@0: rc = 6; sl@0: break; sl@0: case ESqlSrvStmtAsyncBindExec: sl@0: aIpcCallName.Set(KSqlSrvStmtAsyncBindExec); sl@0: rc = 7; sl@0: break; sl@0: case ESqlSrvStmtNext: sl@0: aIpcCallName.Set(KSqlSrvStmtNext); sl@0: rc = 8; sl@0: break; sl@0: case ESqlSrvStmtBindNext: sl@0: aIpcCallName.Set(KSqlSrvStmtBindNext); sl@0: rc = 9; sl@0: break; sl@0: case ESqlSrvStmtColumnNames: sl@0: aIpcCallName.Set(KSqlSrvStmtColumnNames); sl@0: break; sl@0: case ESqlSrvStmtParamNames: sl@0: aIpcCallName.Set(KSqlSrvStmtParamNames); sl@0: break; sl@0: case ESqlSrvStmtColumnSource: sl@0: aIpcCallName.Set(KSqlSrvStmtColumnSource); sl@0: break; sl@0: case ESqlSrvStmtBinParamSink: sl@0: aIpcCallName.Set(KSqlSrvStmtBinParamSink); sl@0: break; sl@0: case ESqlSrvStmtTxtParamSink16: sl@0: aIpcCallName.Set(KSqlSrvStmtTxtParamSink16); sl@0: break; sl@0: case ESqlSrvStmtBufFlat: sl@0: aIpcCallName.Set(KSqlSrvStmtBufFlat); sl@0: break; sl@0: case ESqlSrvStmtColumnValue: sl@0: aIpcCallName.Set(KSqlSrvStmtColumnValue); sl@0: break; sl@0: case ESqlSrvStmtDeclColumnTypes: sl@0: aIpcCallName.Set(KSqlSrvStmtDeclColumnTypes); sl@0: break; sl@0: case ESqlSrvStreamRead: sl@0: aIpcCallName.Set(KSqlSrvStreamRead); sl@0: break; sl@0: case ESqlSrvStreamWrite: sl@0: aIpcCallName.Set(KSqlSrvStreamWrite); sl@0: break; sl@0: case ESqlSrvStreamSize: sl@0: aIpcCallName.Set(KSqlSrvStreamSize); sl@0: break; sl@0: case ESqlSrvStreamSynch: sl@0: aIpcCallName.Set(KSqlSrvStreamSynch); sl@0: break; sl@0: case ESqlSrvStreamClose: sl@0: aIpcCallName.Set(KSqlSrvStreamClose); sl@0: break; sl@0: default: sl@0: return KErrNotSupported; sl@0: }; sl@0: __ASSERT_DEBUG((TUint)rc < KIpcTraceTypeCount || rc == KErrNotFound, __SQLPANIC2(ESqlPanicInternalError)); sl@0: return rc; sl@0: } sl@0: sl@0: //Calculates and returns the time difference between aStartTicks and aEndTicks in microseconds. sl@0: static TInt SqlConvertTicks2Us(TUint32 aStartTicks, TUint32 aEndTicks) sl@0: { sl@0: static TInt freq = 0; sl@0: if(freq == 0) sl@0: { sl@0: TInt err = HAL::Get(HAL::EFastCounterFrequency, freq); sl@0: if(err != KErrNone) sl@0: { sl@0: __SQLPANIC2((TSqlPanic)err); sl@0: } sl@0: } sl@0: TInt64 diffTicks = (TInt64)aEndTicks - (TInt64)aStartTicks; sl@0: if(diffTicks < 0) sl@0: { sl@0: diffTicks = KMaxTUint32 + diffTicks + 1; sl@0: } sl@0: const TInt KMicroSecIn1Sec = 1000000; sl@0: TInt32 us = (diffTicks * KMicroSecIn1Sec) / freq; sl@0: return us; sl@0: } sl@0: sl@0: //Calculates the time since the first time this function has been called. sl@0: static TInt64 SqlTimeFromStartUs() sl@0: { sl@0: struct TStartTime sl@0: { sl@0: inline TStartTime() sl@0: { sl@0: iTime.UniversalTime(); sl@0: } sl@0: TTime iTime; sl@0: }; sl@0: static TStartTime startTime; sl@0: TTime time; sl@0: time.UniversalTime(); sl@0: TTimeIntervalMicroSeconds us = time.MicroSecondsFrom(startTime.iTime); sl@0: const TInt64 KMaxDiff = 999999999999LL;//999999999999 is the max number that can be printed out using %12ld format spec sl@0: if(us.Int64() < 0 || us.Int64() >= KMaxDiff) sl@0: { sl@0: startTime.iTime = time; sl@0: us = 0; sl@0: } sl@0: return us.Int64(); sl@0: } sl@0: sl@0: sl@0: //Tracing data buffer sl@0: const TInt KSqlSrvProfilePrnBufSize = 300; sl@0: static TBuf TheSqlSrvProfileTraceBuf; sl@0: static TBuf8 TheSqlSrvProfileTraceBuf8; sl@0: sl@0: static RFs TheSqlSrvTraceFs; sl@0: static RFile TheTheSqlSrvTraceFile; sl@0: _LIT(KSqlSrvTraceFileName, "C:\\SQLTRACE"); sl@0: sl@0: //Prints out a time stamp sl@0: static void SqlSrvProfileTimePrintf() sl@0: { sl@0: static TInt64 prevTimeDiff = 0;; sl@0: TInt64 timeDiff = SqlTimeFromStartUs(); sl@0: const TInt64 KTimeInterval = 1000000; sl@0: if((timeDiff - prevTimeDiff) >= KTimeInterval || timeDiff < prevTimeDiff) sl@0: { sl@0: prevTimeDiff = timeDiff; sl@0: TTime time; sl@0: time.UniversalTime(); sl@0: TDateTime dt = time.DateTime(); sl@0: TheSqlSrvProfileTraceBuf8.Format(_L8("[SQL]¬\"%X\"¬¬TME¬¬¬¬¬¬¬¬¬¬¬¬%02d:%02d:%02d:%06d¬Prep8¬%d¬Prep16¬%d¬Ex8¬%d¬Ex16¬%d"), sl@0: timeDiff, dt.Hour(), dt.Minute(), dt.Second(), dt.MicroSecond(), sl@0: TheSqlSrvProfilerPreparedCnt8, TheSqlSrvProfilerPreparedCnt16, sl@0: TheSqlSrvProfilerExecutedCnt8, TheSqlSrvProfilerExecutedCnt16); sl@0: if(TheSqlSrvProfilerTraceToFile) sl@0: { sl@0: TheSqlSrvProfileTraceBuf8.Append(_L8("\r\n")); sl@0: (void)TheTheSqlSrvTraceFile.Write(TheSqlSrvProfileTraceBuf8); sl@0: } sl@0: else sl@0: { sl@0: TheSqlSrvProfileTraceBuf8.Append(_L8("\n")); sl@0: RDebug::RawPrint(TheSqlSrvProfileTraceBuf8); sl@0: } sl@0: } sl@0: } sl@0: sl@0: //Trace types sl@0: enum TSqlSrvProfilerTraceType sl@0: { sl@0: ESqlSrvProfilerNonSqlTrace, sl@0: ESqlSrvProfilerMiddleLineSqlTrace, sl@0: ESqlSrvProfilerLastLineSqlTrace sl@0: }; sl@0: sl@0: //Prints out the data that is in TheSqlSrvProfileTraceBuf. sl@0: // aType = ESqlSrvProfilerNonSqlTrace - non-SQL trace sl@0: // aType = ESqlSrvProfilerMiddleLineSqlTrace - not last line of an SQL trace sl@0: // aType = ESqlSrvProfilerLastLineSqlTrace - last line of an SQL trace sl@0: static void SqlSrvProfilePrintf(TSqlSrvProfilerTraceType aType) sl@0: { sl@0: SqlSrvProfileTimePrintf(); sl@0: TheSqlSrvProfileTraceBuf8.Copy(TheSqlSrvProfileTraceBuf); sl@0: if(TheSqlSrvProfilerTraceToFile) sl@0: { sl@0: if(aType == 0 || aType == 2) sl@0: { sl@0: TheSqlSrvProfileTraceBuf8.Append(_L8("\r\n")); sl@0: } sl@0: (void)TheTheSqlSrvTraceFile.Write(TheSqlSrvProfileTraceBuf8); sl@0: } sl@0: else sl@0: { sl@0: TheSqlSrvProfileTraceBuf8.Append(_L8("\n")); sl@0: RDebug::RawPrint(TheSqlSrvProfileTraceBuf8); sl@0: } sl@0: } sl@0: sl@0: //Called at the beginning of CSqlSrvSession::ServiceL(). sl@0: void SqlIpcStart(TUint& aIpcCounter, TUint32& aStartTicks, TUint aDbHandle) sl@0: { sl@0: if(TheSqlSrvProfilerTraceEnabled) sl@0: { sl@0: TheSqlSrvProfilerFileRead = TheSqlSrvProfilerFileWrite = TheSqlSrvProfilerFileSync = TheSqlSrvProfilerFileSetSize = 0; sl@0: if(TheSqlSrvProfilerTraceLevel == 0) sl@0: { sl@0: return; sl@0: } sl@0: if(KSqlSrvProfilerDbName().Length() > 0 && (aDbHandle == 0 || TheSqlSrvProfilerHandle != aDbHandle)) sl@0: { sl@0: return; sl@0: } sl@0: ++aIpcCounter; sl@0: aStartTicks = User::FastCounter(); sl@0: } sl@0: } sl@0: sl@0: //Called at the end of CSqlSrvSession::ServiceL(). sl@0: void SqlIpcEnd(TUint aIpcCounter, TUint32 aStartTicks, TSqlSrvFunction aFuncCode, sl@0: TUint aDbHandle, TSqlSrvIpcTraceData aIpcTraceData[], TInt aRetCode) sl@0: { sl@0: if(TheSqlSrvProfilerTraceEnabled) sl@0: { sl@0: if(TheSqlSrvProfilerTraceLevel == 0) sl@0: { sl@0: return; sl@0: } sl@0: if(KSqlSrvProfilerDbName().Length() > 0 && (aDbHandle == 0 || TheSqlSrvProfilerHandle != aDbHandle)) sl@0: { sl@0: return; sl@0: } sl@0: TUint32 endTicks = User::FastCounter(); sl@0: TInt executionTime = SqlConvertTicks2Us(aStartTicks, endTicks); sl@0: TPtrC ipcCallName; sl@0: TInt ipcCallIdx = SqlIpcTraceIdxAndName(aFuncCode, ipcCallName); sl@0: TInt64 timeFromStart = SqlTimeFromStartUs(); sl@0: TInt64 ttlExecTime = 0; sl@0: TInt count = 0; sl@0: if(ipcCallIdx >= 0) sl@0: { sl@0: aIpcTraceData[ipcCallIdx].iExecutionTime += executionTime; sl@0: ttlExecTime = aIpcTraceData[ipcCallIdx].iExecutionTime; sl@0: count = ++aIpcTraceData[ipcCallIdx].iCount; sl@0: } sl@0: if(ipcCallIdx >= 0 || (ipcCallIdx == KErrNotFound && TheSqlSrvProfilerTraceLevel == 2)) sl@0: { sl@0: TheSqlSrvProfileTraceBuf.Format(_L("[SQL]¬\"%X\"¬%ld¬IPC¬%u¬%S¬%ld¬%d¬%d¬%d¬%d¬%d¬%d¬rc¬%d"), sl@0: //[SQL] sl@0: aDbHandle, //Database handle sl@0: timeFromStart, //Time from start, microseconds sl@0: //IPC sl@0: aIpcCounter, //IPC sequence counter for this database (connection) sl@0: &ipcCallName, //IPC call name sl@0: ttlExecTime, //All time spent in this IPC call type for this database (connection) sl@0: executionTime, //This IPC call execution time sl@0: count, //This IPC call sequence counter for this database (connection) sl@0: TheSqlSrvProfilerFileRead, //File read count, performed during this IPC sl@0: TheSqlSrvProfilerFileWrite, //File write count, performed during this IPC sl@0: TheSqlSrvProfilerFileSync, //File flush count, performed during this IPC sl@0: TheSqlSrvProfilerFileSetSize, //File set size count, performed during this IPC sl@0: aRetCode); //IPC call - return code sl@0: SqlSrvProfilePrintf(ESqlSrvProfilerNonSqlTrace); sl@0: } sl@0: } sl@0: } sl@0: sl@0: //Called at the end of CSqlSrvSession::ServiceError(). sl@0: void SqlIpcError(TUint aIpcCounter, TSqlSrvFunction aFuncCode, TUint aDbHandle, TInt aError) sl@0: { sl@0: if(TheSqlSrvProfilerTraceEnabled) sl@0: { sl@0: if(KSqlSrvProfilerDbName().Length() > 0 && (aDbHandle == 0 || TheSqlSrvProfilerHandle != aDbHandle)) sl@0: { sl@0: return; sl@0: } sl@0: TPtrC ipcCallName; sl@0: (void)SqlIpcTraceIdxAndName(aFuncCode, ipcCallName); sl@0: TInt64 timeFromStart = SqlTimeFromStartUs(); sl@0: TheSqlSrvProfileTraceBuf.Format(_L("[SQL]¬\"%X\"¬%ld¬ERR¬%u¬%S¬¬¬¬¬¬¬¬err¬%d"), sl@0: //[SQL] sl@0: aDbHandle, //Database (connection) handle sl@0: timeFromStart, //Time from start, microseconds sl@0: //ERR sl@0: aIpcCounter, //IPC sequence counter for this database (connection) sl@0: &ipcCallName, //IPC call name sl@0: aError); //IPC call - return code sl@0: SqlSrvProfilePrintf(ESqlSrvProfilerNonSqlTrace); sl@0: } sl@0: } sl@0: sl@0: //Prints the passed as a parameter 16-bit SQL statement. sl@0: void SqlPrintSql16(TUint aDbHandle, const TDesC& aSql, TBool aPrepare) sl@0: { sl@0: if(!TheSqlSrvProfilerTraceEnabled || !TheSqlSrvProfilerSqlTraceEnabled) sl@0: { sl@0: return; sl@0: } sl@0: if(KSqlSrvProfilerDbName().Length() > 0 && (aDbHandle == 0 || TheSqlSrvProfilerHandle != aDbHandle)) sl@0: { sl@0: return; sl@0: } sl@0: sl@0: aPrepare ? ++TheSqlSrvProfilerPreparedCnt16 : ++TheSqlSrvProfilerExecutedCnt16; sl@0: sl@0: TInt64 timeFromStart = SqlTimeFromStartUs(); sl@0: TPtr line((TUint16*)TheSqlTraceBuf.Ptr(), 0, TheSqlTraceBuf.MaxLength()); sl@0: TInt len = aSql.Length(); sl@0: TInt pos = 0; sl@0: do sl@0: { sl@0: _LIT(KPrepare, "Prepare16"); sl@0: _LIT(KExec, "Exec16"); sl@0: _LIT(KEmptyStr, ""); sl@0: if(pos == 0) sl@0: { sl@0: line.Format(_L("[SQL]¬\"%X\"¬%ld¬SQL¬¬%S¬¬¬¬¬¬¬¬¬¬"), aDbHandle, timeFromStart, aPrepare ? &KPrepare : &KExec); sl@0: } sl@0: else sl@0: { sl@0: if(!TheSqlSrvProfilerTraceToFile) sl@0: { sl@0: line.Format(_L("[SQL]¬\"%X\"¬%ld¬SQL¬¬%S¬¬¬¬¬¬¬¬¬¬"), aDbHandle, timeFromStart, &KEmptyStr); sl@0: } sl@0: } sl@0: TInt l = Min(len, (line.MaxLength() - line.Length())); sl@0: TPtrC ptr(aSql.Ptr() + pos, l); sl@0: pos += l; sl@0: len -= l; sl@0: line.Append(ptr); sl@0: TheSqlSrvProfileTraceBuf.Format(_L("%S"), &line); sl@0: SqlSrvProfilePrintf(len > 0 ? ESqlSrvProfilerMiddleLineSqlTrace : ESqlSrvProfilerLastLineSqlTrace); sl@0: line.Zero(); sl@0: } while(len > 0); sl@0: } sl@0: sl@0: //Prints the passed as a parameter 8-bit SQL statement. sl@0: void SqlPrintSql8(TUint aDbHandle, const TDesC8& aSql, TBool aPrepare) sl@0: { sl@0: if(!TheSqlSrvProfilerTraceEnabled || !TheSqlSrvProfilerSqlTraceEnabled) sl@0: { sl@0: return; sl@0: } sl@0: if(KSqlSrvProfilerDbName().Length() > 0 && (aDbHandle == 0 || TheSqlSrvProfilerHandle != aDbHandle)) sl@0: { sl@0: return; sl@0: } sl@0: sl@0: aPrepare ? ++TheSqlSrvProfilerPreparedCnt8 : ++TheSqlSrvProfilerExecutedCnt8; sl@0: sl@0: TInt64 timeFromStart = SqlTimeFromStartUs(); sl@0: TPtr line((TUint16*)TheSqlTraceBuf.Ptr(), 0, TheSqlTraceBuf.MaxLength()); sl@0: TInt len = aSql.Length(); sl@0: TInt pos = 0; sl@0: do sl@0: { sl@0: _LIT(KPrepare, "Prepare8"); sl@0: _LIT(KExec, "Exec8"); sl@0: _LIT(KEmptyStr, ""); sl@0: if(pos == 0) sl@0: { sl@0: line.Format(_L("[SQL]¬\"%X\"¬%ld¬SQL¬¬%S¬¬¬¬¬¬¬¬¬¬"), aDbHandle, timeFromStart, aPrepare ? &KPrepare : &KExec); sl@0: } sl@0: else sl@0: { sl@0: if(!TheSqlSrvProfilerTraceToFile) sl@0: { sl@0: line.Format(_L("[SQL]¬\"%X\"¬%ld¬SQL¬¬%S¬¬¬¬¬¬¬¬¬¬"), aDbHandle, timeFromStart, &KEmptyStr); sl@0: } sl@0: } sl@0: TInt l = Min(len, (line.MaxLength() - line.Length())); sl@0: TPtrC8 ptr(aSql.Ptr() + pos, l); sl@0: pos += l; sl@0: len -= l; sl@0: TPtr p2((TUint16*)line.Ptr() + line.Length(), 0, l); sl@0: p2.Copy(ptr); sl@0: line.SetLength(line.Length() + p2.Length()); sl@0: TheSqlSrvProfileTraceBuf.Format(_L("%S"), &line); sl@0: SqlSrvProfilePrintf(len > 0 ? ESqlSrvProfilerMiddleLineSqlTrace : ESqlSrvProfilerLastLineSqlTrace); sl@0: line.Zero(); sl@0: } while(len > 0); sl@0: } sl@0: sl@0: //Prints the name of the just created database. sl@0: void SqlPrintDbCreate(TUint aDbHandle, const TDesC& aDbName) sl@0: { sl@0: if(TheSqlSrvProfilerTraceEnabled) sl@0: { sl@0: if(KSqlSrvProfilerDbName().Length() > 0 && aDbName.FindF(KSqlSrvProfilerDbName) >= 0) sl@0: { sl@0: TheSqlSrvProfilerHandle = aDbHandle; sl@0: } sl@0: if(KSqlSrvProfilerDbName().Length() > 0 && (aDbHandle == 0 || TheSqlSrvProfilerHandle != aDbHandle)) sl@0: { sl@0: return; sl@0: } sl@0: TInt64 timeFromStart = SqlTimeFromStartUs(); sl@0: TheSqlSrvProfileTraceBuf.Format(_L("[SQL]¬\"%X\"¬%ld¬CRE¬¬¬¬¬¬¬¬¬¬¬¬%S"), sl@0: aDbHandle, sl@0: timeFromStart, sl@0: &aDbName); sl@0: SqlSrvProfilePrintf(ESqlSrvProfilerNonSqlTrace); sl@0: } sl@0: } sl@0: sl@0: //Prints the name of the just opened database. sl@0: void SqlPrintDbOpen(TUint aDbHandle, const TDesC& aDbName) sl@0: { sl@0: if(TheSqlSrvProfilerTraceEnabled) sl@0: { sl@0: if(KSqlSrvProfilerDbName().Length() > 0 && aDbName.FindF(KSqlSrvProfilerDbName) >= 0) sl@0: { sl@0: TheSqlSrvProfilerHandle = aDbHandle; sl@0: } sl@0: if(KSqlSrvProfilerDbName().Length() > 0 && (aDbHandle == 0 || TheSqlSrvProfilerHandle != aDbHandle)) sl@0: { sl@0: return; sl@0: } sl@0: TInt64 timeFromStart = SqlTimeFromStartUs(); sl@0: TheSqlSrvProfileTraceBuf.Format(_L("[SQL]¬\"%X\"¬%ld¬OPN¬¬¬¬¬¬¬¬¬¬¬¬%S"), sl@0: aDbHandle, sl@0: timeFromStart, sl@0: &aDbName); sl@0: SqlSrvProfilePrintf(ESqlSrvProfilerNonSqlTrace); sl@0: } sl@0: } sl@0: sl@0: //Prints the handle of the just closed database. sl@0: void SqlPrintDbClose(TUint aDbHandle) sl@0: { sl@0: if(TheSqlSrvProfilerTraceEnabled) sl@0: { sl@0: if(KSqlSrvProfilerDbName().Length() > 0 && (aDbHandle == 0 || TheSqlSrvProfilerHandle != aDbHandle)) sl@0: { sl@0: return; sl@0: } sl@0: TInt64 timeFromStart = SqlTimeFromStartUs(); sl@0: TheSqlSrvProfileTraceBuf.Format(_L("[SQL]¬\"%X\"¬%ld¬CSE"), sl@0: aDbHandle, sl@0: timeFromStart); sl@0: SqlSrvProfilePrintf(ESqlSrvProfilerNonSqlTrace); sl@0: if(aDbHandle == TheSqlSrvProfilerHandle) sl@0: { sl@0: TheSqlSrvProfilerHandle = 0; sl@0: } sl@0: } sl@0: } sl@0: sl@0: //Prints a trace when the SQL server starts sl@0: void SqlPrintServerStart() sl@0: { sl@0: TInt64 timeFromStart = SqlTimeFromStartUs(); sl@0: if(TheSqlSrvProfilerTraceToFile) sl@0: { sl@0: TInt err = TheSqlSrvTraceFs.Connect(); sl@0: if(err == KErrNone) sl@0: { sl@0: TInt fileNum = 0; sl@0: err = KErrGeneral; sl@0: while(++fileNum < 1000 && err != KErrNone) sl@0: { sl@0: TBuf<80> ftrname; sl@0: ftrname.Copy(KSqlSrvTraceFileName); sl@0: ftrname.AppendNum(fileNum); sl@0: ftrname.Append(_L(".txt")); sl@0: err = TheTheSqlSrvTraceFile.Create(TheSqlSrvTraceFs, ftrname, EFileRead | EFileWrite); sl@0: if(err == KErrNone) sl@0: { sl@0: break; sl@0: } sl@0: } sl@0: } sl@0: if(err != KErrNone) sl@0: { sl@0: TheSqlSrvTraceFs.Close(); sl@0: TheSqlSrvProfilerTraceToFile = EFalse; sl@0: RDebug::Print(_L("SQL trace file creation failed with err=%d"), err); sl@0: } sl@0: } sl@0: TheSqlSrvProfileTraceBuf.Format(_L("[SQL]¬¬%ld¬SRV¬¬Start"), timeFromStart); sl@0: SqlSrvProfilePrintf(ESqlSrvProfilerNonSqlTrace); sl@0: } sl@0: sl@0: //Prints a trace when the SQL server stops sl@0: void SqlPrintServerStop() sl@0: { sl@0: TInt64 timeFromStart = SqlTimeFromStartUs(); sl@0: TheSqlSrvProfileTraceBuf.Format(_L("[SQL]¬¬%ld¬SRV¬¬Stop"), timeFromStart); sl@0: SqlSrvProfilePrintf(ESqlSrvProfilerNonSqlTrace); sl@0: if(TheSqlSrvProfilerTraceToFile) sl@0: { sl@0: TheTheSqlSrvTraceFile.Close(); sl@0: TheSqlSrvTraceFs.Close(); sl@0: } sl@0: } sl@0: sl@0: #else //_SQLPROFILER sl@0: sl@0: void TSqlSrvResourceProfiler::StartL(const RMessage2&) sl@0: { sl@0: __SQLLEAVE2(KErrNotSupported); sl@0: } sl@0: sl@0: void TSqlSrvResourceProfiler::StopL(const RMessage2&) sl@0: { sl@0: __SQLLEAVE2(KErrNotSupported); sl@0: } sl@0: sl@0: void TSqlSrvResourceProfiler::ResetL(const RMessage2&) sl@0: { sl@0: __SQLLEAVE2(KErrNotSupported); sl@0: } sl@0: sl@0: void TSqlSrvResourceProfiler::QueryL(const RMessage2&) sl@0: { sl@0: __SQLLEAVE2(KErrNotSupported); sl@0: } sl@0: sl@0: #endif//_SQLPROFILER