#!/usr/bin/env python3



import argparse
import json
import os
import sys

def main():
    parser = argparse.ArgumentParser(description='Collect all the profile results and process into single json object')
    parser.add_argument('-i', '--input', required=True, help='Directory to read samples from')
    parser.add_argument('-o', '--output', required=True, help='Where to put the json file')
    args = parser.parse_args()
    files = os.listdir(args.input)
    samples = {}
    for file in files:
        try:
            with open(args.input + '/' + file, 'r') as f:
                samples[file] = json.load(f)
        except OSError:
            pass

    if samples:
        with open(args.output, 'w') as f:
            json.dump(samples, f, indent=4, sort_keys=True)
 
if __name__ == '__main__':
    rc = main()
    sys.exit(rc)
