aboutsummaryrefslogtreecommitdiff
path: root/catapult/tracing/bin/validate_all_metrics
blob: 4711c5590f8778900f86182191c4cd72bdb0bbdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
# Copyright 2016 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.

import argparse
import json
import os
import string
import sys

sys.path.insert(1, os.path.join(os.path.dirname(__file__), '..'))
from tracing.metrics import discover
import tracing_project


def Main():
  all_registered_metrics = set(discover.DiscoverMetrics(
      ['/tracing/metrics/all_metrics.html']))
  all_modules = list(
      '/' + rel_path for rel_path in
      tracing_project.TracingProject().FindAllMetricsModuleRelPaths())
  all_possible_metrics = set(discover.DiscoverMetrics(all_modules))
  unregistered_metrics = all_possible_metrics - all_registered_metrics
  if unregistered_metrics:
    print ('These metrics are unregistered: %s. Please import their modules in '
           'tracing/tracing/metrics/all_metrics.html' %
           ', '.join(unregistered_metrics))
    return 1
  uppercased_metrics = []
  for m in all_possible_metrics:
    if str.isupper(m[0]):
      uppercased_metrics.append(m)
  if uppercased_metrics:
    print ('These metrics must be renamed to start with a lower-case: %s' %
           uppercased_metrics)
    return 1
  return 0

if __name__ == '__main__':
  sys.exit(Main())