@@ -143,7 +143,8 @@ private int getCollectConfigHash() {
143143 return (ConfigAccess .isCollectFps () ? 1 : 0 ) |
144144 (ConfigAccess .isCollectTps () ? 2 : 0 ) |
145145 (ConfigAccess .isCollectMspt () ? 4 : 0 ) |
146- (ConfigAccess .isCollectHeap () ? 8 : 0 );
146+ (ConfigAccess .isCollectHeap () ? 8 : 0 ) |
147+ (ConfigAccess .isCollectCpu () ? 16 : 0 );
147148 }
148149
149150 private String [] buildCsvHeaders () {
@@ -152,6 +153,7 @@ private String[] buildCsvHeaders() {
152153 if (ConfigAccess .isCollectTps ()) sb .append ("tps," );
153154 if (ConfigAccess .isCollectMspt ()) sb .append ("mspt," );
154155 if (ConfigAccess .isCollectHeap ()) sb .append ("heap_used,heap_max," );
156+ if (ConfigAccess .isCollectCpu ()) sb .append ("cpu," );
155157 if (sb .length () > 0 ) sb .setLength (sb .length () - 1 );
156158 return sb .toString ().split ("," );
157159 }
@@ -233,7 +235,8 @@ private void outputMetrics() {
233235 ConfigAccess .isCollectFps (), metrics .fps (),
234236 ConfigAccess .isCollectTps (), metrics .tps (),
235237 ConfigAccess .isCollectMspt (), metrics .mspt (),
236- ConfigAccess .isCollectHeap (), metrics .heapUsed (), metrics .heapMax ());
238+ ConfigAccess .isCollectHeap (), metrics .heapUsed (), metrics .heapMax (),
239+ ConfigAccess .isCollectCpu (), metrics .cpuUsage ());
237240 httpService .send (json );
238241 }
239242 }
@@ -264,6 +267,11 @@ private String buildChatMessage(PerformanceMetrics metrics) {
264267 .append (" / " )
265268 .append (TranslationService .colorValue (PerformanceMetrics .formatMemoryMB (metrics .heapMax ())));
266269 }
270+ if (ConfigAccess .isCollectCpu ()) {
271+ if (!first ) sb .append (" | " );
272+ sb .append (TranslationService .colorLabel ("CPU: " ))
273+ .append (TranslationService .colorValue (String .format ("%.1f%%" , metrics .cpuUsage ())));
274+ }
267275 return sb .toString ();
268276 }
269277
@@ -273,6 +281,7 @@ private Object[] buildCsvRowValues(PerformanceMetrics metrics) {
273281 if (ConfigAccess .isCollectTps ()) count ++;
274282 if (ConfigAccess .isCollectMspt ()) count ++;
275283 if (ConfigAccess .isCollectHeap ()) count += 2 ;
284+ if (ConfigAccess .isCollectCpu ()) count ++;
276285
277286 Object [] values = new Object [count ];
278287 int i = 0 ;
@@ -283,6 +292,7 @@ private Object[] buildCsvRowValues(PerformanceMetrics metrics) {
283292 values [i ++] = metrics .heapUsed ();
284293 values [i ++] = metrics .heapMax ();
285294 }
295+ if (ConfigAccess .isCollectCpu ()) values [i ++] = metrics .cpuUsage ();
286296 return values ;
287297 }
288298
@@ -292,7 +302,8 @@ public PerformanceMetrics getMetrics() {
292302 double mspt = ConfigAccess .isCollectMspt () ? serverCollector .getMspt () : 0 ;
293303 double heapUsed = ConfigAccess .isCollectHeap () ? serverCollector .getHeapUsedMB () : 0 ;
294304 double heapMax = ConfigAccess .isCollectHeap () ? serverCollector .getHeapMaxMB () : 0 ;
295- return new PerformanceMetrics (fps , tps , mspt , heapUsed , heapMax );
305+ double cpuUsage = ConfigAccess .isCollectCpu () ? serverCollector .getCpuUsagePercent () : -1 ;
306+ return new PerformanceMetrics (fps , tps , mspt , heapUsed , heapMax , cpuUsage );
296307 }
297308
298309 public boolean isRunning () {
0 commit comments