From c1513d04378d8d6cb8fefd00df670d35eb6cb94f Mon Sep 17 00:00:00 2001 From: Daniel Brown <ddb@star.sr.bham.ac.uk> Date: Wed, 24 Jul 2013 17:23:36 +0100 Subject: [PATCH] Added function to plot summed performance data --- bin/parse.kat | 2 +- bin/test_parser.py | 13 ++++++------- pykat/finesse.py | 26 +++++++++++++++++++++++--- pykat/profiling.py | 26 ++++++++++++++++++++++++++ setup.py | 2 +- 5 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 pykat/profiling.py diff --git a/bin/parse.kat b/bin/parse.kat index 84fdb87..8b779fb 100644 --- a/bin/parse.kat +++ b/bin/parse.kat @@ -6,4 +6,4 @@ m m2 0.5 0.5 0 n4 dump pd PD1 n2 -xaxis m1 phi lin 0 360 360 +xaxis m1 phi lin 0 360 10000 diff --git a/bin/test_parser.py b/bin/test_parser.py index 5cae9e5..ad51e26 100644 --- a/bin/test_parser.py +++ b/bin/test_parser.py @@ -2,18 +2,17 @@ import sys sys.path.append("../") from pykat import finesse +import pykat.profiling import numpy as np import pylab as pl kat = finesse.kat() -kat.load("parse.kat") +#kat.load("D:\\finesse\\test\\kat_test\\physics\\mirror_astig_tilt_all_BH.kat") +kat.load('parse.kat') +kat.getPerformanceData = True -run = kat.run(printout=0,printerr=0) +[run, perfdata] = kat.run(printout=0,printerr=0) -pl.figure() +pykat.profiling.plotReducedPerformanceData(perfdata) -pl.plot(run.x,run.y) -pl.xlabel(run.xlabel) -pl.legend(run.ylabels) -pl.show() diff --git a/pykat/finesse.py b/pykat/finesse.py index 52b9a82..e6a1a15 100644 --- a/pykat/finesse.py +++ b/pykat/finesse.py @@ -89,6 +89,7 @@ class kat(object): self.__phase = None self.__maxtem = None self.__noxaxis = None + self.__time_code = None @property def maxtem(self): return self.__maxtem @@ -100,6 +101,11 @@ class kat(object): @phase.setter def phase(self,value): self.__phase = int(value) + @property + def getPerformanceData(self): return self.__time_code + @getPerformanceData.setter + def getPerformanceData(self,value): self.__time_code = bool(value) + @property def noxaxis(self): return self.__noxaxis @noxaxis.setter @@ -147,7 +153,12 @@ class kat(object): katfile.writelines(r.katScript) katfile.flush() - kat_exec = "{0} {1}".format(kat_exec, katfile.name) + flags = "" + + if self.__time_code: + flags = flags + " --perf-timing " + + kat_exec = "{0} {1} {2}".format(kat_exec, flags, katfile.name) p=subprocess.Popen(kat_exec, stdout=subprocess.PIPE, @@ -180,7 +191,6 @@ class kat(object): r.ylabels = hdr[1:] if save_output: - newoutfile = "{0}.out".format(base) cwd = os.path.os.getcwd() @@ -209,8 +219,18 @@ class kat(object): katfile.close() + perfData = [] - return r + if self.__time_code: + perffile = open(root[0] + ".perf",'r') + + for l in perffile.readlines(): + vals = l.strip().split(' ') + perfData.append((vals[0], float(vals[1]), float(vals[2]), float(vals[3]))) + + return [r, perfData] + else: + return r def add(self, obj) : diff --git a/pykat/profiling.py b/pykat/profiling.py new file mode 100644 index 0000000..d018f66 --- /dev/null +++ b/pykat/profiling.py @@ -0,0 +1,26 @@ +import numpy as np +import pylab as pl + +def plotReducedPerformanceData(perfdata, ordered=False): + labels = [] + times = [] + + for pd in perfdata: + if pd[0] in labels: + times[labels.index(pd[0])] += pd[3] + else: + labels.append(pd[0]) + times.append(pd[3]) + + if ordered: + times,labels = (list(t) for t in zip(*sorted(zip(times,labels)))) + + ind = np.arange(len(labels)) + + fig = pl.figure() + plt = fig.add_subplot(111) + plt.barh(ind, times, height=0.5, log=True, align='center') + pl.yticks(ind, labels) + pl.show() + + return labels, times \ No newline at end of file diff --git a/setup.py b/setup.py index 5d8d23f..6f9b1fa 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ from distutils.core import setup setup( name='PyKat', - version='0.0.1', + version='0.0.2', author='Daniel Brown', author_email='ddb@star.sr.bham.ac.uk', packages=['pykat','pykat.gui','pykat.gui.resources'], -- GitLab