jenkinsci / ontrack-plugin

ontrack plug-in for Jenkins
https://plugins.jenkins.io/ontrack/
MIT License
9 stars 6 forks source link

Get a more precise timing for the stage execution time #54

Closed dcoraboeuf closed 5 years ago

dcoraboeuf commented 5 years ago

The current way to get the execution time for a stage if to get the total timing of the stage ; this includes queuing time and node preparation time.

We want the time to be only about the execution of the stage.

dcoraboeuf commented 5 years ago

In a declarative pipeline, when using:

stage("x") {
   agent { }
}

the time to create the agent if not available is taken into account when measuring the timing of the x stage:

image

It's a same issue with a scripted pipeline written this way:

stage("x") {
   node {
   }
}
image

When inverting the syntax:

node {
   stage("x") {}
}

then the computation is OK:

image

So it means that have to take into account the cases of:

i) declarative pipeline ii) node creation inside a declarative stage

The case iii) node creation outside of a stage is already correct.

dcoraboeuf commented 5 years ago

Proposal: when computing the execution time of a stage, we go up the step tree until we find the stage step itself. We take its execution time s.

On the way up the tree, we collect each "Allocate node" step execution time into the n time.

The computed stage execution time will be x = s - t.

This will solve cases i) and ii) (and also work for iii) where t = 0)

dcoraboeuf commented 5 years ago

"Allocate Node: Start" (n) and "Allocate Node: Body: Start" (b) have to be taken into account.

If no such step is seen before we get to the stage, t = s.

If not, t = sum(b) where b is the list of "Node: Body: Start" steps.

dcoraboeuf commented 5 years ago

Fixed in 3.4