I've been finding it hard to get enough resolution out of our existing timers when measuring really tiny pictures.
BUG=skia:2378
R=bsalomon@google.com, mtklein@google.com, bungeman@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/
250243002
git-svn-id: http://skia.googlecode.com/svn/trunk@14362
2bbb7eff-a529-9590-31e7-
b0007b416f81
};
static void GetDateTime(DateTime*);
- static SkMSec GetMSecs();
+ static SkMSec GetMSecs() { return GetNSecs() / 1000000; }
+
+ static SkNSec GetNSecs();
};
#if defined(SK_DEBUG) && defined(SK_BUILD_FOR_WIN32)
*/
#define SkMSec_LE(a, b) ((int32_t)(a) - (int32_t)(b) <= 0)
+/** 64 bit value to hold nanosecond count
+*/
+typedef uint64_t SkNSec;
+
/** The generation IDs in Skia reserve 0 has an invalid marker.
*/
#define SK_InvalidGenID 0
#include <sys/time.h>
#include <time.h>
-void SkTime::GetDateTime(DateTime* dt)
-{
- if (dt)
- {
+void SkTime::GetDateTime(DateTime* dt) {
+ if (dt) {
time_t m_time;
time(&m_time);
struct tm* tstruct;
}
}
-SkMSec SkTime::GetMSecs()
-{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (SkMSec) (tv.tv_sec * 1000 + tv.tv_usec / 1000 ); // microseconds to milliseconds
+#ifdef __MACH__
+# include <mach/mach_time.h>
+
+namespace {
+
+struct ConversionFactor {
+ ConversionFactor() {
+ mach_timebase_info_data_t timebase;
+ mach_timebase_info(&timebase);
+ toNanos = (double) timebase.numer / timebase.denom;
+ }
+ double toNanos;
+};
+
+} // namespace
+
+SkNSec SkTime::GetNSecs() {
+ static ConversionFactor convert; // Since already know we're on Mac, this is threadsafe.
+ return mach_absolute_time() * convert.toNanos;
}
+
+#else // Linux, presumably all others too
+
+SkNSec SkTime::GetNSecs() {
+ struct timespec time;
+ clock_gettime(CLOCK_MONOTONIC, &time);
+ return (SkNSec)(time.tv_sec * 1000000000 + time.tv_nsec);
+}
+
+#endif
#include "SkTime.h"
-void SkTime::GetDateTime(DateTime* dt)
-{
+void SkTime::GetDateTime(DateTime* dt) {
if (dt)
{
SYSTEMTIME st;
}
}
-SkMSec SkTime::GetMSecs()
-{
+SkNSec SkTime::GetNSecs() {
FILETIME ft;
LARGE_INTEGER li;
GetSystemTimeAsFileTime(&ft);
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
__int64 t = li.QuadPart; /* In 100-nanosecond intervals */
- return (SkMSec)(t / 10000); /* In milliseconds */
+ return (SkMSec)(t * 100);
}
src.width() * sizeof(SkPMColor)));
canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLAGS_tile)));
- const SkMSec start = SkTime::GetMSecs();
+ const SkNSec start = SkTime::GetNSecs();
for (int i = 0; i < FLAGS_loops; i++) {
if (FLAGS_skr) {
SkRecordDraw(record, canvas.get());
}
}
- const SkMSec elapsed = SkTime::GetMSecs() - start;
- const double msPerLoop = elapsed / (double)FLAGS_loops;
- printf("%6.2f\t%s\n", msPerLoop, name);
+ const SkNSec elapsed = SkTime::GetNSecs() - start;
+ const double nsPerLoop = elapsed / (double)FLAGS_loops;
+ printf("%u\t%s\n", SkToUInt(nsPerLoop), name);
}
int tool_main(int argc, char** argv);
}
static void bench_record(SkPicture* src, const char* name, SkBBHFactory* bbhFactory) {
- const SkMSec start = SkTime::GetMSecs();
+ const SkNSec start = SkTime::GetNSecs();
const int width = src ? src->width() : FLAGS_nullSize;
const int height = src ? src->height() : FLAGS_nullSize;
}
}
- const SkMSec elapsed = SkTime::GetMSecs() - start;
- const double msPerLoop = elapsed / (double)FLAGS_loops;
- printf("%.2g\t%s\n", msPerLoop, name);
+ const SkNSec elapsed = SkTime::GetNSecs() - start;
+ const double nsPerLoop = elapsed / (double)FLAGS_loops;
+ printf("%u\t%s\n", SkToUInt(nsPerLoop), name);
}
int tool_main(int argc, char** argv);