Beispiel #1
0
def parse_fn(fn):
    if(not isfile(fn)):
        msg = "No trace found at filename %s" % (fn)
        raise NoTraceException(msg)
    contents = load_file(fn)
    lines = contents.splitlines()
    accum = list()
    for line in lines:
        ep = split_line(line)
        if(ep == None):
            continue
        accum.append(tuple(ep))
    return accum
Beispiel #2
0
 def stop(self, name, *args, **kargs):
     rootdir = kargs.get("trace_dir")
     pidfile = joinpths(rootdir, name + ".pid")
     stderr = joinpths(rootdir, name + ".stderr")
     stdout = joinpths(rootdir, name + ".stdout")
     tfname = Trace.trace_fn(rootdir, name)
     if(isfile(pidfile) and isfile(tfname)):
         pid = int(load_file(pidfile).strip())
         killed = False
         lastmsg = ""
         attempts = 1
         for attempt in range(0, MAX_KILL_TRY):
             try:
                 os.kill(pid, signal.SIGKILL)
                 attempts += 1
             except OSError as (ec, msg):
                 if(ec == errno.ESRCH):
                     killed = True
                     break
                 else:
                     lastmsg = msg
                     time.sleep(SLEEP_TIME)
         #trash the files
         if(killed):
             LOG.info("Killed pid %s in %s attempts" % (str(pid), str(attempts)))
             LOG.info("Removing pid file %s" % (pidfile))
             unlink(pidfile)
             LOG.info("Removing stderr file %s" % (stderr))
             unlink(stderr)
             LOG.info("Removing stdout file %s" % (stdout))
             unlink(stdout)
             LOG.info("Removing %s trace file %s" % (name, tfname))
             unlink(tfname)
         else:
             msg = "Could not stop program named %s after %s attempts - [%s]" % (name, MAX_KILL_TRY, lastmsg)
             raise StopException(msg)