From 0836295b52aaad1dce10a31a13cb544802d7de03 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Mon, 6 Mar 2023 22:16:58 +0100 Subject: Fix Clock for performance counter: Add currentTimeNanos() since module startup, retrievable via getMonotonicStartupTime(). (performance) Settings two long fields in getMonotonicTime() and creating Instant and using Duration for high-frequency counter is too expensive. currentTimeNanos() subtracts the startup time from the current monotonic time and returns the resulting duration in nanoseconds, which lasts for 292 years since module startup. This satisfies performance counter requirements. --- src/java/com/jogamp/common/util/PerfCounterCtrl.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/java/com/jogamp/common/util/PerfCounterCtrl.java') diff --git a/src/java/com/jogamp/common/util/PerfCounterCtrl.java b/src/java/com/jogamp/common/util/PerfCounterCtrl.java index 486c248..30290f8 100644 --- a/src/java/com/jogamp/common/util/PerfCounterCtrl.java +++ b/src/java/com/jogamp/common/util/PerfCounterCtrl.java @@ -26,9 +26,15 @@ package com.jogamp.common.util; import java.io.PrintStream; -import java.time.Duration; +import com.jogamp.common.os.Clock; -/** Simple performance counter controller. */ +/** + * Simple performance counter controller. + *

+ * Implementation is expected to utilize nanosecond counter since module start, + * e.g. {@link Clock#currentTimeNanos()}. + *

+ */ public interface PerfCounterCtrl { /** Enable or disable performance counter. */ void enable(final boolean enable); @@ -36,8 +42,8 @@ public interface PerfCounterCtrl { /** Clear performance counter. */ void clear(); - /** Return the total duration, covering all sub-counter. */ - Duration getTotalDuration(); + /** Return the total duration in nanoseconds, covering all sub-counter. */ + long getTotalDuration(); /** Print performance counter. */ void print(final PrintStream out); -- cgit v1.2.3