#!/usr/bin/env python | |
import json | |
import jsonschema | |
import socket | |
import uuid | |
import time | |
from thclient import (TreeherderClient, TreeherderJobCollection, TreeherderArtifactCollection) | |
# These would come from a config | |
CLIENT_ID = 'awsy-local' # TODO(ER): Load from a config | |
CLIENT_SECRET = '1f055c18-6bd1-4600-a045-06ca4cf63d8e' # TODO(ER): Load from a config | |
TREEHERDER_HOST = 'local.treeherder.mozilla.org' # TODO(ER): Load from a config | |
# These would be params | |
repo = 'mozilla-inbound' | |
revision = '3001c83fdb81' | |
client = TreeherderClient(protocol='http', host=TREEHERDER_HOST, client_id=CLIENT_ID, secret=CLIENT_SECRET) | |
rev_hash = client.get_resultsets(repo, revision=revision)[0]['revision_hash'] | |
tjc = TreeherderJobCollection() | |
tj = tjc.get_job() | |
tj.add_tier(2) | |
tj.add_revision_hash(rev_hash) | |
tj.add_project(repo) | |
tj.add_job_guid(str(uuid.uuid4())) | |
######################################################### | |
# Treeherder rep: "AWSY(a1)" | |
tj.add_job_name('awsy 1') | |
tj.add_job_symbol('a1') | |
tj.add_group_name('awsy') | |
tj.add_group_symbol('AWSY') | |
######################################################### | |
tj.add_product_name('firefox') | |
tj.add_state('completed') | |
tj.add_result('success') | |
submit_timestamp = int(time.time()) | |
tj.add_submit_timestamp(submit_timestamp) | |
tj.add_start_timestamp(submit_timestamp) | |
tj.add_end_timestamp(submit_timestamp) | |
tj.add_machine(socket.getfqdn()) | |
tj.add_build_info('linux', 'linux64', 'x86_64') # TODO(ER): gank this from rwood's impl | |
tj.add_machine_info('linux', 'linux64', 'x86_64') | |
tj.add_option_collection({'opt': True}) # Presumably this means an opt build | |
########################################################################## | |
# This would include values for: | |
# - "MaxMemoryV2" | |
# - "MaxMemorySettledV2" | |
# - "MaxMemoryForceGCV2" | |
# - "MaxMemoryResidentV2" | |
# - "MaxMemoryResidentSettledV2" | |
# - "MaxMemoryResidentForceGCV2" | |
# - "StartMemoryV2" | |
# - "StartMemoryResidentV2" | |
# - "StartMemorySettledV2" | |
# - "StartMemoryResidentSettledV2" | |
# - "EndMemoryV2" | |
# - "EndMemoryResidentV2" | |
# - "EndMemorySettledV2" | |
# - "EndMemoryForceGCV2" | |
# - "EndMemoryResidentSettledV2" | |
# - "EndMemoryResidentForceGCV2" | |
# - "MaxHeapUnclassifiedV2" | |
# - "MaxJSV2" | |
# - "MaxImagesV2" | |
# Divide into 5 suites | |
rss_results = { | |
"MaxMemory": 12244, | |
"MaxMemorySettled": 122342, | |
"MaxMemoryForceGC": 12132, | |
"StartMemory": 2234, | |
"StartMemorySettled": 112321, | |
"EndMemory": 342343, | |
"EndMemorySettled": 234234, | |
"EndMemoryForceeGC": 23423432 | |
} | |
explicit_results = { | |
"MaxMemory": 12244, | |
"MaxMemorySettled": 122342, | |
"MaxMemoryForceGC": 12132, | |
"StartMemory": 2234, | |
"StartMemorySettled": 112321, | |
"EndMemory": 342343, | |
"EndMemorySettled": 234234, | |
"EndMemoryForceeGC": 23423432 | |
} | |
heap_unclassified = { | |
"heap-unclassified": 234322 | |
} | |
max_js = { | |
"max-js": 23423423 | |
} | |
max_images = { | |
"max-images": 121212 | |
} | |
def create_suite(name, data): | |
suite = { | |
"name": name, | |
"subtests": [], | |
"lowerIsBetter": True | |
} | |
for k,v in data.iteritems(): | |
suite['subtests'].append({ "name": k, "value": v, "lowerIsBetter": True, "units": "bytes" }); | |
return suite | |
PERF_BLOB = { | |
"framework": { "name": "awsy" }, | |
"suites": [] | |
} | |
PERF_BLOB['suites'].append(create_suite("RSS", rss_results)) | |
PERF_BLOB['suites'].append(create_suite("explicit", explicit_results)) | |
PERF_BLOB['suites'].append(create_suite("heap-unclassified", heap_unclassified)) | |
PERF_BLOB['suites'].append(create_suite("max-js", max_js)) | |
PERF_BLOB['suites'].append(create_suite("max-images", max_images)) | |
# Lets just make sure it's all good | |
with open("performance-artifact.json") as f: | |
schema = json.load(f) | |
jsonschema.validate(PERF_BLOB, schema) | |
tj.add_artifact('performance', 'json', PERF_BLOB) | |
########################################################################## | |
tjc.add(tj) | |
print tjc.to_json() | |
#client.post_collection('mozilla-inbound', tjc) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment