#!/usr/bin/env python
# Copyright 2020 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 os
import json
import sys

tracing_path = os.path.abspath(os.path.join(
  os.path.dirname(os.path.realpath(__file__)), '..'))
sys.path.append(tracing_path)
from tracing.value import histogram_set


def main():
  parser = argparse.ArgumentParser(description='Convert a histogram.proto proto'
                                   'to histogram JSON.', add_help=False)
  parser.add_argument('proto_path', help='proto file path (input).')
  args = parser.parse_args()

  hs = histogram_set.HistogramSet()
  with open(args.proto_path, "rb") as f:
    hs.ImportProto(f.read())

  print(json.dumps(hs.AsDicts(), indent=4))

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