Commit 78cc99cc authored by Woonsan Ko's avatar Woonsan Ko

CMS-10078: adding hdc logging option for max threshold for subtasks

parent 39582638
......@@ -21,13 +21,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Utility class to get a pretty printed hierarchical task log
* Utility class to get a pretty printed hierarchical task log.
*/
public class TaskLogFormatUtils {
private static final Logger log = LoggerFactory.getLogger(TaskLogFormatUtils.class);
/**
* Returns a nicely formatted string showing all the tasks hierarchically.
* @return returns the <code>task</code> nicely hierarchical formatted
*/
public static String getTaskLog(Task task) {
......@@ -35,16 +36,39 @@ public class TaskLogFormatUtils {
}
/**
*
* Returns a formatted string from the <code>task</code> including its descendant tasks.
* The log should include descendant tasks only in <code>maxDepth</code> level at max.
* When <code>maxDepth</code> is set to a negative value, all the descendant tasks will be included.
* @param task the task to log
* @param maxDepth the maximum depth until how deep child tasks should be logged. <code>maxDepth</code> of <code>-1</code>
* @param maxDepth the maximum depth until how deep child tasks should be logged. A negative <code>maxDepth</code> value
* will log all descendant tasks, <code>maxDepth</code> of <code>0</code> only the rootTask, <code>maxDepth</code>
* of <code>1</code> the rootTask plus its direct children, etc.
* @return
*/
public static String getTaskLog(Task task, final int maxDepth) {
StringBuilder sb = new StringBuilder(256);
appendTaskLog(sb, task, 0, new BitSet(0), false, maxDepth);
appendTaskLog(sb, task, 0, new BitSet(0), false, maxDepth, -1);
return sb.toString();
}
/**
* Returns a formatted string from the <code>task</code> including its descendant tasks.
* The log should include descendant tasks only in <code>maxDepth</code> level at max.
* When <code>maxDepth</code> is set to a negative value, all the descendant tasks will be included.
* Also, the log should include descendant tasks only a descendant task takes more time than
* <code>subtaskThresholdMillisec</code> in milliseconds.
* When <code>subtaskThresholdMillisec</code> is set to a non-negative value, only descendant tasks which take not less
* time than <code>taskThresholdMillisec</code> will be included.
* @param task the task to log
* @param maxDepth the maximum depth until how deep child tasks should be logged. A negative <code>maxDepth</code> value
* will log all descendant tasks, <code>maxDepth</code> of <code>0</code> only the rootTask, <code>maxDepth</code>
* of <code>1</code> the rootTask plus its direct children, etc.
* @param subtaskThresholdMillisec the threshold time milliseconds to include logs of subtasks under <code>task</code>.
* @return
*/
public static String getTaskLog(Task task, final int maxDepth, final long subtaskThresholdMillisec) {
StringBuilder sb = new StringBuilder(256);
appendTaskLog(sb, task, 0, new BitSet(0), false, maxDepth, subtaskThresholdMillisec);
return sb.toString();
}
......@@ -53,11 +77,20 @@ public class TaskLogFormatUtils {
final int depth,
final BitSet bitset,
final boolean lastChild,
final int maxDepth) {
final int maxDepth,
final long subtaskThresholdMillisec) {
if (maxDepth > -1 && depth > maxDepth) {
return;
}
final long durationTimeMillis = task.getDurationTimeMillis();
if (depth > 0 && subtaskThresholdMillisec > -1) {
if (durationTimeMillis < subtaskThresholdMillisec) {
return;
}
}
BitSet hidePipeAt = new BitSet(depth);
hidePipeAt.or(bitset);
for (int i = 0; i < depth; i++) {
......@@ -80,7 +113,7 @@ public class TaskLogFormatUtils {
}
}
try {
String msg = "- " + task.getName() + " (" + task.getDurationTimeMillis() + "ms): " + task.getAttributeMap();
String msg = "- " + task.getName() + " (" + durationTimeMillis + "ms): " + task.getAttributeMap();
sb.append(msg).append('\n');
} catch (Throwable e) {
if (log.isDebugEnabled()) {
......@@ -94,9 +127,9 @@ public class TaskLogFormatUtils {
for (Task childTask : task.getChildTasks()) {
count++;
if (count == task.getChildTasks().size()) {
appendTaskLog(sb, childTask, depth + 1,hidePipeAt, true, maxDepth);
appendTaskLog(sb, childTask, depth + 1,hidePipeAt, true, maxDepth, subtaskThresholdMillisec);
} else {
appendTaskLog(sb, childTask, depth + 1,hidePipeAt, false, maxDepth);
appendTaskLog(sb, childTask, depth + 1,hidePipeAt, false, maxDepth, subtaskThresholdMillisec);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment