@@ -32,11 +32,40 @@ public static void main(String[] args) throws Exception {
3232
3333 CoverageSummary coverage = loadCoverage (arguments .coverageSummary , arguments .coverageHtmlUrl );
3434
35- SummaryAndComment output = buildSummaryAndComment (data , title , marker , successMessage , coverage , arguments .vmTime , arguments .compilationTime );
35+ Map <String , String > extraStats = new LinkedHashMap <>();
36+ if (arguments .extraStats != null ) {
37+ for (Path p : arguments .extraStats ) {
38+ if (Files .isRegularFile (p )) {
39+ parseStatsFile (p , extraStats );
40+ }
41+ }
42+ }
43+
44+ SummaryAndComment output = buildSummaryAndComment (data , title , marker , successMessage , coverage , arguments .vmTime , arguments .compilationTime , extraStats );
3645 writeLines (arguments .summaryOut , output .summaryLines );
3746 writeLines (arguments .commentOut , output .commentLines );
3847 }
3948
49+ private static void parseStatsFile (Path p , Map <String , String > extraStats ) {
50+ try {
51+ List <String > lines = Files .readAllLines (p , StandardCharsets .UTF_8 );
52+ for (String line : lines ) {
53+ line = line .trim ();
54+ if (line .isEmpty () || line .startsWith ("-" )) {
55+ continue ;
56+ }
57+ int colon = line .indexOf (':' );
58+ if (colon > 0 ) {
59+ String key = line .substring (0 , colon ).trim ();
60+ String val = line .substring (colon + 1 ).trim ();
61+ extraStats .put (key , val );
62+ }
63+ }
64+ } catch (IOException e ) {
65+ System .err .println ("Failed to read stats file " + p + ": " + e .getMessage ());
66+ }
67+ }
68+
4069 private static void writeLines (Path path , List <String > lines ) throws IOException {
4170 StringBuilder sb = new StringBuilder ();
4271 for (int i = 0 ; i < lines .size (); i ++) {
@@ -51,7 +80,7 @@ private static void writeLines(Path path, List<String> lines) throws IOException
5180 Files .writeString (path , sb .toString (), StandardCharsets .UTF_8 );
5281 }
5382
54- private static SummaryAndComment buildSummaryAndComment (Map <String , Object > data , String title , String marker , String successMessage , CoverageSummary coverage , Long vmTime , Long compilationTime ) {
83+ private static SummaryAndComment buildSummaryAndComment (Map <String , Object > data , String title , String marker , String successMessage , CoverageSummary coverage , Long vmTime , Long compilationTime , Map < String , String > extraStats ) {
5584 List <String > summaryLines = new ArrayList <>();
5685 List <String > commentLines = new ArrayList <>();
5786 Object resultsObj = data .get ("results" );
@@ -161,7 +190,7 @@ private static SummaryAndComment buildSummaryAndComment(Map<String, Object> data
161190 }
162191
163192 // Add benchmark results at the end
164- appendBenchmarkResults (commentLines , vmTime , compilationTime );
193+ appendBenchmarkResults (commentLines , vmTime , compilationTime , extraStats );
165194
166195 if (commentLines .isEmpty () || (commentLines .size () == 1 && commentLines .get (0 ).isEmpty ())) {
167196 // This fallback block might be redundant now, but kept for safety.
@@ -231,8 +260,8 @@ private static void appendCoverageSummary(List<String> summaryLines, CoverageSum
231260 }
232261 }
233262
234- private static void appendBenchmarkResults (List <String > commentLines , Long vmTime , Long compilationTime ) {
235- if (vmTime == null && compilationTime == null ) {
263+ private static void appendBenchmarkResults (List <String > commentLines , Long vmTime , Long compilationTime , Map < String , String > extraStats ) {
264+ if (vmTime == null && compilationTime == null && ( extraStats == null || extraStats . isEmpty ()) ) {
236265 return ;
237266 }
238267 if (!commentLines .isEmpty () && !commentLines .get (commentLines .size () - 1 ).isEmpty ()) {
@@ -246,6 +275,15 @@ private static void appendBenchmarkResults(List<String> commentLines, Long vmTim
246275 if (compilationTime != null ) {
247276 commentLines .add (String .format ("- **Compilation Time:** %d seconds" , compilationTime ));
248277 }
278+ if (extraStats != null && !extraStats .isEmpty ()) {
279+ commentLines .add ("" );
280+ commentLines .add ("#### Detailed Performance Metrics" );
281+ commentLines .add ("| Metric | Duration |" );
282+ commentLines .add ("| --- | --- |" );
283+ for (Map .Entry <String , String > entry : extraStats .entrySet ()) {
284+ commentLines .add (String .format ("| %s | %s |" , entry .getKey (), entry .getValue ()));
285+ }
286+ }
249287 commentLines .add ("" );
250288 }
251289
@@ -450,8 +488,9 @@ private static class Arguments {
450488 final String coverageHtmlUrl ;
451489 final Long vmTime ;
452490 final Long compilationTime ;
491+ final List <Path > extraStats ;
453492
454- private Arguments (Path compareJson , Path commentOut , Path summaryOut , String marker , String title , String successMessage , Path coverageSummary , String coverageHtmlUrl , Long vmTime , Long compilationTime ) {
493+ private Arguments (Path compareJson , Path commentOut , Path summaryOut , String marker , String title , String successMessage , Path coverageSummary , String coverageHtmlUrl , Long vmTime , Long compilationTime , List < Path > extraStats ) {
455494 this .compareJson = compareJson ;
456495 this .commentOut = commentOut ;
457496 this .summaryOut = summaryOut ;
@@ -462,6 +501,7 @@ private Arguments(Path compareJson, Path commentOut, Path summaryOut, String mar
462501 this .coverageHtmlUrl = coverageHtmlUrl ;
463502 this .vmTime = vmTime ;
464503 this .compilationTime = compilationTime ;
504+ this .extraStats = extraStats ;
465505 }
466506
467507 static Arguments parse (String [] args ) {
@@ -475,6 +515,7 @@ static Arguments parse(String[] args) {
475515 String coverageHtmlUrl = null ;
476516 Long vmTime = null ;
477517 Long compilationTime = null ;
518+ List <Path > extraStats = new ArrayList <>();
478519 for (int i = 0 ; i < args .length ; i ++) {
479520 String arg = args [i ];
480521 switch (arg ) {
@@ -558,6 +599,13 @@ static Arguments parse(String[] args) {
558599 return null ;
559600 }
560601 }
602+ case "--extra-stats" -> {
603+ if (++i >= args .length ) {
604+ System .err .println ("Missing value for --extra-stats" );
605+ return null ;
606+ }
607+ extraStats .add (Path .of (args [i ]));
608+ }
561609 default -> {
562610 System .err .println ("Unknown argument: " + arg );
563611 return null ;
@@ -568,7 +616,7 @@ static Arguments parse(String[] args) {
568616 System .err .println ("--compare-json, --comment-out, and --summary-out are required" );
569617 return null ;
570618 }
571- return new Arguments (compare , comment , summary , marker , title , successMessage , coverageSummary , coverageHtmlUrl , vmTime , compilationTime );
619+ return new Arguments (compare , comment , summary , marker , title , successMessage , coverageSummary , coverageHtmlUrl , vmTime , compilationTime , extraStats );
572620 }
573621 }
574622
0 commit comments