Skip to content
Snippets Groups Projects
Commit fdfd3ad7 authored by Alexander Rose's avatar Alexander Rose
Browse files

added user-timing to mol-task

parent b45a3cf7
No related branches found
No related tags found
No related merge requests found
/**
* Copyright (c) 2017 mol* contributors, licensed under MIT, See LICENSE file for more info.
* Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
......@@ -9,6 +9,7 @@ import { RuntimeContext } from './runtime-context'
import { Progress } from './progress'
import { now } from '../util/now'
import { Scheduler } from '../util/scheduler'
import { UserTiming } from '../util/user-timing'
interface ExposedTask<T> extends Task<T> {
f: (ctx: RuntimeContext) => Promise<T>,
......@@ -91,9 +92,12 @@ function snapshotProgress(info: ProgressInfo): Progress {
}
async function execute<T>(task: ExposedTask<T>, ctx: ObservableRuntimeContext) {
UserTiming.markStart(task)
ctx.node.progress.startedTime = now();
try {
const ret = await task.f(ctx);
UserTiming.markEnd(task)
UserTiming.measure(task)
if (ctx.info.abortToken.abortRequested) {
abort(ctx.info, ctx.node);
}
......
/**
* Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author Alexander Rose <alexander.rose@weirdbyte.de>
*/
import { Task } from '../task'
const hasPerformance = typeof performance !== 'undefined'
export namespace UserTiming {
function startMarkName(task: Task<any>) { return `startTask${task.id}` }
function endMarkName(task: Task<any>) { return `endTask${task.id}` }
export function markStart(task: Task<any>) {
if (hasPerformance) performance.mark(startMarkName(task))
}
export function markEnd(task: Task<any>) {
if (hasPerformance) performance.mark(endMarkName(task))
}
export function measure(task: Task<any>) {
if (hasPerformance) performance.measure(task.name, startMarkName(task), endMarkName(task))
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment