< prev index next >

src/hotspot/share/utilities/ticks.cpp

Print this page
rev 49619 : JEP 328 : Flight Recorder open source preview
   1 /*
   2  * Copyright (c) 2013, 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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "runtime/os.hpp"
  27 #include "utilities/ticks.inline.hpp"
  28 
  29 #ifdef ASSERT
  30  const jlong Ticks::invalid_time_stamp = -2; // 0xFFFF FFFF`FFFF FFFE
  31 #endif
  32 
  33 void Ticks::stamp() {
  34   _stamp_ticks = os::elapsed_counter();










































  35 }
  36 
  37 const Ticks Ticks::now() {
  38   Ticks t;
  39   t.stamp();
  40   return t;
  41 }
  42 
  43 Tickspan::Tickspan(const Ticks& end, const Ticks& start) {
  44   assert(end.value() != Ticks::invalid_time_stamp, "end is unstamped!");
  45   assert(start.value() != Ticks::invalid_time_stamp, "start is unstamped!");




  46 
  47   assert(end >= start, "negative time!");





  48 
  49   _span_ticks = end.value() - start.value();


  50 }
  51 
  52 template <typename ReturnType>
  53 static ReturnType time_conversion(const Tickspan& span, TicksToTimeHelper::Unit unit) {
  54   assert(TicksToTimeHelper::SECONDS == unit ||
  55          TicksToTimeHelper::MILLISECONDS == unit, "invalid unit!");

  56 
  57   ReturnType frequency_per_unit = (ReturnType)os::elapsed_frequency() / (ReturnType)unit;




  58 
  59   return (ReturnType) ((ReturnType)span.value() / frequency_per_unit);


  60 }
  61 
  62 double TicksToTimeHelper::seconds(const Tickspan& span) {
  63   return time_conversion<double>(span, SECONDS);




  64 }
  65 
  66 jlong TicksToTimeHelper::milliseconds(const Tickspan& span) {
  67   return time_conversion<jlong>(span, MILLISECONDS);

  68 }
   1 /*
   2  * Copyright (c) 2013, 2018, 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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "runtime/os.hpp"
  27 #include "utilities/ticks.inline.hpp"
  28 
  29 #ifdef X86
  30 #include "rdtsc_x86.hpp"
  31 #endif
  32 
  33 #include OS_CPU_HEADER(os)
  34 
  35 ElapsedCounterStamped::ElapsedCounterStamped() : ElapsedCounter(os::elapsed_counter()) {}
  36 
  37 void ElapsedCounter::stamp() {
  38   _instant = now().value();
  39 }
  40 
  41 ElapsedCounter ElapsedCounter::now() {
  42   return ElapsedCounterStamped();
  43 }
  44 
  45 #ifdef X86
  46 FastElapsedCounterStamped::FastElapsedCounterStamped() : FastElapsedCounter(Rdtsc::elapsed_counter()) {}
  47 #else
  48 FastElapsedCounterStamped::FastElapsedCounterStamped() : FastElapsedCounter(os::elapsed_counter()) {}
  49 #endif
  50 
  51 void FastElapsedCounter::stamp() {
  52   _instant = now().value();
  53 }
  54 
  55 FastElapsedCounter FastElapsedCounter::now() {
  56   return FastElapsedCounterStamped();
  57 }
  58 
  59 TraceElapsedInterval::TraceElapsedInterval(const TraceElapsedCounter& end, const TraceElapsedCounter& start) :
  60   _elapsed_interval(end.value() - start.value())
  61 #ifdef X86
  62   , _ft_elapsed_interval(end.ft_value() - start.ft_value())
  63 #endif
  64   {}
  65 
  66 TraceElapsedInterval::TraceElapsedInterval(jlong interval) :
  67   _elapsed_interval(interval)
  68 #ifdef X86
  69   , _ft_elapsed_interval(interval)
  70 #endif
  71   {}
  72 
  73 TraceElapsedInterval& TraceElapsedInterval::operator+=(const TraceElapsedInterval& rhs) {
  74   _elapsed_interval += rhs._elapsed_interval;
  75   X86_ONLY(_ft_elapsed_interval += rhs._ft_elapsed_interval;)
  76   return *this;
  77 }
  78 
  79 TraceElapsedInterval& TraceElapsedInterval::operator-=(const TraceElapsedInterval& rhs) {
  80   _elapsed_interval -= rhs._elapsed_interval;
  81   X86_ONLY(_ft_elapsed_interval -= rhs._ft_elapsed_interval;)
  82   return *this;
  83 }
  84 
  85 jlong TraceElapsedInterval::ft_value() const {
  86 #ifdef X86
  87   return _ft_elapsed_interval.value();
  88 #else
  89   return _elapsed_interval.value();
  90 #endif
  91 }
  92 
  93 TraceElapsedCounter::TraceElapsedCounter(jlong stamp) :
  94   _elapsed(stamp)
  95 #ifdef X86
  96   , _ft_elapsed(stamp)
  97 #endif
  98   {}
  99 
 100 TraceElapsedCounter TraceElapsedCounter::now() {
 101   TraceElapsedCounterStamped dec;
 102   return dec;
 103 }
 104 
 105 TraceElapsedCounter& TraceElapsedCounter::operator+=(const TraceElapsedInterval& rhs) {
 106   _elapsed += rhs.value();
 107   X86_ONLY(_ft_elapsed += rhs.ft_value();)
 108   return *this;
 109 }
 110 
 111 TraceElapsedCounter& TraceElapsedCounter::operator-=(const TraceElapsedInterval& rhs) {
 112   _elapsed -= rhs.value();
 113   X86_ONLY(_ft_elapsed -= rhs.ft_value();)
 114   return *this;
 115 }
 116 
 117 void TraceElapsedCounter::stamp() {
 118   _elapsed.stamp();
 119   X86_ONLY(_ft_elapsed.stamp();)
 120 }
 121 
 122 jlong TraceElapsedCounter::ft_value() const {
 123 #ifdef X86
 124   return _ft_elapsed.value();
 125 #else
 126   return _elapsed.value();
 127 #endif
 128 }
 129 
 130 TraceElapsedCounterStamped::TraceElapsedCounterStamped() : TraceElapsedCounter() {
 131   _elapsed.stamp();
 132   X86_ONLY(_ft_elapsed.stamp());
 133 }
< prev index next >