summaryrefslogtreecommitdiff
path: root/resourceqt-client/client.h
diff options
context:
space:
mode:
authorMartin Wolf <ext-martin.2.wolf@nokia.com>2010-04-07 13:33:26 +0300
committerMartin Wolf <ext-martin.2.wolf@nokia.com>2010-04-07 13:33:26 +0300
commit7bfa856f0673b81d4d0dafd6e02e07f10f07a023 (patch)
tree309ac66b5cbfe77df701fc9c7a0c7e5a68d147e7 /resourceqt-client/client.h
parenta19a377ae930d54beb98dbe1f6171c6d39ddea80 (diff)
dbus-qeventloop update
Diffstat (limited to 'resourceqt-client/client.h')
-rw-r--r--resourceqt-client/client.h61
1 files changed, 61 insertions, 0 deletions
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);