Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return subtask map #1

Merged
merged 2 commits into from
Jun 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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