blob: c88682c5051971a87a3f5bc1151ad9c90555a37e [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="/tracing/base/base.html">
<link rel="import" href="/tracing/base/utils.html">
<link rel="import" href="/tracing/base/xhr.html">
<link rel="import" href="/tracing/model/model.html">
<link rel="import" href="/tracing/extras/full_config.html">
<link rel="import" href="/perf_insights/value/value.html">
<link rel="import" href="/perf_insights/map_function.html">
<script>
'use strict';
tr.exportTo('pi', function() {
var currentRunID = undefined;
var FailureValue = pi.v.FailureValue;
function mapSingleTrace(results, options) {
try {
currentRunID = options.run_info.run_id;
mapSingleTraceImpl(results, options);
} finally {
currentRunID = undefined;
}
}
function mapSingleTraceImpl(results, options) {
// Load the mapper.
var allTypeInfos = pi.MapFunction.getAllRegisteredTypeInfos();
try {
var numTypeInfosBefore = allTypeInfos.length;
loadHTMLFile(options.map_file, options.map_file);
} catch (ex) {
var ex = tr.b.normalizeException(ex);
results.addValue(new FailureValue(
options.run_info, 'MapFunctionLoadingError',
{description: ex.message, stack: ex.stack}));
return;
} finally {
if (numTypeInfosNow !== numTypeInfosBefore) {
}
}
// Verify a mapFunction was defined.
var numTypeInfosNow = allTypeInfos.length;
if (numTypeInfosNow !== (numTypeInfosBefore + 1)) {
results.addValue(new FailureValue(
options.run_info, 'MapFunctionNotDefinedError',
{description: options.map_file + ' did not call defineMapFunction',
stack: tr.b.stackTraceAsString()}));
return;
}
var mapFunction = allTypeInfos[allTypeInfos.length - 1].constructor;
// Data.
try {
var traceData = tr.b.getSync('file://' + options.filename_to_map);
} catch (ex) {
results.addValue(new FailureValue(
options.run_info, 'TraceImportError',
{description: 'Could not open ' + options.filename_to_map,
stack: tr.b.stackTraceAsString()}));
return;
}
// Load the model.
var importOptions = new tr.ImportOptions();
importOptions.pruneEmptyContainers = false;
importOptions.showImportWarnings = false;
var model = new tr.Model();
try {
model.importTraces([traceData], importOptions);
} catch (ex) {
var ex = tr.b.normalizeException(ex);
results.addValue(new FailureValue(
options.run_info, 'TraceImportError',
{description: ex.message, stack: ex.stack}));
return;
}
// Mixin the metadata in case its interesting to the mapper.
for (var k in options.metadata) {
if (model.metadata[k] !== undefined) {
results.addValue(new FailureValue(
options.run_info, 'TraceImportError',
{description: k + ' is on model and corpus tables!',
stack: tr.b.stackTraceAsString()}));
return;
}
model.metadata[k] = options.metadata[k];
}
// Map the function.
var numResultsBeforeMapping = results.all_values.length;
try {
mapFunction(results, options.run_info, model);
} catch (ex) {
var ex = tr.b.normalizeException(ex);
results.addValue(new FailureValue(
options.run_info, 'MapFunctionError',
{description: ex.message, stack: ex.stack}));
return;
}
if (results.all_values.length === numResultsBeforeMapping) {
results.addValue(new FailureValue(
options.run_info, 'NoResultsAddedError',
{'description': options.map_file + ' did not add any results! ' +
'Add a SkipValue if this was intentional.',
stack: tr.b.stackTraceAsString()}));
return;
}
}
return {
mapSingleTrace: mapSingleTrace
};
});
</script>