From 7bfa856f0673b81d4d0dafd6e02e07f10f07a023 Mon Sep 17 00:00:00 2001 From: Martin Wolf Date: Wed, 7 Apr 2010 13:33:26 +0300 Subject: dbus-qeventloop update --- resourceqt-client/client.h | 61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'resourceqt-client/client.h') 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 #include +#include #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); -- cgit v1.2.3