-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#9267] Add Clock with millisecond precision
- Loading branch information
Showing
6 changed files
with
94 additions
and
16 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/clock/Clock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.navercorp.pinpoint.common.profiler.clock; | ||
|
||
/** | ||
* millisecond precision clock | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
public interface Clock { | ||
|
||
long millis(); | ||
|
||
static Clock systemUTC() { | ||
return SystemClock.UTC; | ||
} | ||
|
||
static Clock fixed(long timestamp) { | ||
return new FixedClock(timestamp); | ||
} | ||
|
||
static Clock tick(long tick) { | ||
return new TickClock(Clock.systemUTC(), tick); | ||
} | ||
|
||
static Clock tick(Clock clock, long tick) { | ||
return new TickClock(clock, tick); | ||
} | ||
|
||
class SystemClock implements Clock { | ||
static final SystemClock UTC = new SystemClock(); | ||
|
||
@Override | ||
public long millis() { | ||
return System.currentTimeMillis(); | ||
} | ||
} | ||
|
||
class FixedClock implements Clock { | ||
private final long timestamp; | ||
|
||
public FixedClock(long timestamp) { | ||
this.timestamp = timestamp; | ||
} | ||
|
||
@Override | ||
public long millis() { | ||
return timestamp; | ||
} | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
commons-profiler/src/main/java/com/navercorp/pinpoint/common/profiler/clock/TickClock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.navercorp.pinpoint.common.profiler.clock; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* @author Woonduk Kang(emeroad) | ||
*/ | ||
public class TickClock implements Clock { | ||
private final Clock baseClock; | ||
private final long tick; | ||
|
||
public TickClock(Clock baseClock, long tick) { | ||
this.baseClock = Objects.requireNonNull(baseClock, "baseClock"); | ||
if (tick < 0) { | ||
throw new IllegalArgumentException("negative tick"); | ||
} | ||
this.tick = tick; | ||
} | ||
|
||
public long millis() { | ||
long millis = baseClock.millis(); | ||
return tick(millis); | ||
} | ||
|
||
public long tick(long millis) { | ||
return millis - (millis % tick); | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
grpc/src/main/java/com/navercorp/pinpoint/grpc/server/flowcontrol/DefaultIdleTimeout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters