summaryrefslogtreecommitdiff
path: root/resourceqt-client
diff options
context:
space:
mode:
Diffstat (limited to 'resourceqt-client')
-rw-r--r--resourceqt-client/client.cpp26
-rw-r--r--resourceqt-client/client.h61
2 files changed, 87 insertions, 0 deletions
diff --git a/resourceqt-client/client.cpp b/resourceqt-client/client.cpp
index 078e6e4..e0adbd0 100644
--- a/resourceqt-client/client.cpp
+++ b/resourceqt-client/client.cpp
@@ -297,6 +297,10 @@ void Client::showResources(const QList<Resource*> resList)
void Client::resourceAcquiredHandler(const QList<ResourceType>& /*grantedResList*/)
{
+ if( timeStat.markEnd() ) {
+ timeStat.report("\nOperation took %.2f ms\n");
+ }
+
QList<Resource*> list = resourceSet->resources();
if (!list.count()) {
printf("\nGranted resource set is empty. Possible bug?\n");
@@ -311,18 +315,30 @@ void Client::resourceAcquiredHandler(const QList<ResourceType>& /*grantedResList
void Client::resourceDeniedHandler()
{
+ if( timeStat.markEnd() ) {
+ timeStat.report("\nOperation took %.2f ms\n");
+ }
+
printf("\nManager denies access to resources!\n");
showPrompt();
}
void Client::resourceLostHandler()
{
+ if( timeStat.markEnd() ) {
+ timeStat.report("\nOperation took %.2f ms\n");
+ }
+
printf("\nLost resources from manager!\n");
showPrompt();
}
void Client::resourceReleasedHandler()
{
+ if( timeStat.markEnd() ) {
+ timeStat.report("\nOperation took %.2f ms\n");
+ }
+
printf("\nAll resources released\n");
showPrompt();
}
@@ -376,12 +392,22 @@ void Client::timerEvent(QTimerEvent*)
}
}
else if (params[0] == "acquire") {
+ timeStat.markStart();
if (!resourceSet || !resourceSet->acquire()) {
+ if( timeStat.markEnd() ) {
+ timeStat.report("Operation took %.2f ms\n");
+ }
+
printf("Acquire failed!\n");
}
}
else if (params[0] == "release") {
+ timeStat.markStart();
if (!resourceSet || !resourceSet->release()) {
+ if( timeStat.markEnd() ) {
+ timeStat.report("Operation took %.2f ms\n");
+ }
+
printf("Release failed!\n");
}
}
diff --git a/resourceqt-client/client.h b/resourceqt-client/client.h
index ed32538..c61a74c 100644
--- a/resourceqt-client/client.h
+++ b/resourceqt-client/client.h
@@ -5,6 +5,7 @@
#include <QtCore/QTextStream>
#include <policy/resource-set.h>
+#include <sys/resource.h>
#define RES_AUDIO_PLAYBACK (1<<0)
#define RES_VIDEO_PLAYBACK (1<<1)
@@ -19,6 +20,64 @@
#define RES_SNAP_BUTTON (1<<10)
#define RES_LENS_COVER (1<<11)
+class TimeStat
+{
+public:
+ double totalTime;
+
+ TimeStat()
+ {
+ running = false;
+ totalTime = 0;
+ };
+
+ inline void markStart()
+ {
+ running = true;
+ getrusage(RUSAGE_SELF, &start);
+ }
+
+ inline bool markEnd()
+ {
+ getrusage(RUSAGE_SELF, &end);
+
+ if( !running )
+ return false;
+
+ running = false;
+ timevalSub(&end.ru_utime, &start.ru_utime, &end.ru_utime);
+ timevalSub(&end.ru_stime, &start.ru_stime, &end.ru_stime);
+
+ double sys = end.ru_stime.tv_sec * 1000.0 + end.ru_stime.tv_usec / 1000.0;
+ double usr = end.ru_utime.tv_sec * 1000.0 + end.ru_utime.tv_usec / 1000.0;
+ totalTime = sys + usr;
+
+ return true;
+ }
+
+ void report(const char* format)
+ {
+ printf(format, totalTime);
+ }
+
+private:
+ bool running;
+ struct rusage start;
+ struct rusage end;
+
+ void timevalSub(struct timeval *a, struct timeval *b, struct timeval *diff)
+ {
+ diff->tv_sec = a->tv_sec - b->tv_sec;
+ if( a->tv_usec < b->tv_usec )
+ {
+ diff->tv_sec--;
+ diff->tv_usec = 1000000 - b->tv_usec + a->tv_usec;
+ }
+ else
+ diff->tv_usec = a->tv_usec - b->tv_usec;
+ }
+};
+
class Client : public QObject
{
Q_OBJECT
@@ -47,6 +106,8 @@ private:
uint32_t resourcesOptional;
QString applicationClass;
+ TimeStat timeStat;
+
ResourcePolicy::ResourceSet* resourceSet;
ResourcePolicy::Resource* allocateResource(ResourcePolicy::ResourceType resource, bool optional);