Skip to content

Commit

Permalink
Merge branch 'plugin-fw-performance-improvements'
Browse files Browse the repository at this point in the history
  • Loading branch information
saschazelzer committed Apr 21, 2013
2 parents bedf171 + 702fbc6 commit 6fef28f
Show file tree
Hide file tree
Showing 48 changed files with 1,478 additions and 465 deletions.
1 change: 1 addition & 0 deletions Libs/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ set(KIT_SRCS
ctkErrorLogStreamMessageHandler.h
ctkException.cpp
ctkException.h
ctkHighPrecisionTimer.h
ctkLogger.cpp
ctkLogger.h
ctkHistogram.cpp
Expand Down
155 changes: 155 additions & 0 deletions Libs/Core/ctkHighPrecisionTimer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*=============================================================================
Library: CTK
Copyright (c) German Cancer Research Center,
Division of Medical and Biological Informatics
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=============================================================================*/

#ifndef CTKHIGHPRECISIONTIMER_H
#define CTKHIGHPRECISIONTIMER_H


#include <qglobal.h>

#ifdef Q_OS_UNIX
#include <time.h>
#include <unistd.h>
#elif defined(Q_OS_WIN)
#include <windows.h>
#else
#include <QTime>
#endif

#include "ctkException.h"

/**
* \ingroup Core
*
*
* @brief A fast and high precision timer.
*
* This class provides a fast and high precision timer depending on
* platform specific API. It can be used as a QTime replacement for
* runtime measurements with a minimal performance overhead.
*/
class ctkHighPrecisionTimer {

public:

inline ctkHighPrecisionTimer();

inline void start();

inline qint64 elapsedMilli();

inline qint64 elapsedMicro();

private:

#ifdef _POSIX_MONOTONIC_CLOCK
timespec startTime;
#elif defined(Q_OS_WIN)
LARGE_INTEGER timerFrequency;
LARGE_INTEGER startTime;
#else
QTime startTime;
#endif
};

#ifdef _POSIX_MONOTONIC_CLOCK

inline ctkHighPrecisionTimer::ctkHighPrecisionTimer()
{
startTime.tv_nsec = 0;
startTime.tv_sec = 0;
}

inline void ctkHighPrecisionTimer::start()
{
clock_gettime(CLOCK_MONOTONIC, &startTime);
}

inline qint64 ctkHighPrecisionTimer::elapsedMilli()
{
timespec current;
clock_gettime(CLOCK_MONOTONIC, &current);
return (static_cast<qint64>(current.tv_sec)*1000 + current.tv_nsec/1000/1000) -
(static_cast<qint64>(startTime.tv_sec)*1000 + startTime.tv_nsec/1000/1000);
}

inline qint64 ctkHighPrecisionTimer::elapsedMicro()
{
timespec current;
clock_gettime(CLOCK_MONOTONIC, &current);
return (static_cast<qint64>(current.tv_sec)*1000*1000 + current.tv_nsec/1000) -
(static_cast<qint64>(startTime.tv_sec)*1000*1000 + startTime.tv_nsec/1000);
}

#elif defined(Q_OS_WIN)

inline ctkHighPrecisionTimer::ctkHighPrecisionTimer()
{
if (!QueryPerformanceFrequency(&timerFrequency))
throw ctkRuntimeException("QueryPerformanceFrequency() failed");
}

inline void ctkHighPrecisionTimer::start()
{
//DWORD_PTR oldmask = SetThreadAffinityMask(GetCurrentThread(), 0);
QueryPerformanceCounter(&startTime);
//SetThreadAffinityMask(GetCurrentThread(), oldmask);
}

inline qint64 ctkHighPrecisionTimer::elapsedMilli()
{
LARGE_INTEGER current;
QueryPerformanceCounter(&current);
return (current.QuadPart - startTime.QuadPart) / (timerFrequency.QuadPart / 1000);
}

inline qint64 ctkHighPrecisionTimer::elapsedMicro()
{
LARGE_INTEGER current;
QueryPerformanceCounter(&current);
return (current.QuadPart - startTime.QuadPart) / (timerFrequency.QuadPart / (1000*1000));
}

#else

inline ctkHighPrecisionTimer::ctkHighPrecisionTimer()
: startTime(QTime::currentTime())
{
}

inline void ctkHighPrecisionTimer::start()
{
startTime = QTime::currentTime();
}

inline qint64 ctkHighPrecisionTimer::elapsedMilli()
{
return startTime.elapsed();
}

inline qint64 ctkHighPrecisionTimer::elapsedMicro()
{
return startTime.elapsed() * 1000;
}

#endif

#endif // CTKHIGHPRECISIONTIMER_H
5 changes: 3 additions & 2 deletions Libs/PluginFramework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ set(KIT_export_directive "CTK_PLUGINFW_EXPORT")

# Source files
set(KIT_SRCS
ctkCaseInsensitiveString.cpp
ctkDictionary.cpp
ctkDictionary.h
ctkLDAPExpr.cpp
ctkLDAPExpr_p.h
ctkLDAPSearchFilter.cpp
Expand Down Expand Up @@ -62,6 +61,8 @@ set(KIT_SRCS
ctkServiceEvent.cpp
ctkServiceException.cpp
ctkServiceFactory.h
ctkServiceProperties_p.h
ctkServiceProperties.cpp
ctkServiceReference.cpp
ctkServiceReference_p.cpp
ctkServiceRegistration.cpp
Expand Down
3 changes: 3 additions & 0 deletions Libs/PluginFramework/Testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ set(metatypetest_plugins
add_subdirectory(org.commontk.pluginfwtest)
add_subdirectory(FrameworkTestPlugins)

add_subdirectory(org.commontk.pluginfwtest.perf)
add_subdirectory(org.commontk.eventadmintest.perf)

add_subdirectory(org.commontk.configadmintest)
add_subdirectory(org.commontk.eventadmintest)

Expand Down
140 changes: 0 additions & 140 deletions Libs/PluginFramework/Testing/Cpp/ctkPluginFrameworkTestMain.cpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ class ctkPluginFrameworkTestRunnerPrivate
while(dirIter.hasNext())
{
dirIter.next();
if (dirIter.fileName().contains(name))
QString fileName = dirIter.fileName().mid(3); // strip the "lib" prefix
fileName.truncate(fileName.lastIndexOf('.')); // remove the suffix
if (fileName == name)
{
try
{
Expand Down Expand Up @@ -253,6 +255,7 @@ void ctkPluginFrameworkTestRunner::init(const ctkProperties& fwProps)
foreach(ctkPluginFrameworkTestRunnerPrivate::InstallCandPair candidate,
d->installCandidates)
{
qDebug() << "Installing" << candidate.first << "," << candidate.second;
d->installPlugin(candidate.first, candidate.second);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
project(org_commontk_eventadmintest_perf)

set(PLUGIN_export_directive "org_commontk_eventadmintest_perf_EXPORT")

set(PLUGIN_SRCS
ctkEventAdminTestPerfActivator_p.h
ctkEventAdminTestPerfActivator.cpp
ctkEventAdminPerfTestSuite_p.h
ctkEventAdminPerfTestSuite.cpp
)

set(PLUGIN_MOC_SRCS
ctkEventAdminTestPerfActivator_p.h
ctkEventAdminPerfTestSuite_p.h
)

set(PLUGIN_UI_FORMS

)

set(PLUGIN_resources

)

ctkFunctionGetTargetLibraries(PLUGIN_target_libraries)

if(UNIX)
list(APPEND PLUGIN_target_libraries rt)
endif()

ctkMacroBuildPlugin(
NAME ${PROJECT_NAME}
EXPORT_DIRECTIVE ${PLUGIN_export_directive}
SRCS ${PLUGIN_SRCS}
MOC_SRCS ${PLUGIN_MOC_SRCS}
UI_FORMS ${PLUGIN_UI_FORMS}
RESOURCES ${PLUGIN_resources}
TARGET_LIBRARIES ${PLUGIN_target_libraries}
TEST_PLUGIN
)

set(eventadmin_perftest ${PROJECT_NAME} CACHE INTERNAL "Target name for the plugin containing performance tests for EventAdmin implementations")

0 comments on commit 6fef28f

Please sign in to comment.