1818import java .util .LinkedHashMap ;
1919import java .util .List ;
2020import java .util .Map ;
21+ import java .util .concurrent .TimeUnit ;
2122import net .rptools .maptool .client .AppState ;
2223import net .rptools .maptool .client .MapTool ;
2324
@@ -66,6 +67,7 @@ public static CodeTimer get() {
6667 private final Map <String , Timer > timeMap = new LinkedHashMap <>();
6768 private final String name ;
6869 private long threshold = 1 ;
70+ private TimeUnit reportingUnit = TimeUnit .MILLISECONDS ;
6971 private boolean enabled ;
7072
7173 private CodeTimer (String n ) {
@@ -78,7 +80,15 @@ public boolean isEnabled() {
7880 }
7981
8082 public void setThreshold (long threshold ) {
81- this .threshold = threshold ;
83+ this .threshold = TimeUnit .NANOSECONDS .convert (threshold , TimeUnit .MILLISECONDS );
84+ }
85+
86+ public void setThreshold (long threshold , TimeUnit timeUnit ) {
87+ this .threshold = TimeUnit .NANOSECONDS .convert (threshold , timeUnit );
88+ }
89+
90+ public void setReportingUnit (TimeUnit reportingUnit ) {
91+ this .reportingUnit = reportingUnit ;
8292 }
8393
8494 public void setEnabled (boolean enabled ) {
@@ -144,11 +154,18 @@ public String toString() {
144154 ++i ;
145155
146156 var id = entry .getKey ();
147- long elapsed = entry .getValue ().getElapsed () / 1_000_000 ;
157+ long elapsed = entry .getValue ().getElapsed ();
148158 if (elapsed < threshold ) {
149159 continue ;
150160 }
151- builder .append (String .format (" %3d. %6d ms %s\n " , i , elapsed , id ));
161+
162+ builder .append (
163+ String .format (
164+ " %3d. %6d %s %s\n " ,
165+ i ,
166+ reportingUnit .convert (elapsed , TimeUnit .NANOSECONDS ),
167+ StringUtil .formatTimeUnit (reportingUnit ),
168+ id ));
152169 }
153170
154171 if (!counterMap .isEmpty ()) {
0 commit comments