diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/basetypes/MCOperationQueue.cc | 4 | ||||
-rw-r--r-- | src/core/perf/MCPerfEvent.cc | 40 | ||||
-rw-r--r-- | src/core/perf/MCPerfEvent.h | 29 |
3 files changed, 73 insertions, 0 deletions
diff --git a/src/core/basetypes/MCOperationQueue.cc b/src/core/basetypes/MCOperationQueue.cc index 9a740ef6..315bf9c9 100644 --- a/src/core/basetypes/MCOperationQueue.cc +++ b/src/core/basetypes/MCOperationQueue.cc @@ -10,6 +10,7 @@ #include "MCArray.h" #include "MCLog.h" #include "MCAutoreleasePool.h" +#include "MCPerfEvent.h" using namespace mailcore; @@ -72,6 +73,9 @@ void OperationQueue::runOperationsOnThread(OperationQueue * queue) void OperationQueue::runOperations() { MCLog("start thread"); + + TRACE_PERF; + mailsem_up(mStartSem); while (true) { diff --git a/src/core/perf/MCPerfEvent.cc b/src/core/perf/MCPerfEvent.cc new file mode 100644 index 00000000..c2119a40 --- /dev/null +++ b/src/core/perf/MCPerfEvent.cc @@ -0,0 +1,40 @@ +// +// MCPerfEvent.cpp +// mailcore2 +// +// Created by Yuk Lai Suen on 5/30/14. +// Copyright (c) 2014 MailCore. All rights reserved. +// + +#include <stdint.h> +#include <mach/mach.h> +#include <mach/mach_time.h> +#include "MCLog.h" +#include "MCPerfEvent.h" + +static struct mach_timebase_info sTimebaseInfo; + +using namespace mailcore; +MCPerfEvent::MCPerfEvent(const char *_functionName, bool start) +: isStarted(false) +, functionName(_functionName) +{ + if (start) { + if (sTimebaseInfo.denom == 0) { + mach_timebase_info(&sTimebaseInfo); + } + startTime = mach_absolute_time(); + isStarted = true; + } +} + +MCPerfEvent::~MCPerfEvent() +{ + if (isStarted) { + endTime = mach_absolute_time(); + isStarted = false; + } + + uint64_t timeElpasedInMs = ((endTime - startTime) / 1000000ull * sTimebaseInfo.numer / sTimebaseInfo.denom); + MCLog("================= %s: %llu (ms)", functionName, timeElpasedInMs); +} diff --git a/src/core/perf/MCPerfEvent.h b/src/core/perf/MCPerfEvent.h new file mode 100644 index 00000000..00db68a8 --- /dev/null +++ b/src/core/perf/MCPerfEvent.h @@ -0,0 +1,29 @@ +// +// MCPerfEvent.h +// mailcore2 +// +// Created by Yuk Lai Suen on 5/30/14. +// Copyright (c) 2014 MailCore. All rights reserved. +// + +#ifndef __mailcore2__File__ +#define __mailcore2__File__ +#include <stdint.h> + +#define TRACE_PERF MCPerfEvent event(__PRETTY_FUNCTION__) + +namespace mailcore { + class MCPerfEvent + { + public: + MCPerfEvent(const char *functionName, bool start = true); + ~MCPerfEvent(); + unsigned long long timeElapsedInMs; + private: + bool isStarted; + const char *functionName; + uint64_t startTime; + uint64_t endTime; + }; +} +#endif /* defined(__mailcore2__File__) */ |