• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2016 The Chromium Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4import os
5
6from perf_insights import map_single_trace
7from perf_insights import function_handle
8from perf_insights.mre import file_handle
9from perf_insights.mre import job as job_module
10
11_METRIC_MAP_FUNCTION_FILENAME = 'metric_map_function.html'
12
13_METRIC_MAP_FUNCTION_NAME = 'metricMapFunction'
14
15def _GetMetricsDir():
16  return os.path.dirname(os.path.abspath(__file__))
17
18def _GetMetricRunnerHandle(metric):
19  assert isinstance(metric, basestring)
20  metrics_dir = _GetMetricsDir()
21  metric_mapper_path = os.path.join(metrics_dir, _METRIC_MAP_FUNCTION_FILENAME)
22
23  modules_to_load = [function_handle.ModuleToLoad(filename=metric_mapper_path)]
24  map_function_handle = function_handle.FunctionHandle(
25      modules_to_load, _METRIC_MAP_FUNCTION_NAME, {'metric': metric})
26
27  return job_module.Job(map_function_handle, None)
28
29def RunMetric(filename, metric, extra_import_options=None):
30  th = file_handle.URLFileHandle(filename, 'file://' + filename)
31  result = map_single_trace.MapSingleTrace(
32      th, _GetMetricRunnerHandle(metric), extra_import_options)
33
34  return result
35