< prev index next >

src/share/vm/runtime/timer.cpp

Print this page
rev 8910 : full patch for jfr
   1 /*
   2  * Copyright (c) 1997, 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  *


  31 #endif
  32 #ifdef TARGET_OS_FAMILY_solaris
  33 # include "os_solaris.inline.hpp"
  34 #endif
  35 #ifdef TARGET_OS_FAMILY_windows
  36 # include "os_windows.inline.hpp"
  37 #endif
  38 #ifdef TARGET_OS_FAMILY_aix
  39 # include "os_aix.inline.hpp"
  40 #endif
  41 #ifdef TARGET_OS_FAMILY_bsd
  42 # include "os_bsd.inline.hpp"
  43 #endif
  44 
  45 double TimeHelper::counter_to_seconds(jlong counter) {
  46   double count = (double) counter;
  47   double freq  = (double) os::elapsed_frequency();
  48   return counter/freq;
  49 }
  50 






  51 void elapsedTimer::add(elapsedTimer t) {
  52   _counter += t._counter;
  53 }
  54 
  55 void elapsedTimer::start() {
  56   if (!_active) {
  57     _active = true;
  58     _start_counter = os::elapsed_counter();
  59   }
  60 }
  61 
  62 void elapsedTimer::stop() {
  63   if (_active) {
  64     _counter += os::elapsed_counter() - _start_counter;
  65     _active = false;
  66   }
  67 }
  68 
  69 double elapsedTimer::seconds() const {
  70  return TimeHelper::counter_to_seconds(_counter);


   1 /*
   2  * Copyright (c) 1997, 2019, 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  *


  31 #endif
  32 #ifdef TARGET_OS_FAMILY_solaris
  33 # include "os_solaris.inline.hpp"
  34 #endif
  35 #ifdef TARGET_OS_FAMILY_windows
  36 # include "os_windows.inline.hpp"
  37 #endif
  38 #ifdef TARGET_OS_FAMILY_aix
  39 # include "os_aix.inline.hpp"
  40 #endif
  41 #ifdef TARGET_OS_FAMILY_bsd
  42 # include "os_bsd.inline.hpp"
  43 #endif
  44 
  45 double TimeHelper::counter_to_seconds(jlong counter) {
  46   double count = (double) counter;
  47   double freq  = (double) os::elapsed_frequency();
  48   return counter/freq;
  49 }
  50 
  51 double TimeHelper::counter_to_milliseconds(jlong counter) {
  52   double count = (double) counter;
  53   double freq  = (double) os::elapsed_frequency() / (double) 1000;
  54   return counter/freq;
  55 }
  56 
  57 void elapsedTimer::add(elapsedTimer t) {
  58   _counter += t._counter;
  59 }
  60 
  61 void elapsedTimer::start() {
  62   if (!_active) {
  63     _active = true;
  64     _start_counter = os::elapsed_counter();
  65   }
  66 }
  67 
  68 void elapsedTimer::stop() {
  69   if (_active) {
  70     _counter += os::elapsed_counter() - _start_counter;
  71     _active = false;
  72   }
  73 }
  74 
  75 double elapsedTimer::seconds() const {
  76  return TimeHelper::counter_to_seconds(_counter);


< prev index next >