3535import org .apache .hadoop .mapreduce .*;
3636import org .apache .hadoop .mapreduce .TaskAttemptID ;
3737import org .apache .hadoop .mapreduce .v2 .api .records .JobId ;
38+ import org .apache .hadoop .util .Shell ;
3839import org .apache .hadoop .yarn .api .records .ApplicationId ;
3940import org .apache .hadoop .yarn .conf .YarnConfiguration ;
4041import org .apache .hadoop .yarn .server .resourcemanager .rmapp .RMAppState ;
4344import org .slf4j .Logger ;
4445import org .slf4j .LoggerFactory ;
4546
47+ import static org .junit .Assume .assumeFalse ;
48+
4649public class TestMRJobsWithProfiler {
4750
4851 private static final Logger LOG =
@@ -107,6 +110,8 @@ public static void tearDown() {
107110
108111 @ Test (timeout = 150000 )
109112 public void testDefaultProfiler () throws Exception {
113+ assumeFalse ("The hprof agent has been removed since Java 9. Skipping." ,
114+ Shell .isJavaVersionAtLeast (9 ));
110115 LOG .info ("Starting testDefaultProfiler" );
111116 testProfilerInternal (true );
112117 }
@@ -132,13 +137,21 @@ private void testProfilerInternal(boolean useDefault) throws Exception {
132137 sleepConf .setProfileTaskRange (false , String .valueOf (PROFILED_TASK_ID ));
133138
134139 if (!useDefault ) {
135- // use hprof for map to profile.out
136- sleepConf .set (MRJobConfig .TASK_MAP_PROFILE_PARAMS ,
137- "-agentlib:hprof=cpu=samples,heap=sites,force=n,thread=y,verbose=n,"
138- + "file=%s" );
140+ if (Shell .isJavaVersionAtLeast (9 )) {
141+ // use JDK Flight Recorder
142+ sleepConf .set (MRJobConfig .TASK_MAP_PROFILE_PARAMS ,
143+ "-XX:StartFlightRecording=dumponexit=true,filename=%s" );
144+ sleepConf .set (MRJobConfig .TASK_REDUCE_PROFILE_PARAMS ,
145+ "-XX:StartFlightRecording=dumponexit=true,filename=%s" );
146+ } else {
147+ // use hprof for map to profile.out
148+ sleepConf .set (MRJobConfig .TASK_MAP_PROFILE_PARAMS ,
149+ "-agentlib:hprof=cpu=samples,heap=sites,force=n,thread=y,verbose=n,"
150+ + "file=%s" );
139151
140- // use Xprof for reduce to stdout
141- sleepConf .set (MRJobConfig .TASK_REDUCE_PROFILE_PARAMS , "-Xprof" );
152+ // use Xprof for reduce to stdout
153+ sleepConf .set (MRJobConfig .TASK_REDUCE_PROFILE_PARAMS , "-Xprof" );
154+ }
142155 }
143156
144157 sleepJob .setConf (sleepConf );
@@ -211,6 +224,11 @@ private void testProfilerInternal(boolean useDefault) throws Exception {
211224
212225 Assert .assertEquals (4 , taLogDirs .size ()); // all 4 attempts found
213226
227+ // Skip checking the contents because the JFR dumps binary files
228+ if (Shell .isJavaVersionAtLeast (9 )) {
229+ return ;
230+ }
231+
214232 for (Map .Entry <TaskAttemptID ,Path > dirEntry : taLogDirs .entrySet ()) {
215233 final TaskAttemptID tid = dirEntry .getKey ();
216234 final Path profilePath = new Path (dirEntry .getValue (),
0 commit comments