summaryrefslogtreecommitdiffstats
path: root/WebKit/android/TimeCounter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebKit/android/TimeCounter.cpp')
-rw-r--r--WebKit/android/TimeCounter.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/WebKit/android/TimeCounter.cpp b/WebKit/android/TimeCounter.cpp
index 7abc113..da09b07 100644
--- a/WebKit/android/TimeCounter.cpp
+++ b/WebKit/android/TimeCounter.cpp
@@ -13,7 +13,7 @@
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
@@ -34,6 +34,11 @@
#include "Node.h"
#include "SystemTime.h"
#include "StyleBase.h"
+#include <utils/Log.h>
+#include <wtf/CurrentTime.h>
+
+#include <sys/time.h>
+#include <time.h>
#if USE(JSC)
#include "JSDOMWindow.h"
@@ -41,14 +46,28 @@
#include <runtime/JSLock.h>
#endif
-#include <utils/Log.h>
-
using namespace WebCore;
using namespace WTF;
using namespace JSC;
namespace android {
+uint32_t getThreadMsec()
+{
+#if defined(HAVE_POSIX_CLOCKS)
+ struct timespec tm;
+
+ clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tm);
+ return tm.tv_sec * 1000LL + tm.tv_nsec / 1000000;
+#else
+ struct timeval now;
+ struct timezone zone;
+
+ gettimeofday(&now, &zone);
+ return now.tv_sec * 1000LL + now.tv_usec / 1000;
+#endif
+}
+
#ifdef ANDROID_INSTRUMENT
static double sStartTotalTime;
@@ -94,7 +113,7 @@ void TimeCounter::record(enum Type type, const char* functionName)
void TimeCounter::recordNoCounter(enum Type type, const char* functionName)
{
- uint32_t time = sEndWebCoreThreadTime = get_thread_msec();
+ uint32_t time = sEndWebCoreThreadTime = getThreadMsec();
uint32_t elapsed = time - sStartTime[type];
sTotalTimeUsed[type] += elapsed;
if (elapsed > 1000)
@@ -105,7 +124,7 @@ void TimeCounter::report(const KURL& url, int live, int dead, size_t arenaSize)
{
String urlString = url;
int totalTime = static_cast<int>((currentTime() - sStartTotalTime) * 1000);
- int threadTime = get_thread_msec() - sStartThreadTime;
+ int threadTime = getThreadMsec() - sStartThreadTime;
LOGD("*-* Total load time: %d ms, thread time: %d ms for %s\n",
totalTime, threadTime, urlString.utf8().data());
for (Type type = (Type) 0; type < TotalTimeCounterCount; type
@@ -132,7 +151,7 @@ void TimeCounter::report(const KURL& url, int live, int dead, size_t arenaSize)
void TimeCounter::reportNow()
{
double current = currentTime();
- uint32_t currentThread = get_thread_msec();
+ uint32_t currentThread = getThreadMsec();
int elapsedTime = static_cast<int>((current - sLastTotalTime) * 1000);
int elapsedThreadTime = currentThread - sLastThreadTime;
LOGD("*-* Elapsed time: %d ms, ui thread time: %d ms, webcore thread time:"
@@ -162,12 +181,12 @@ void TimeCounter::reset() {
bzero(sCounter, sizeof(sCounter));
LOGD("*-* Start browser instrument\n");
sStartTotalTime = currentTime();
- sStartThreadTime = get_thread_msec();
+ sStartThreadTime = getThreadMsec();
}
void TimeCounter::start(enum Type type)
{
- uint32_t time = get_thread_msec();
+ uint32_t time = getThreadMsec();
if (sRecordWebCoreTime) {
sStartWebCoreThreadTime = time;
sRecordWebCoreTime = false;
@@ -175,6 +194,6 @@ void TimeCounter::start(enum Type type)
sStartTime[type] = time;
}
-#endif
+#endif // ANDROID_INSTRUMENT
}