|
14 | 14 | * (at your option) any later version. *
|
15 | 15 | * *
|
16 | 16 | ***************************************************************************/
|
| 17 | +#include <QtGlobal> |
| 18 | + |
17 | 19 | #include <cmath>
|
18 | 20 | #include <ctime>
|
19 | 21 | #include <iostream>
|
20 | 22 | #include <stdio.h>
|
| 23 | +#ifndef Q_OS_WIN |
21 | 24 | #include <sys/resource.h>
|
| 25 | +#endif |
22 | 26 | #include <time.h>
|
23 | 27 | #include <math.h>
|
24 | 28 |
|
|
35 | 39 | #include "qgsmaplayerregistry.h"
|
36 | 40 | #include "qgsproject.h"
|
37 | 41 |
|
| 42 | +#ifdef Q_OS_WIN |
| 43 | +// slightly adapted from http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/port/getrusage.c?rev=1.18;content-type=text%2Fplain |
| 44 | + |
| 45 | +#include <winsock2.h> |
| 46 | +#include <errno.h> |
| 47 | + |
| 48 | +#define RUSAGE_SELF 0 |
| 49 | + |
| 50 | +struct rusage |
| 51 | +{ |
| 52 | + struct timeval ru_utime; /* user time used */ |
| 53 | + struct timeval ru_stime; /* system time used */ |
| 54 | +}; |
| 55 | + |
| 56 | +/*------------------------------------------------------------------------- |
| 57 | + * |
| 58 | + * getrusage.c |
| 59 | + * get information about resource utilisation |
| 60 | + * |
| 61 | + * Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group |
| 62 | + * Portions Copyright (c) 1994, Regents of the University of California |
| 63 | + * |
| 64 | + * |
| 65 | + * IDENTIFICATION |
| 66 | + * $PostgreSQL: pgsql/src/port/getrusage.c,v 1.18 2010-01-02 16:58:13 momjian Exp $ |
| 67 | + * |
| 68 | + *------------------------------------------------------------------------- |
| 69 | + */ |
| 70 | + |
| 71 | + |
| 72 | +int getrusage( int who, struct rusage * rusage ) |
| 73 | +{ |
| 74 | + FILETIME starttime; |
| 75 | + FILETIME exittime; |
| 76 | + FILETIME kerneltime; |
| 77 | + FILETIME usertime; |
| 78 | + ULARGE_INTEGER li; |
| 79 | + |
| 80 | + if ( who != RUSAGE_SELF ) |
| 81 | + { |
| 82 | + /* Only RUSAGE_SELF is supported in this implementation for now */ |
| 83 | + errno = EINVAL; |
| 84 | + return -1; |
| 85 | + } |
| 86 | + |
| 87 | + if ( rusage == ( struct rusage * ) NULL ) |
| 88 | + { |
| 89 | + errno = EFAULT; |
| 90 | + return -1; |
| 91 | + } |
| 92 | + memset( rusage, 0, sizeof( struct rusage ) ); |
| 93 | + if ( GetProcessTimes( GetCurrentProcess(), |
| 94 | + &starttime, &exittime, &kerneltime, &usertime ) == 0 ) |
| 95 | + { |
| 96 | + // _dosmaperr(GetLastError()); |
| 97 | + return -1; |
| 98 | + } |
| 99 | + |
| 100 | + /* Convert FILETIMEs (0.1 us) to struct timeval */ |
| 101 | + memcpy( &li, &kerneltime, sizeof( FILETIME ) ); |
| 102 | + li.QuadPart /= 10L; /* Convert to microseconds */ |
| 103 | + rusage->ru_stime.tv_sec = li.QuadPart / 1000000L; |
| 104 | + rusage->ru_stime.tv_usec = li.QuadPart % 1000000L; |
| 105 | + |
| 106 | + memcpy( &li, &usertime, sizeof( FILETIME ) ); |
| 107 | + li.QuadPart /= 10L; /* Convert to microseconds */ |
| 108 | + rusage->ru_utime.tv_sec = li.QuadPart / 1000000L; |
| 109 | + rusage->ru_utime.tv_usec = li.QuadPart % 1000000L; |
| 110 | + |
| 111 | + return 0; |
| 112 | +} |
| 113 | +#endif |
| 114 | + |
38 | 115 | QgsBench::QgsBench( int theWidth, int theHeight, int theIterations )
|
39 | 116 | : QObject(), mWidth( theWidth ), mHeight( theHeight ), mIterations( theIterations ), mSetExtent( false )
|
40 | 117 | {
|
@@ -260,4 +337,3 @@ void QgsBench::elapsed()
|
260 | 337 | t[2] = t[0] + t[1];
|
261 | 338 | mTimes.append( t );
|
262 | 339 | }
|
263 |
| - |
|
0 commit comments