11/*
2- * Copyright (c) 2015, 2020 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2015, 2021 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3333import java .io .FileWriter ;
3434import java .io .IOException ;
3535import java .io .PrintWriter ;
36+ import java .nio .file .Files ;
3637import java .nio .file .Path ;
3738import java .nio .file .Paths ;
38- import java .util .HashMap ;
39- import java .util .Map ;
4039
4140/**
4241 * The jtreg test execution observer, which gathers info about
4544public class GatherDiagnosticInfoObserver implements Harness .Observer {
4645 public static final String LOG_FILENAME = "environment.log" ;
4746 public static final String ENVIRONMENT_OUTPUT = "environment.html" ;
47+ public static final String CORES_OUTPUT = "cores.html" ;
48+
4849
4950 private Path compileJdk ;
5051 private Path testJdk ;
@@ -64,25 +65,31 @@ public void finishedTest(TestResult tr) {
6465 workDir .toFile ().mkdir ();
6566
6667 String name = getClass ().getName ();
67- PrintWriter log ;
68+ PrintWriter log1 ;
6869 boolean needClose = false ;
6970 try {
70- log = new PrintWriter (new FileWriter (
71+ log1 = new PrintWriter (new FileWriter (
7172 workDir .resolve (LOG_FILENAME ).toFile (), true ), true );
7273 needClose = true ;
7374 } catch (IOException e ) {
74- log = new PrintWriter (System .out );
75- log .printf ("ERROR: %s cannot open log file %s" , name ,
75+ log1 = new PrintWriter (System .out );
76+ log1 .printf ("ERROR: %s cannot open log file %s" , name ,
7677 LOG_FILENAME );
77- e .printStackTrace (log );
78+ e .printStackTrace (log1 );
7879 }
80+ final PrintWriter log = log1 ;
7981 try {
8082 log .printf ("%s ---%n" , name );
8183 GathererFactory gathererFactory = new GathererFactory (
8284 OS .current ().family , workDir , log ,
8385 testJdk , compileJdk );
8486 gatherEnvInfo (workDir , name , log ,
8587 gathererFactory .getEnvironmentInfoGatherer ());
88+ Files .walk (workDir )
89+ .filter (Files ::isRegularFile )
90+ .filter (f -> (f .getFileName ().toString ().contains ("core" ) || f .getFileName ().toString ().contains ("mdmp" )))
91+ .forEach (core -> gatherCoreInfo (workDir , name ,
92+ core , log , gathererFactory .getCoreInfoGatherer ()));
8693 } catch (Throwable e ) {
8794 log .printf ("ERROR: exception in observer %s:" , name );
8895 e .printStackTrace (log );
@@ -96,6 +103,22 @@ public void finishedTest(TestResult tr) {
96103 }
97104 }
98105
106+ private void gatherCoreInfo (Path workDir , String name , Path core , PrintWriter log ,
107+ CoreInfoGatherer gatherer ) {
108+ File output = workDir .resolve (CORES_OUTPUT ).toFile ();
109+ try (HtmlPage html = new HtmlPage (new PrintWriter (
110+ new FileWriter (output , true ), true ))) {
111+ try (ElapsedTimePrinter timePrinter
112+ = new ElapsedTimePrinter (new Stopwatch (), name , log )) {
113+ gatherer .gatherCoreInfo (html .getRootSection (), core );
114+ }
115+ } catch (Throwable e ) {
116+ log .printf ("ERROR: exception in observer on getting environment "
117+ + "information %s:" , name );
118+ e .printStackTrace (log );
119+ }
120+ }
121+
99122 private void gatherEnvInfo (Path workDir , String name , PrintWriter log ,
100123 EnvironmentInfoGatherer gatherer ) {
101124 File output = workDir .resolve (ENVIRONMENT_OUTPUT ).toFile ();
0 commit comments