Browse Source

HADOOP-2895. Let the profiling string be configurable.
Contributed by Martin Traverso




git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@632411 13f79535-47bb-0310-9956-ffa450edef68

Christopher Douglas 17 years ago
parent
commit
ea17888aaa

+ 3 - 0
CHANGES.txt

@@ -47,6 +47,9 @@ Trunk (unreleased changes)
     methods for fs.default.name, and check for null authority in HDFS.
     (cutting)
 
+    HADOOP-2895. Let the profiling string be configurable.
+    (Martin Traverso via cdouglas)
+
   OPTIMIZATIONS
 
   BUG FIXES

+ 27 - 0
src/java/org/apache/hadoop/mapred/JobConf.java

@@ -1204,6 +1204,33 @@ public class JobConf extends Configuration {
     setBoolean("mapred.task.profile", newValue);
   }
 
+  /**
+   * Get the profiler configuration arguments.
+   *
+   * The default value for this property is
+   * "-agentlib:hprof=cpu=samples,heap=sites,force=n,thread=y,verbose=n,file=%s"
+   * 
+   * @return the parameters to pass to the task child to configure profiling
+   */
+  public String getProfileParams() {
+    return get("mapred.task.profile.params",
+               "-agentlib:hprof=cpu=samples,heap=sites,force=n,thread=y," +
+                 "verbose=n,file=%s");
+  }
+
+  /**
+   * Set the profiler configuration arguments. If the string contains a '%s' it
+   * will be replaced with the name of the profiling output file when the task
+   * runs.
+   *
+   * This value is passed to the task child JVM on the command line.
+   *
+   * @param value the configuration string
+   */
+  public void setProfileParams(String value) {
+    set("mapred.task.profile.params", value);
+  }
+
   /**
    * Get the range of maps or reduces to profile.
    * @param isMap is the task a map?

+ 1 - 2
src/java/org/apache/hadoop/mapred/TaskRunner.java

@@ -355,8 +355,7 @@ abstract class TaskRunner extends Thread {
         if (conf.getProfileTaskRange(t.isMapTask()
                                      ).isIncluded(t.getPartition())) {
           File prof = TaskLog.getTaskLogFile(taskid, TaskLog.LogName.PROFILE);
-          vargs.add("-agentlib:hprof=cpu=samples,heap=sites,force=n,thread=y,"
-                     + "verbose=n,file=" + prof.toString());
+          vargs.add(String.format(conf.getProfileParams(), prof.toString()));
         }
       }
 

+ 53 - 0
src/test/org/apache/hadoop/conf/TestJobConf.java

@@ -0,0 +1,53 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hadoop.conf;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+import org.apache.hadoop.mapred.JobConf;
+
+public class TestJobConf extends TestCase {
+
+  public void testProfileParamsDefaults() {
+    JobConf configuration = new JobConf();
+
+    Assert.assertNull(configuration.get("mapred.task.profile.params"));
+
+    String result = configuration.getProfileParams();
+
+    Assert.assertNotNull(result);
+    Assert.assertTrue(result.contains("file=%s"));
+    Assert.assertTrue(result.startsWith("-agentlib:hprof"));
+  }
+
+  public void testProfileParamsSetter() {
+    JobConf configuration = new JobConf();
+
+    configuration.setProfileParams("test");
+    Assert.assertEquals("test", configuration.get("mapred.task.profile.params"));
+  }
+
+  public void testProfileParamsGetter() {
+    JobConf configuration = new JobConf();
+
+    configuration.set("mapred.task.profile.params", "test");
+    Assert.assertEquals("test", configuration.getProfileParams());
+  }
+
+
+}