diff --git a/src/main/java/jenkins/metrics/impl/TimeInQueueAction.java b/src/main/java/jenkins/metrics/impl/TimeInQueueAction.java index b8bd183..bc3964b 100644 --- a/src/main/java/jenkins/metrics/impl/TimeInQueueAction.java +++ b/src/main/java/jenkins/metrics/impl/TimeInQueueAction.java @@ -30,6 +30,8 @@ import hudson.model.queue.SubTask; import java.io.Serializable; import java.util.List; +import java.util.HashMap; +import java.util.Map; import jenkins.model.RunAction2; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.DoNotUse; @@ -158,6 +160,28 @@ public long getQueuingTimeMillis() { return total; } + /** + * Returns the a map of all the subtasks in this {@link Run} mapped to the time spent by each {@link SubTask} in queue. + * Subtasks are denoted in the map by chronological order and the subtask time in queue is denoted using + * {@link SubTaskTimeInQueueAction#getQueuingDurationMillis()} + * + * @return a map where each {@link SubTask} in this {@link Run} is mapped to each subtask's time in queue + */ + @Exported(visibility = 2) + public Map getSubTaskMap() { + + Map subtasks = new HashMap(); + if (run == null) { + return subtasks; + } + int subtask_count = 0; + for (SubTaskTimeInQueueAction t : run.getActions(SubTaskTimeInQueueAction.class)) { + subtasks.put("Subtask_" + subtask_count, t.getQueuingDurationMillis()); + subtask_count = subtask_count + 1; + } + return subtasks; + } + /** * Returns the total time this {@link Run}, and any associated {@link SubTask}s, spent in the queue because they * were blocked.