analysePickle.py
Go to the documentation of this file.
1 #!/bin/env python
2 print "run : --- Analyse production test pickle"
3 ########################### Imports
4 print "run : Importing modules"
5 import cPickle
6 import ROOT
7 import ParserArtEvents
8 ROOT.gROOT.SetBatch(1)
9 print "run : done"
10 ########################### Option parser
11 from optparse import OptionParser
12 parser = OptionParser()
13 parser.add_option("-p", "--pickle", help="input pickle file", action="store", type=str, dest="pickle", default=False)
14 parser.add_option("-o", "--output", help="output file name", action="store", type=str, dest="output", default="analyse_pickle.root")
15 parser.add_option("-v", "--verbose", help="turn on verbose mode", action="store_true", dest="verbose", default=False)
16 (options, args) = parser.parse_args()
17 if options.verbose:
18  print "run : --- Options"
19  print "run : pickle: ",options.pickle
20  print "run : output: ",options.output
21  print "run : verbose mode: ",options.verbose
22 assert (options.pickle), "No file provided to unpickle, specify one with -p MYFILE"
23 ########################### Unpickle
24 print "run : Opening pickle file %s"%options.pickle
25 chain = cPickle.load(open(options.pickle, "rb"))
26 ########################### Analyse
27 attributes = ["memory",
28  "memory_percent",
29  "cpu_percent",
30  "read_bytes",
31  "write_bytes",
32  "u_cpu_times",
33  "s_cpu_times",
34  "rss_memory",
35  "vms_memory",
36  "n_open_files",
37  "n_connections",
38 ]
39 histograms = {}
40 events = {}
41 queries = {}
42 parsing = {}
43 SLICE_IN_SECONDS = 0.1
44 SLICE_IN_MINUTES = SLICE_IN_SECONDS/60.
45 for tier in chain.tiers:
46  metric = tier.metric
47  if (tier.metric.run == False): continue
48  histograms[tier.short_name] = {}
49  d_attrs = {}
50  # recalculate some variables
51  metric.refresh()
52  # try and get event times
53  if tier.log != "":
54  art_events = ParserArtEvents.parseLines(tier.log,verbose=True)
55  print art_events
56  events[tier.short_name] = art_events.events
57  queries[tier.short_name] = art_events.queries
58  parsing[tier.short_name] = art_events.parsing
59  for attribute in attributes:
60  values = getattr(metric,attribute)
61  times = metric.sample_times
62 
63  hist = ROOT.TGraph(len(times))
64  hist.SetName("%s_%s"%(tier.short_name,attribute))
65  hist.SetTitle("%s_%s;time [s];%s"%(tier.short_name,attribute,attribute))
66 
67  for i, time in enumerate(times):
68  hist.SetPoint(i,time,values[i])
69 
70  histograms[tier.short_name][attribute] = hist
71 ########################### Draw histograms
72 import rootlogon
73 ROOT.gROOT.SetStyle("novaStyle")
74 ROOT.gROOT.ForceStyle()
75 canvas = ROOT.TCanvas("canvas","variable",700,600)
76 canvas.Clear()
77 ps = "AnalysePickle-Histograms.pdf"
78 canvas.Print(ps+"[")
79 for tier in chain.tiers:
80  metric = tier.metric
81  if (tier.metric.run == False): continue
82  for attribute in attributes:
83  canvas.Clear()
84  this_hist = histograms[tier.short_name][attribute]
85  this_hist.Draw()
86  this_events = events[tier.short_name]
87  this_queries = queries[tier.short_name]
88  this_parsing = parsing[tier.short_name]
89  #print this_events
90  lines = []
91  for event in this_events.keys():
92  t_0 = this_events[event]
93  line = ROOT.TLine(t_0,
94  this_hist.GetHistogram().GetMinimum(),
95  t_0,
96  this_hist.GetHistogram().GetMaximum())
97  line.SetLineColor(ROOT.kRed)
98  line.SetLineWidth(3)
99  #print line.GetX1(),line.GetY1(),line.GetX2(),line.GetY2()
100  lines.append(line)
101  for query in this_queries.keys():
102  t_0 = this_queries[query]
103  line = ROOT.TLine(t_0,
104  this_hist.GetHistogram().GetMinimum(),
105  t_0,
106  this_hist.GetHistogram().GetMaximum())
107  line.SetLineColor(ROOT.kMagenta+3)
108  line.SetLineWidth(3)
109  #print line.GetX1(),line.GetY1(),line.GetX2(),line.GetY2()
110  lines.append(line)
111  for parse in this_parsing.keys():
112  t_0 = this_parsing[parse]
113  line = ROOT.TLine(t_0,
114  this_hist.GetHistogram().GetMinimum(),
115  t_0,
116  this_hist.GetHistogram().GetMaximum())
117  line.SetLineColor(ROOT.kCyan+1)
118  line.SetLineStyle(2)
119  line.SetLineWidth(3)
120  #print line.GetX1(),line.GetY1(),line.GetX2(),line.GetY2()
121  lines.append(line)
122  for line in lines:
123  line.Draw("same")
124  canvas.Update()
125  canvas.Print(ps)
126 canvas.Print(ps+"]")
127 print "run : Saved histograms to: %s"%ps
128 ########################### Save output
129 if options.output:
130  print "run : Saving output to %s"%options.output
131  root_file = ROOT.TFile(options.output, "RECREATE")
132  for tier in chain.tiers:
133  if (tier.metric.run == False): continue
134  for attribute in attributes:
135  histograms[tier.short_name][attribute].Write()
136  root_file.Close()
137 ########################### Done
138 print "run : --- Done\n"
procfile open("FD_BRL_v0.txt")
def parseLines(lines, verbose=False)
Parse output file.
gm Write()