From 2157451af7ca8ff89e9d40d253391755bd777210 Mon Sep 17 00:00:00 2001 From: William Cohen Date: Thu, 3 Dec 2015 15:04:03 -0500 Subject: [PATCH] cpu time info --- TODO.txt | 1 - mrs_gp.py | 20 ++++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/TODO.txt b/TODO.txt index 7f3437e..2720cd7 100644 --- a/TODO.txt +++ b/TODO.txt @@ -10,7 +10,6 @@ the working version. TODO for mrs_gp.py: - test on processes with errors, .... - - os.times() - can this show children's time/CPU pct so I can see actual load? - server timeout, for security, in case I leave it running...? - add an 'abort task' method for server...? or maybe kill client thread? diff --git a/mrs_gp.py b/mrs_gp.py index 9aa3ebc..b18c81d 100644 --- a/mrs_gp.py +++ b/mrs_gp.py @@ -24,14 +24,10 @@ # just files in directories. This combines multi-threading and # multi-processing. # -# TODO: -# document --inputs -# test/eval on servers and with gp -# # Gotchas/bugs: # - threading doesn't work right in jython, and doesn't help # much in cpython. best interpreter is pypy, due to lack -# of GIL. TODO: confirm this for v4. +# of GIL. # - if you use /afs/ as file store the server seems to # leave some sort of lock file around which make deletion # impossible while the server is running @@ -60,6 +56,9 @@ class MRS(object): VERSION = "1.4.1" COPYRIGHT = '(c) William Cohen 2015' +#SAFE_PREFIX="" #disables the relative-path check +SAFE_PREFIX="./" #prepending to paths ensures that all paths are relative + ############################################################################## # # shared "file system" @@ -241,6 +240,11 @@ def report(self,includeLogs=True): buf.extend([' %-7s summary: %d/%d finished/started %s min/max time %.3f/%.3f' % \ (k,self.numFinished[k],self.numStarted[k],progressBar,minTime,maxTime)]) now = time.time() + (user,system,childuser,childsystem,unused)=os.times() + total = sum((user,system,childuser,childsystem)) + elapsed = now - self.startTime['__top level task'] + buf.extend([' CPU time: user/system main: %.1fs/%.1fs child: %.1fs/%.1fs elapsed: %.1f CPU%% %.1f' \ + % (user,system,childuser,childsystem,elapsed,100*total/elapsed)]) for k in sorted(self.startTime.keys()): if k in self.endTime: line = ' %-40s: finished in %.3f sec' % (k,self.endTime[k]-self.startTime[k]) @@ -583,7 +587,7 @@ def __init__(self,outdir,outfile): self.outdir = outdir self.outfile = outfile else: - self.fp = open(os.path.join("./"+outdir,outfile),'w') + self.fp = open(os.path.join(SAFE_PREFIX+outdir,outfile),'w') def collect(self,str): if self.gpfs: global FS @@ -732,7 +736,7 @@ def getInput(indir,f): else: inputString = cStringIO.StringIO() k = 0 - for line in open("./"+os.path.join(indir,f)): + for line in open(SAFE_PREFIX+os.path.join(indir,f)): inputString.write(line) k += 1 return inputString.getvalue() @@ -914,7 +918,7 @@ def runServer(): httpd.handle_request() logging.info(startMsg + ' has been shut down') -# client +# client, for submitting command-line jobs to the server import httplib