Skip to content

Commit

Permalink
Merge pull request #1 from deepfield/subtask_map
Browse files Browse the repository at this point in the history
Return subtask map
  • Loading branch information
matchand-nokia authored Jun 30, 2021
2 parents 06a8665 + 8bb24cb commit feb20c5
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/jenkins/metrics/impl/TimeInQueueAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, Long> getSubTaskMap() {

Map<String, Long> subtasks = new HashMap<String, Long>();
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.
Expand Down

0 comments on commit feb20c5

Please sign in to comment.