aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CMMCPConnection.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-06-27 14:27:10 +0000
committerrowanbeentje <rowan@beent.je>2009-06-27 14:27:10 +0000
commitcd7bc33e901ca84efa53dd5a26c837b5918a3b10 (patch)
tree9ea82f1f36ac3ecf96a3f34149266ca5bf0f842f /Source/CMMCPConnection.m
parentdd93ba60cc062ce4a733338ff993acf4db7cc537 (diff)
downloadsequelpro-cd7bc33e901ca84efa53dd5a26c837b5918a3b10.tar.gz
sequelpro-cd7bc33e901ca84efa53dd5a26c837b5918a3b10.tar.bz2
sequelpro-cd7bc33e901ca84efa53dd5a26c837b5918a3b10.zip
Improve custom query timing and display:
- Amend timing using clock() to timing based on mach_absolute_time() (see revision comment on Google code) - Ensure the time returned is for the requested query and not subsequent helper queries - Use NSNumberFormatter to return a localised "< 0.1 ms" rather than the hardcoded Euro-style "< 0,1 ms"
Diffstat (limited to 'Source/CMMCPConnection.m')
-rw-r--r--Source/CMMCPConnection.m12
1 files changed, 8 insertions, 4 deletions
diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m
index afba40a9..b9bffd9b 100644
--- a/Source/CMMCPConnection.m
+++ b/Source/CMMCPConnection.m
@@ -27,6 +27,7 @@
#import "SPStringAdditions.h"
#include <unistd.h>
#include <setjmp.h>
+#include <mach/mach_time.h>
static jmp_buf pingTimeoutJumpLocation;
static void forcePingTimeout(int signalNumber);
@@ -742,7 +743,8 @@ static void forcePingTimeout(int signalNumber);
- (CMMCPResult *)queryString:(NSString *) query usingEncoding:(NSStringEncoding) encoding
{
CMMCPResult *theResult = nil;
- int queryStartTime;
+ uint64_t queryStartTime, queryExecutionTime_t;
+ Nanoseconds queryExecutionTime;
const char *theCQuery;
unsigned long theCQueryLength;
int queryResultCode;
@@ -825,9 +827,10 @@ static void forcePingTimeout(int signalNumber);
// Run (or re-run) the query, timing the execution time of the query - note
// that this time will include network lag.
- queryStartTime = clock();
+ queryStartTime = mach_absolute_time();
queryResultCode = mysql_real_query(mConnection, theCQuery, theCQueryLength);
- lastQueryExecutionTime = (clock() - queryStartTime);
+ queryExecutionTime_t = mach_absolute_time() - queryStartTime;
+ queryExecutionTime = AbsoluteToNanoseconds( *(AbsoluteTime *) &(queryExecutionTime_t) );
// On success, capture the results
if (0 == queryResultCode) {
@@ -876,6 +879,7 @@ static void forcePingTimeout(int signalNumber);
[self setLastErrorMessage:queryErrorMessage?queryErrorMessage:@""];
if (queryErrorMessage) [queryErrorMessage release];
lastQueryAffectedRows = queryAffectedRows;
+ lastQueryExecutionTime = ((double) UnsignedWideToUInt64( queryExecutionTime )) * 1e-9;
// If an error occurred, inform the delegate
if (queryResultCode & delegateResponseToWillQueryString)
@@ -892,7 +896,7 @@ static void forcePingTimeout(int signalNumber);
* Return the time taken to execute the last query. This should be close to the time it took
* the server to run the query, but will include network lag and some client library overhead.
*/
-- (float) lastQueryExecutionTime
+- (double) lastQueryExecutionTime
{
return lastQueryExecutionTime;
}