blob: 583aae103776f43a25eeb4b13bfbdc78008c050b [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/perf_insights/mre/failure.html">
<link rel="import" href="/tracing/base/base.html">
<link rel="import" href="/tracing/base/iteration_helpers.html">
<link rel="import" href="/tracing/base/utils.html">
<link rel="import" href="/tracing/base/xhr.html">
<link rel="import" href="/tracing/extras/full_config.html">
<link rel="import" href="/tracing/importer/import.html">
<link rel="import" href="/tracing/model/model.html">
<script>
'use strict';
tr.exportTo('pi', function() {
var Failure = pi.mre.Failure;
function runAndConvertErrorsToFailures(result, job,
traceHandle, cb, opt_this) {
try {
cb.call(opt_this);
} catch (err) {
var err = tr.b.normalizeException(err);
// TODO(eakuefner): Set job once reduction is implemented.
result.addFailure(new Failure(
job, job.mapFunctionHandle.asUserFriendlyString(),
traceHandle.canonicalUrl, err.typeName, err.message, err.stack));
}
}
function mapSingleTrace(result, model, options, mapFunction) {
// Do not map the trace if its timer is low resolution.
if (!model.isTimeHighResolution) {
var err = new Error('Trace doesn\'t have high resolution time, ' +
'cannot map.');
err.name = 'LowResolutionTimeError';
throw err;
}
// Map the function.
var numPairsBeforeMapping = tr.b.dictionaryLength(result.pairs);
var numFailuresBeforeMapping = result.failures.length;
try {
mapFunction(result, model, options);
} catch (ex) {
ex.name = 'MapFunctionError';
throw ex;
}
var addedPairs = (tr.b.dictionaryLength(result.pairs) >
numPairsBeforeMapping);
var addedFailures = result.failures.length > numFailuresBeforeMapping;
if (!(addedPairs || addedFailures)) {
var err = new Error('Mapper did not add any results!');
err.name = 'NoResultsAddedError';
throw err;
}
}
return {
mapSingleTrace: mapSingleTrace,
runAndConvertErrorsToFailures: runAndConvertErrorsToFailures
};
});
</script>