persistentstorage/sql/INC/SqlResourceProfiler.h
changeset 0 08ec8eefde2f
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2008-2009 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 // Symbian SQL Resource Profiler header file
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 #ifndef __SQLRESOURCEPROFILER_H__
       
    23 #define __SQLRESOURCEPROFILER_H__
       
    24 
       
    25 #include <sqldb.h>
       
    26 
       
    27 /**
       
    28 Symbian SQL profiling interface.
       
    29 TSqlResourceProfiler class is used for:
       
    30 
       
    31 @code
       
    32 
       
    33  -	Retrieving the current state of the SQL server heap and SQLite heap stats.
       
    34    	Example:
       
    35 		RSqlDatabase db;
       
    36 		//initialize the db object....
       
    37 		...
       
    38 		TSqlResourceProfiler profiler(db);
       
    39 		profiler.Start(TSqlResourceProfiler::ESqlCounterMemory);//Start the profiling
       
    40 		profiler.Reset(TSqlResourceProfiler::ESqlCounterMemory);//Zero the porfiling counters
       
    41 		....
       
    42 		profiler.Stop(TSqlResourceProfiler::ESqlCounterMemory); //Stop the profiling
       
    43 		TBuf8<128> res;
       
    44 		profiler.Query(TSqlResourceProfiler::ESqlCounterMemory, res);
       
    45 	The format of the retrieved counters is:   
       
    46 		"<Allocated cells count>;<Allocated size>;<Free space>;<Largest block size>;
       
    47 		 <SQLite: allocated cnt>;<SQLite: reallocated cnt>;<SQLite: freed cnt>;
       
    48 		 <SQLite: allocated bytes>;<SQLite: freed bytes>;
       
    49 		 <SQLite: time spent in alloc(), us>;<SQLite: time spent in realloc(), us>;<SQLite: time spent in free(), us>;";
       
    50 	This service can be used only if the SQL code is compiled with the _SQLPROFILER macro.
       
    51 		
       
    52  - Retrieving the size of the biggest memory block ever allocated by the Symbian SQL server and SQLite.
       
    53    	Example:
       
    54 		RSqlDatabase db;
       
    55 		//initialize the db object....
       
    56 		...
       
    57 		TSqlResourceProfiler profiler(db);
       
    58 		.....
       
    59 		profiler.Start(TSqlResourceProfiler::ESqlCounterMaxAlloc);//Start the profiling
       
    60 		.....
       
    61 		TBuf8<32> res;
       
    62 		profiler.Query(TSqlResourceProfiler::ESqlCounterMaxAlloc, res);
       
    63 		...
       
    64 		profiler.Reset(TSqlResourceProfiler::ESqlCounterMaxAlloc);//Reset the profiling 
       
    65 		....
       
    66 		profiler.Stop(TSqlResourceProfiler::ESqlCounterMaxAlloc);
       
    67 	The format of the retrieved counters is: 
       
    68 		"<SQL server - max alloc size>;<SQLite - max alloc size>";
       
    69 	This service can be used only if the SQL code is compiled with the _SQLPROFILER macro.
       
    70 
       
    71  - Retrieving the number of the file system calls made by the OS porting layer and the amount of written/read data.
       
    72   	Example:
       
    73 		RSqlDatabase db;
       
    74 		//initialize the db object....
       
    75 		...
       
    76 		TSqlResourceProfiler profiler(db);
       
    77 		.....
       
    78 		profiler.Start(TSqlResourceProfiler::ESqlCounterFileIO);//Start the profiling
       
    79 		.....
       
    80 		TBuf8<300> res;
       
    81 		profiler.Query(TSqlResourceProfiler::ESqlCounterFileIO, res);
       
    82 		.....
       
    83 		profiler.Reset(TSqlResourceProfiler::ESqlCounterFileIO);//Reset the profiling 
       
    84 		....
       
    85 		profiler.Stop(TSqlResourceProfiler::ESqlCounterFileIO);
       
    86 	The format of the retrieved data is: 
       
    87 	"<RFileBuf64::Create() cnt>;<RFileBuf64::Open() cnt>;<RFileBuf64::Close() cnt>;<RFs::Delete() cnt>;
       
    88 	 <RFileBuf64::Read() cnt>;<RFileBuf64::Write() cnt>;<RFileBuf64::Seek() cnt>;<RFileBuf64::Size() cnt>;<RFileBuf64::SetSize() cnt>;
       
    89 	 <RFileBuf64::Flush() cnt>;<RFile64::Drive() cnt>;<RFileBuf64::AdoptFromClient() cnt>;<RFs::Close() cnt>;
       
    90 	 <RFs::Connect() cnt>;<RFs::GetSystemDrive() cnt>;<RFs::CreatePrivatePath() cnt>;<RFs::PrivatePath() cnt>;
       
    91 	 <RFs::VolumeIoParam() cnt>;<RFs::Entry() cnt>;<RFs::Att() cnt>;<RFileBuf64::Temp() cnt>;<0>;
       
    92 	 <bytes written>;<bytes read>;"
       
    93 	Note that currently the file operations are buffered, so the retrieved results will be about the operations executed on a
       
    94 	RFileBuf64 objects.
       
    95 	This service can be used only if the SQL code is compiled with the _SQLPROFILER macro.
       
    96 
       
    97  - Retrieving information regading the current SQL/SQLite configuration.
       
    98   	Example:
       
    99 		RSqlDatabase db;
       
   100 		//initialize the db object....
       
   101 		...
       
   102 		TSqlResourceProfiler profiler(db);
       
   103 		TBuf8<128> res;
       
   104 		profiler.Query(TSqlResourceProfiler::ESqlCounterConfig, res);
       
   105 	The format of the retrieved numbers is:   
       
   106 		"<Cache size in pages>;<Page size in bytes>;<Database encoding>;<Default soft heap limit>;<SQLite vacuum mode>";
       
   107 
       
   108  - Retrieving the number of the OS porting layer calls made by SQLite.
       
   109   	Example:
       
   110 		RSqlDatabase db;
       
   111 		//initialize the db object....
       
   112 		...
       
   113 		TSqlResourceProfiler profiler(db);
       
   114 		.....
       
   115 		profiler.Start(TSqlResourceProfiler::ESqlCounterOsCall);//Start the profiling
       
   116 		.....
       
   117 		TBuf8<300> res;
       
   118 		profiler.Query(TSqlResourceProfiler::ESqlCounterOsCall, res);
       
   119 		.....
       
   120 		profiler.Reset(TSqlResourceProfiler::ESqlCounterOsCall);//Reset the profiling 
       
   121 		....
       
   122 		profiler.Stop(TSqlResourceProfiler::ESqlCounterOsCall);
       
   123 	The format of the retrieved data is: 
       
   124 	"<file close cnt>;<file read cnt>;<file write cnt>;<file truncate cnt>;
       
   125 	 <file sync cnt>;<file size cnt>;<file lock cnt>;<file unlock cnt>;<file check reserved lock cnt>;
       
   126 	 <file i/o control cnt>;<file sector size cnt>;<file device characteristics cnt>;<vfs open cnt>;
       
   127 	 <vfs delete cnt>;<vfs access cnt>;<vfs full path name cnt>;<vfs randomness cnt>;
       
   128 	 <vfs sleep cnt>;<vfs current time cnt>;<vfs get last error cnt>;"
       
   129 	This service can be used only if the SQL code is compiled with the _SQLPROFILER macro.
       
   130    	
       
   131  - Retrieving the OS porting layer call times in microseconds per call type.
       
   132   	Example:
       
   133 		RSqlDatabase db;
       
   134 		//initialize the db object....
       
   135 		...
       
   136 		TSqlResourceProfiler profiler(db);
       
   137 		.....
       
   138 		profiler.Start(TSqlResourceProfiler::ESqlCounterOsCallTime);//Start the profiling
       
   139 		.....
       
   140 		TBuf8<300> res;
       
   141 		profiler.Query(TSqlResourceProfiler::ESqlCounterOsCallTime, res);
       
   142 		.....
       
   143 		profiler.Reset(TSqlResourceProfiler::ESqlCounterOsCallTime);//Reset the profiling 
       
   144 		....
       
   145 		profiler.Stop(TSqlResourceProfiler::ESqlCounterOsCallTime);
       
   146 	The format of the retrieved data is: 
       
   147 	"<file close time>;<file read time>;<file write time>;<file truncate time>;
       
   148 	 <file sync time>;<file size time>;<file lock time>;<file unlock time>;<file check reserved lock time>;
       
   149 	 <file i/o control time>;<file sector size time>;<file device characteristics time>;<vfs open time>;
       
   150 	 <vfs delete time>;<vfs access time>;<vfs full path name time>;<vfs randomness time>;
       
   151 	 <vfs sleep time>;<vfs current time time>;<vfs get last error time>;"
       
   152 	This service can be used only if the SQL code is compiled with the _SQLPROFILER macro.
       
   153 
       
   154  - Retrieving the OS porting layer call times in microseconds per call type plus adding a log entry 
       
   155    for each call. The returned information is the same as for the previous profiling type.
       
   156    But for each OS porting layer call an entry is added to the log file (epocwind.out).
       
   157    The format of the log entry is:
       
   158    	<'M'/'J'>,<'Call Id'>,<#Counter>,<Call Counter>,<File Offset>,<Bytes>,<Ticks>,<Bytes Total>,<Ticks Total>
       
   159    Note: ESqlCounterOsCallDetails and ESqlCounterOsCallTime profiles cannot be used together.
       
   160 
       
   161  - Retrieving the number of the IPC calls and IPC read/write operations.
       
   162   	Example:
       
   163 		RSqlDatabase db;
       
   164 		//initialize the db object....
       
   165 		...
       
   166 		TSqlResourceProfiler profiler(db);
       
   167 		.....
       
   168 		profiler.Start(TSqlResourceProfiler::ESqlCounterIpc);//Start the profiling
       
   169 		.....
       
   170 		TBuf8<300> res;
       
   171 		profiler.Query(TSqlResourceProfiler::ESqlCounterIpc, res);
       
   172 		.....
       
   173 		profiler.Reset(TSqlResourceProfiler::ESqlCounterIpc);//Reset the profiling 
       
   174 		....
       
   175 		profiler.Stop(TSqlResourceProfiler::ESqlCounterIpc);
       
   176 	The format of the retrieved data is: 
       
   177 	"<IPC call cnt>;<IPC write cnt>;<IPC read cnt>;<IPC write bytes>;<IPC read bytes>;
       
   178 	This service can be used only if the SQL code is compiled with the _SQLPROFILER macro.
       
   179    	
       
   180  - Tracing the executed SQL statements and IPC calls.
       
   181    The folowing tracing configurations can be used (pased as a configuration parameter in TSqlResourceProfiler::Start()):
       
   182    - "L0" - [default] tracing level 0. IPC traces disabled;
       
   183    - "L1" - tracing level 1. Only the most important IPC calls are traced:
       
   184             ESqlSrvDbExec8, ESqlSrvDbExec16, ESqlSrvDbScalarFullSelect16, ESqlSrvStmtExec,
       
   185             ESqlSrvStmtAsyncExec, ESqlSrvStmtBindExec, ESqlSrvStmtAsyncBindExec, ESqlSrvStmtNext,
       
   186             ESqlSrvStmtBindNext;
       
   187    - "L2" - tracing level 2. All IPC calls traced;
       
   188    - "S0" - [default] SQL statement tracing is off; 
       
   189    - "S1" - SQL statement tracing is on;
       
   190     Example:
       
   191         RSqlDatabase db;
       
   192         //initialize the db object....
       
   193         ...
       
   194         TSqlResourceProfiler profiler(db);
       
   195         .....
       
   196         _LIT8(KConfig, "<config string>");
       
   197         profiler.Start(TSqlResourceProfiler::ESqlCounterTrace, &KConfig);//Start the profiling
       
   198         .....
       
   199         profiler.Stop(TSqlResourceProfiler::ESqlCounterTrace);
       
   200     The format of the traces is:
       
   201     - SQL statement trace:
       
   202       <DbHandle>¬<TimeFromStart>¬SQL¬Prepare/Exec¬<SQL statemment>
       
   203     - "Database create" trace:
       
   204       <DbHandle>¬<TimeFromStart>¬CRE¬<database file path>
       
   205     - "Database open" trace:
       
   206       <DbHandle>¬<TimeFromStart>¬OPN¬<database file path>
       
   207     - "Database close" trace:
       
   208       <DbHandle>¬<TimeFromStart>¬CSE
       
   209     - "IPC call error" trace:
       
   210       <DbHandle>¬<TimeFromStart>¬ERR¬<IPC counter>¬<IPC call name>¬err=<error code>
       
   211     - "IPC call level 1 or level 2" trace:
       
   212       <DbHandle>¬<TimeFromStart>¬IPC¬<IPC counter>¬<IPC call name>¬<TotalExecTime>¬<ExecTime>¬<ThisCallIpcCount>¬..¬rc=<ret code>
       
   213     This service can be used only if the SQL code is compiled with the _SQLPROFILER macro.
       
   214 @endcode
       
   215 
       
   216 @internalComponent
       
   217 */
       
   218 class TSqlResourceProfiler
       
   219 	{
       
   220 public:
       
   221 	enum TSqlCounter
       
   222 		{
       
   223 		ESqlCounterFileIO,
       
   224 		ESqlCounterOsCall,
       
   225 		ESqlCounterOsCallTime,
       
   226 		ESqlCounterOsCallDetails,
       
   227 		ESqlCounterIpc,
       
   228 		ESqlCounterMemory,
       
   229 		ESqlCounterMaxAlloc,
       
   230 		ESqlCounterConfig,
       
   231 		ESqlCounterTrace
       
   232 		};
       
   233 	IMPORT_C TSqlResourceProfiler(RSqlDatabase& aDatabase);
       
   234 	IMPORT_C TInt Start(TSqlCounter aCounterType, const TDesC8* aParam = NULL);
       
   235 	IMPORT_C TInt Stop(TSqlCounter aCounterType);
       
   236 	IMPORT_C TInt Reset(TSqlCounter aCounterType);
       
   237 	IMPORT_C TInt Query(TSqlCounter aCounterType, TDes8& aResult);
       
   238 	
       
   239 private:	
       
   240 	RSqlDatabase iDatabase;
       
   241 	
       
   242 	};
       
   243 
       
   244 #endif //__SQLRESOURCEPROFILER_H__