Skip to content

Commit c8c486a

Browse files
authored
[ui5-builder][INTERNAL] Enable task processing time measurement (#745)
By using the environment variable UI5_PERF_TASK=true the processing time of a task is calculated and written to the log BLI: CPOUI5FOUNDATION-497
1 parent 73808e3 commit c8c486a

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

packages/builder/lib/types/AbstractBuilder.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class AbstractBuilder {
201201
* @param {Array} tasksToRun List of tasks which should be executed
202202
* @returns {Promise} Returns promise chain with tasks
203203
*/
204-
build(tasksToRun) {
204+
async build(tasksToRun) {
205205
const allTasks = this.taskExecutionOrder.filter((taskName) => {
206206
// There might be a numeric suffix in case a custom task is configured multiple times.
207207
// The suffix needs to be removed in order to check against the list of tasks to run.
@@ -217,15 +217,12 @@ class AbstractBuilder {
217217

218218
this.taskLog.addWork(allTasks.length);
219219

220-
return allTasks.reduce((taskChain, taskName) => {
220+
for (const taskName of allTasks) {
221221
const taskFunction = this.tasks[taskName];
222-
223222
if (typeof taskFunction === "function") {
224-
taskChain = taskChain.then(this.wrapTask(taskName, taskFunction));
223+
await this.executeTask(taskName, taskFunction);
225224
}
226-
227-
return taskChain;
228-
}, Promise.resolve());
225+
}
229226
}
230227

231228
/**
@@ -234,13 +231,16 @@ class AbstractBuilder {
234231
* @private
235232
* @param {string} taskName Name of the task
236233
* @param {Function} taskFunction Function which executed the task
237-
* @returns {Function} Wrapped task function
234+
* @returns {Promise} Resolves when task has finished
238235
*/
239-
wrapTask(taskName, taskFunction) {
240-
return () => {
241-
this.taskLog.startWork(`Running task ${taskName}...`);
242-
return taskFunction().then(() => this.taskLog.completeWork(1));
243-
};
236+
async executeTask(taskName, taskFunction) {
237+
this.taskLog.startWork(`Running task ${taskName}...`);
238+
this._taskStart = performance.now();
239+
await taskFunction();
240+
this.taskLog.completeWork(1);
241+
if (process.env.UI5_PERF_TASK) {
242+
this.taskLog.info(`Task succeeded in ${Math.round((performance.now() - this._taskStart))} ms`);
243+
}
244244
}
245245

246246
/**

0 commit comments

Comments
 (0)