1 <!DOCTYPE html> 2 <!-- 3 Copyright (c) 2015 The Chromium Authors. All rights reserved. 4 Use of this source code is governed by a BSD-style license that can be 5 found in the LICENSE file. 6 --> 7 <link rel="import" href="/perf_insights/function_handle.html"> 8 <link rel="import" href="/perf_insights/map_single_trace.html"> 9 <link rel="import" href="/perf_insights/mre/failure.html"> 10 <link rel="import" href="/perf_insights/mre/file_handle.html"> 11 <link rel="import" href="/perf_insights/mre/job.html"> 12 <link rel="import" href="/perf_insights/mre/mre_result.html"> 13 14 <script> 15 'use strict'; 16 17 tr.exportTo('pi', function() { 18 19 var Failure = pi.mre.Failure; 20 21 function createModelFromTraceData(traceData, 22 canonicalUrl, 23 opt_extraImportOptions) { 24 var model = new tr.Model(); 25 try { 26 var importOptions = new tr.importer.ImportOptions(); 27 importOptions.pruneEmptyContainers = false; 28 importOptions.showImportWarnings = false; 29 if (opt_extraImportOptions !== undefined) { 30 for (var property in opt_extraImportOptions) { 31 if (opt_extraImportOptions.hasOwnProperty(property)) { 32 importOptions[property] = opt_extraImportOptions[property]; 33 } 34 } 35 } 36 37 var i = new tr.importer.Import(model, importOptions); 38 i.importTraces([traceData]); 39 } catch (ex) { 40 ex.name = 'TraceImportError'; 41 throw ex; 42 } 43 44 model.canonicalUrlThatCreatedThisTrace = canonicalUrl; 45 46 return model; 47 } 48 49 function mapSingleTraceMain(args) { 50 if (args.length !== 2 && args.length !== 3) 51 throw new Error('Must provide two or three arguments.'); 52 53 var options = { 54 traceHandle: pi.mre.FileHandle.fromDict(JSON.parse(args[0])), 55 job: pi.mre.Job.fromDict(JSON.parse(args[1])), 56 extraImportOptions: args.length === 3 ? JSON.parse(args[2]) : undefined 57 }; 58 59 var result = new pi.mre.MreResult(); 60 61 var canonicalUrl = options.traceHandle.canonicalUrl; 62 63 pi.runAndConvertErrorsToFailures( 64 result, options.job, options.traceHandle, 65 function() { 66 var mapFunction = options.job.mapFunctionHandle.load(); 67 var traceData = options.traceHandle.load(); 68 var model = createModelFromTraceData( 69 traceData, canonicalUrl, options.extraImportOptions); 70 var opt_options = options.job.mapFunctionHandle.options; 71 pi.mapSingleTrace(result, model, opt_options, mapFunction); 72 }); 73 74 console.log('MRE_RESULT: ' + JSON.stringify(result.asDict())); 75 return 0; 76 } 77 78 return { 79 mapSingleTraceMain: mapSingleTraceMain 80 }; 81 }); 82 83 if (tr.isHeadless) 84 quit(pi.mapSingleTraceMain(sys.argv.slice(1))); 85 86 </script> 87