forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-json-performance-charts
executable file
·159 lines (126 loc) · 4.44 KB
/
generate-json-performance-charts
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#! /usr/bin/env python
from optparse import OptionParser
from os import listdir
from os import path
import re
import json
#------------------------------------------------------------------------------------------------------------
# This script reads a list of the workflows, steps and parameters for which you want to see the graphs
# It generates a json file with the correct structure and links to each graph, this json file is used
# to create the visualization
#------------------------------------------------------------------------------------------------------------
def get_wfs_ordered(base_dir):
workflows={}
check=re.compile("^[0-9]+.")
for wf in listdir(base_dir):
if check.match(wf):
wf_number = float(re.sub('_.*$', '', wf))
workflows[wf_number]=wf
return [ workflows[wf_number] for wf_number in sorted(workflows.keys()) ]
def add_images_to_step(wf,step):
imgs = []
for img_name in listdir('%s/%s/%s' % (BASE_DIR,wf['wf_name'],step['step_name'])):
if (img_name in RESULT_FILE_NAMES ):
img = {}
img['name'] = img_name
img['url'] = '%s/%s/%s/%s' % (BASE_URL,wf['wf_name'],step['step_name'],img['name'])
imgs.append(img)
print img['name']
step['imgs'] = imgs
def add_steps_to_wf(wf):
steps = []
for step_name in sorted(listdir('%s/%s' % (BASE_DIR,wf['wf_name']))):
if path.isdir('%s/%s/%s'% (BASE_DIR,wf['wf_name'],step_name) ):
step = {}
step['step_name'] = step_name
add_images_to_step(wf,step)
steps.append(step)
print step_name
wf['steps'] = steps
def get_workflows():
workflows = []
for wf_name in get_wfs_ordered(BASE_DIR):
if path.isdir('%s/%s/'% (BASE_DIR,wf_name) ) and not 'bootstrap' in wf_name:
print 'Adding %s' % wf_name
wf = {}
wf['wf_name'] = wf_name
add_steps_to_wf(wf)
workflows.append(wf)
print
return workflows
def print_workflows(wfs):
for wf in wfs:
print wf['wf_name']
for step in wf['steps']:
print '\t %s' % step['step_name']
for img in step['imgs']:
print img
def add_workflow(results,wf_name):
for wf in results['wfs']:
if wf['wf_name'] == wf_name:
return wf
new_wf = {}
new_wf['wf_name'] = wf_name
results['wfs'].append(new_wf)
return new_wf
def add_step(workflow,step_name):
if not workflow.get('steps'):
workflow['steps'] = []
for step in workflow['steps']:
if step['step_name'] == step_name:
return step
new_step = {}
new_step['step_name'] = step_name
workflow['steps'].append(new_step)
return new_step
def add_param(step,param_name):
if not step.get('imgs'):
step['imgs'] = []
for p in step['imgs']:
if p['name'] == param_name:
return p
new_param = {}
new_param['name'] = param_name
step['imgs'].append(new_param)
return new_param
def add_url_to_param(workflow,step,param):
step_number = step['step_name'].split('_')[0]
url = BASE_URL.replace('WORKFLOW',workflow['wf_name']).replace('STEP',step_number).replace('PARAM',param['name'])
url = url.replace('+','%2B')
print url
param['url'] = url
#-----------------------------------------------------------------------------------
#---- Parser Options
#-----------------------------------------------------------------------------------
parser = OptionParser(usage="usage: %prog PLOTS_LIST \n PLOTS_LIST list of plots that you want to visualize")
(options, args) = parser.parse_args()
#-----------------------------------------------------------------------------------
#---- Start
#-----------------------------------------------------------------------------------
if (len(args)<1):
print 'you need to specify a list of plots'
parser.print_help()
exit()
WF_LIST = args[0]
GRAPH_PARAMS = '&from=-15days&fontBold=true&fontSize=12&lineWidth=5&title=PARAM&yMin=0'
BASE_URL = 'https://cmsgraph.cern.ch/render?target=IBRelVals.slc6_amd64_gcc481.CMSSW_7_1_X.WORKFLOW.STEP.PARAM&height=800&width=800%s'%GRAPH_PARAMS
result = {}
lines = open(WF_LIST, "r").readlines()
result['wfs'] = []
for l in lines:
if l.startswith("#"):
continue
else:
l = l.replace('\n','')
parts = l.split(' ')
wf_name = parts[0]
step_name = parts[1]
param_name = parts[2]
workflow = add_workflow(result,wf_name)
step = add_step(workflow,step_name)
param = add_param(step,param_name)
add_url_to_param(workflow,step,param)
print result
out_json = open("plots_summary.json", "w")
json.dump(result,out_json,indent=4)
out_json.close()