1 /*
2 * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
1305 bool os::vtime_enabled() { return false; }
1306
1307 double os::elapsedVTime() {
1308 struct rusage usage;
1309 int retval = getrusage(RUSAGE_THREAD, &usage);
1310 if (retval == 0) {
1311 return (double) (usage.ru_utime.tv_sec + usage.ru_stime.tv_sec) + (double) (usage.ru_utime.tv_usec + usage.ru_stime.tv_usec) / (1000 * 1000);
1312 } else {
1313 // better than nothing, but not much
1314 return elapsedTime();
1315 }
1316 }
1317
1318 jlong os::javaTimeMillis() {
1319 timeval time;
1320 int status = gettimeofday(&time, NULL);
1321 assert(status != -1, "linux error");
1322 return jlong(time.tv_sec) * 1000 + jlong(time.tv_usec / 1000);
1323 }
1324
1325 #ifndef CLOCK_MONOTONIC
1326 #define CLOCK_MONOTONIC (1)
1327 #endif
1328
1329 void os::Linux::clock_init() {
1330 // we do dlopen's in this particular order due to bug in linux
1331 // dynamical loader (see 6348968) leading to crash on exit
1332 void* handle = dlopen("librt.so.1", RTLD_LAZY);
1333 if (handle == NULL) {
1334 handle = dlopen("librt.so", RTLD_LAZY);
1335 }
1336
1337 if (handle) {
1338 int (*clock_getres_func)(clockid_t, struct timespec*) =
1339 (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_getres");
1340 int (*clock_gettime_func)(clockid_t, struct timespec*) =
1341 (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_gettime");
1342 if (clock_getres_func && clock_gettime_func) {
1343 // See if monotonic clock is supported by the kernel. Note that some
1344 // early implementations simply return kernel jiffies (updated every
|
1 /*
2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
1305 bool os::vtime_enabled() { return false; }
1306
1307 double os::elapsedVTime() {
1308 struct rusage usage;
1309 int retval = getrusage(RUSAGE_THREAD, &usage);
1310 if (retval == 0) {
1311 return (double) (usage.ru_utime.tv_sec + usage.ru_stime.tv_sec) + (double) (usage.ru_utime.tv_usec + usage.ru_stime.tv_usec) / (1000 * 1000);
1312 } else {
1313 // better than nothing, but not much
1314 return elapsedTime();
1315 }
1316 }
1317
1318 jlong os::javaTimeMillis() {
1319 timeval time;
1320 int status = gettimeofday(&time, NULL);
1321 assert(status != -1, "linux error");
1322 return jlong(time.tv_sec) * 1000 + jlong(time.tv_usec / 1000);
1323 }
1324
1325 void os::javaTimeSystemUTC(jlong &seconds, jlong &nanos) {
1326 timeval time;
1327 int status = gettimeofday(&time, NULL);
1328 assert(status != -1, "linux error");
1329 seconds = jlong(time.tv_sec);
1330 nanos = jlong(time.tv_usec) * 1000;
1331 }
1332
1333
1334 #ifndef CLOCK_MONOTONIC
1335 #define CLOCK_MONOTONIC (1)
1336 #endif
1337
1338 void os::Linux::clock_init() {
1339 // we do dlopen's in this particular order due to bug in linux
1340 // dynamical loader (see 6348968) leading to crash on exit
1341 void* handle = dlopen("librt.so.1", RTLD_LAZY);
1342 if (handle == NULL) {
1343 handle = dlopen("librt.so", RTLD_LAZY);
1344 }
1345
1346 if (handle) {
1347 int (*clock_getres_func)(clockid_t, struct timespec*) =
1348 (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_getres");
1349 int (*clock_gettime_func)(clockid_t, struct timespec*) =
1350 (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_gettime");
1351 if (clock_getres_func && clock_gettime_func) {
1352 // See if monotonic clock is supported by the kernel. Note that some
1353 // early implementations simply return kernel jiffies (updated every
|