github.com/xgoffin/jenkins-library@v1.154.0/vars/durationMeasure.groovy (about) 1 import com.sap.piper.GenerateDocumentation 2 import static com.sap.piper.Prerequisites.checkScript 3 import com.sap.piper.analytics.InfluxData 4 5 import groovy.transform.Field 6 7 @Field STEP_NAME = getClass().getName() 8 9 @Field Set GENERAL_CONFIG_KEYS = [] 10 11 @Field Set STEP_CONFIG_KEYS = [] 12 13 @Field Set PARAMETER_KEYS = [ 14 /** Defines the name of the measurement which is written to the Influx database.*/ 15 'measurementName' 16 ] 17 18 /** 19 * This step is used to measure the duration of a set of steps, e.g. a certain stage. 20 * The duration is stored in a Map. The measurement data can then be written to an Influx database using step [influxWriteData](influxWriteData.md). 21 * 22 * !!! tip 23 * Measuring for example the duration of pipeline stages helps to identify potential bottlenecks within the deployment pipeline. 24 * This then helps to counter identified issues with respective optimization measures, e.g parallelization of tests. 25 */ 26 @GenerateDocumentation 27 def call(Map parameters = [:], body) { 28 29 def script = checkScript(this, parameters) 30 31 def measurementName = parameters.get('measurementName', 'test_duration') 32 33 //start measurement 34 def start = System.currentTimeMillis() 35 36 body() 37 38 //record measurement 39 def duration = System.currentTimeMillis() - start 40 41 InfluxData.addField('pipeline_data', measurementName, duration) 42 43 return duration 44 }