wang-jiahua commented on code in PR #10514:
URL: https://github.com/apache/rocketmq/pull/10514#discussion_r3575624541
##########
remoting/src/main/java/org/apache/rocketmq/remoting/protocol/RemotingCommand.java:
##########
@@ -635,12 +658,25 @@ public void setSerializeTypeCurrentRPC(SerializeType
serializeTypeCurrentRPC) {
this.serializeTypeCurrentRPC = serializeTypeCurrentRPC;
}
- public Stopwatch getProcessTimer() {
- return processTimer;
+ public long processTimerElapsedMs() {
+ if (processTimerNanos == 0) {
+ return 0;
+ }
+ return (System.nanoTime() - processTimerNanos) / 1_000_000;
+ }
+
+ @Deprecated
+ public com.google.common.base.Stopwatch getProcessTimer() {
+ return com.google.common.base.Stopwatch.createStarted();
+ }
+
+ @Deprecated
+ public void setProcessTimer(com.google.common.base.Stopwatch processTimer)
{
+ this.processTimerNanos =
processTimer.elapsed(java.util.concurrent.TimeUnit.NANOSECONDS);
Review Comment:
Good catch, thanks. Fixed in the deprecated `setProcessTimer(Stopwatch)` by
reconstructing a `System.nanoTime()` start instead of storing the elapsed
duration:
```java
this.processTimerNanos = System.nanoTime() -
processTimer.elapsed(java.util.concurrent.TimeUnit.NANOSECONDS);
```
Now `processTimerElapsedMs()` (which computes `System.nanoTime() -
processTimerNanos`) keeps returning the real request duration for callers still
using the deprecated setter, instead of a near-JVM-uptime value. Also updated
the Javadoc and added
`RemotingCommandTest#testSetProcessTimerStopwatchKeepsElapsed` to lock in the
behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]