-
Notifications
You must be signed in to change notification settings - Fork 0
/
profiling-plot.py
executable file
·174 lines (148 loc) · 5.65 KB
/
profiling-plot.py
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/env dls-python
import os, sys
from pkg_resources import require
require("matplotlib")
require("numpy")
require("cothread")
import numpy
from cothread.catools import *
from pylab import *
import h5py
#TSNAME="/entry/instrument/performance/timestamp"
TSNAME="/profiling"
DSETNAME="/entry/detector/data"
# [proc, field, step]
def smooth(x,window_len=11,window='hanning'):
"""smooth the data using a window with requested size.
This method is based on the convolution of a scaled window with the signal.
The signal is prepared by introducing reflected copies of the signal
(with the window size) in both ends so that transient parts are minimized
in the begining and end part of the output signal.
This is stolen from a SciPy cookbook recipe: http://wiki.scipy.org/Cookbook/SignalSmooth
"""
if x.ndim != 1:
raise ValueError, "smooth only accepts 1 dimension arrays."
if x.size < window_len:
raise ValueError, "Input vector needs to be bigger than window size."
if window_len<3:
return x
if not window in ['flat', 'hanning', 'hamming', 'bartlett', 'blackman']:
raise ValueError, "Window is on of 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'"
s=numpy.r_[x[window_len-1:0:-1],x,x[-1:-window_len:-1]]
if window == 'flat': #moving average
w=numpy.ones(window_len,'d')
else:
w=eval('numpy.'+window+'(window_len)')
y=numpy.convolve(w/w.sum(),s,mode='valid')
return y
# Indeices to the /profiling dataset columns
TIMESTAMP = 0
DT_TIMESTAMP = 1
WRITETIME = 2
DT_TIME_RATE = 3
WRITETIME_RATE = 4
def timestamps_xy(filename, performance, column=WRITETIME):
plots = [] # A list of plots in the form [x,y1, x,y2, x,y3 ... ]
x = arange(len(performance[0,0,1:]))
processes = range(len(performance[:,0,0]))
for proc in processes:
y = performance[proc,column,1:]
plots += [x,y]
return (["process%s"% str(proc) for proc in processes], plots)
def timestamps(filename, performance, column=DT_TIMESTAMP):
plots = [] # A list of plots in the form [x,y1, x,y2, x,y3 ... ]
processes = range(len(performance[:,0,0]))
for proc in processes:
y = performance[proc,column,1:]
plots += [y]
return (["process%s"% str(proc) for proc in processes], plots)
def main():
if len(sys.argv) < 2:
print "No input file specified. Attempting to use caget to get latest file from Excalibur"
#sys.exit(-1)
path=caget("BL13J-EA-EXCBR-01:CONFIG:PHDF:FilePath_RBV", datatype=DBR_CHAR_STR)
name=caget("BL13J-EA-EXCBR-01:CONFIG:PHDF:FileName_RBV", datatype=DBR_CHAR_STR)
number=caget("BL13J-EA-EXCBR-01:CONFIG:PHDF:FileNumber")
templ=caget("BL13J-EA-EXCBR-01:CONFIG:PHDF:FileTemplate_RBV", datatype=DBR_CHAR_STR)
fname = templ%(path,name,number)
else:
fname = sys.argv[1]
print "Opening file: %s" % str(fname)
hdffile = h5py.File(fname, 'r')
performance = hdffile[TSNAME]
dataset = hdffile[DSETNAME]
print "dataset dims: ", dataset.shape
framesize = dataset.shape[1] * dataset.shape[2] * 2.0 / (1024. * 1024.)
process_framesize = framesize/len(performance[:,0,0])
last_timestamps = performance[:, 0, -1]
print "Overall avg datarate: ", framesize * dataset.shape[0] / max(last_timestamps)
figure(1)
title(fname)
### First plot is the period time ####
#subplot(211)
#result = timestamps_xy( fname, performance )
# now for the plotting
#plotArgs = result[1]
#plot( *plotArgs, linestyle='None', marker='.' )
#legend( result[0], shadow = True, loc = (0.1, 0.5) )
#for l in gca().get_legend().get_texts():
# setp(l, fontsize = 12)
#ylabel('period time [s]')
#xlabel('frame')
#hold(False)
#grid(True)
### Second plot is the avg datarate based on period time ####
#subplot(212)
#result = timestamps_xy( fname, performance, column=DT_TIME_RATE )
#plotArgs = result[1]
#plot( *plotArgs )
#ylabel('data rate [MB/s]')
#xlabel('frame')
#hold(False)
#grid(True)
#### Second window figure #####
#figure(2)
# First plot is the smoothed period time.
# smoothing for 2s using a hanning window.
#subplot(211)
legends, result = timestamps( fname, performance, column=DT_TIMESTAMP )
plotArgs = []
smoothed_periods = []
frequency = 1/result[0].mean()
window_time = 20.0
window_length = window_time * frequency
print "Smoothing window lenght: %.1fs, %i frames "%(window_time, window_length)
for period_time in result:
print "Mean: ", period_time.mean(), "s ", process_framesize / period_time.mean(), "MB/s"
niceline = smooth(period_time, window='hanning', window_len=window_length)
plotArgs += [arange(len(niceline))]
plotArgs += [ niceline ]
smoothed_periods += [niceline]
#plot( *plotArgs )
#legend( legends, shadow = True )
#for l in gca().get_legend().get_texts():
# setp(l, fontsize = 12)
#ylabel('period time [s]')
#xlabel('frame')
#hold(False)
#grid(True)
# Second plot is datarate using the smoothed period time.
#subplot(212)
plotArgs=[]
for smoothed_period in smoothed_periods:
plotArgs += [arange(len(smoothed_period))]
plotArgs += [ process_framesize / smoothed_period ]
plot( *plotArgs )
legend( legends, shadow = True )
for l in gca().get_legend().get_texts():
setp(l, fontsize = 12)
ylabel('period time [s]')
ylabel('data rate [MB/s]')
xlabel('frame')
hold(False)
grid(True)
hdffile.close()
# finally show (and block)
show()
if __name__=="__main__":
main()