Beispiel #1
0
def profile(command, *args, **kwargs):

    if callable(command):
        cmd_str = "%s %s %s" % (command.__name__, str(args), str(kwargs))

    else:
        cmd_str = command

    print "profile: %s" % cmd_str

    if '_RADICAL_SYNAPSE_EMULATED' in os.environ:
        cmd_str = os.environ.get('_RADICAL_SYNAPSE_EMULATEE', cmd_str)
        print 'using emulated command name: %s' % cmd_str

    info = {'cmd': cmd_str}

    # start stress, get it spinning for one min to get a confirmed load
    # measurement, then run our own load, then kill stress.
    if LOAD > 0:
        rsu.logger.info("creating system load %s" % LOAD)
        os.popen("killall -9 stress 2>&1 > /dev/null")
        os.popen('stress --cpu %s &' % LOAD)
        time.sleep(60)

    load_1 = float(os.popen(LOAD_CMD).read())
    start = rsu.timestamp()

    os.environ['_RADICAL_SYNAPSE_PROFILED'] = 'TRUE'

    # run the profiled function/command in a separate process
    if callable(command):

        proc = mp.Process(target=command, args=args, kwargs=kwargs)
        proc.start()

    else:

        proc = sp.Popen(command.split(), stdout=sp.PIPE, stderr=sp.STDOUT)

    watch_mode = os.environ.get('RADICAL_SYNAPSE_WATCHMODE', 'full').lower()
    watchers = list()

    if watch_mode == 'full':
        watchers.append(rsw.WatcherCPU(proc.pid))
        watchers.append(rsw.WatcherSto(proc.pid))
        watchers.append(rsw.WatcherMem(proc.pid))

    # watchmode 'basic'
    watchers.append(rsw.WatcherSys(proc.pid))

    if callable(command):

        proc.join()
        out = ""
        ret = None

    else:
        out = proc.communicate()[0]
        ret = proc.returncode

    stop = rsu.timestamp()

    info['time'] = dict()
    info['time']['start'] = rsu.time_zero()
    info['time']['real'] = stop - start

    for watcher in reversed(watchers):
        watcher.stop()
        watcher.join()
        ru.dict_merge(info, watcher.get_data())

    # allow watchers to finalize some stuff, now having data from other watchers
    # available
    for watcher in reversed(watchers):
        watcher.finalize(info)

    time_2 = rsu.timestamp()
    load_2 = float(os.popen(LOAD_CMD).read())
    info['cpu']['load'] = max(load_1, load_2)
    rsu.logger.info("system load %s: %s" % (LOAD, info['cpu']['load']))

    if LOAD > 0:
        rsu.logger.info("stopping system load")
        os.popen("killall -9 stress 2>&1 > /dev/null")
        rsu.logger.info("stopped  system load")

    return info, ret, out
def execute (command, *args, **kwargs):

    if callable (command):
        cmd_str = "%s %s %s" % (command.__name__, str (args), str(kwargs))

    else:
        cmd_str = command


    print "execute: %s" % cmd_str

    info = {'cmd' : cmd_str}


    # start stress, get it spinning for one min to get a confirmed load
    # measurement, then run our own load, then kill stress.
    if  LOAD > 0:
        rsu.logger.info ("creating system load %s" % LOAD)
        os.popen ("killall -9 stress 2>&1 > /dev/null")
        os.popen ('stress --cpu %s &' % LOAD)
        time.sleep (60)

    load_1 = float(os.popen (LOAD_CMD).read())
    start  = rsu.timestamp()

    os.environ['_RADICAL_SYNAPSE_PROFILED'] = 'TRUE'

    # run the function/command in a separate process
    if callable (command):

        proc = mp.Process (target = command,
                           args   = args,
                           kwargs = kwargs)
        proc.start ()

    else:

        proc = sp.Popen (command.split(),
                        stdout = sp.PIPE,
                        stderr = sp.STDOUT)

    if callable (command):

        proc.join()
        out = ""
        ret = None

    else:
        out = proc.communicate()[0]
        ret = proc.returncode

    stop   = rsu.timestamp()
    load_2 = float(os.popen (LOAD_CMD).read())

    info['time'] = dict()
    info['time']['start'] = rsu.time_zero()
    info['time']['real']  = stop-start

    info['cpu']  = dict()
    info['cpu']['load']   = max(load_1, load_2)
   
    if  LOAD > 0:
        rsu.logger.info ("stopping system load")
        os.popen ("killall -9 stress 2>&1 > /dev/null")
        rsu.logger.info ("stopped  system load")

    return info, ret, out
Beispiel #3
0
def execute(command, *args, **kwargs):

    if callable(command):
        cmd_str = "%s %s %s" % (command.__name__, str(args), str(kwargs))

    else:
        cmd_str = command

    print "execute: %s" % cmd_str

    info = {'cmd': cmd_str}

    # start stress, get it spinning for one min to get a confirmed load
    # measurement, then run our own load, then kill stress.
    if LOAD > 0:
        rsu.logger.info("creating system load %s" % LOAD)
        os.popen("killall -9 stress 2>&1 > /dev/null")
        os.popen('stress --cpu %s &' % LOAD)
        time.sleep(60)

    load_1 = float(os.popen(LOAD_CMD).read())
    start = rsu.timestamp()

    os.environ['_RADICAL_SYNAPSE_PROFILED'] = 'TRUE'

    # run the function/command in a separate process
    if callable(command):

        proc = mp.Process(target=command, args=args, kwargs=kwargs)
        proc.start()

    else:

        proc = sp.Popen(command.split(), stdout=sp.PIPE, stderr=sp.STDOUT)

    if callable(command):

        proc.join()
        out = ""
        ret = None

    else:
        out = proc.communicate()[0]
        ret = proc.returncode

    stop = rsu.timestamp()
    load_2 = float(os.popen(LOAD_CMD).read())

    info['time'] = dict()
    info['time']['start'] = rsu.time_zero()
    info['time']['real'] = stop - start

    info['cpu'] = dict()
    info['cpu']['load'] = max(load_1, load_2)

    if LOAD > 0:
        rsu.logger.info("stopping system load")
        os.popen("killall -9 stress 2>&1 > /dev/null")
        rsu.logger.info("stopped  system load")

    return info, ret, out
def profile (command, *args, **kwargs) :

    if callable (command):
        cmd_str = "%s %s %s" % (command.__name__, str (args), str(kwargs))

    else:
        cmd_str = command


    print "profile: %s" % cmd_str

    if '_RADICAL_SYNAPSE_EMULATED' in os.environ:
        cmd_str = os.environ.get ('_RADICAL_SYNAPSE_EMULATEE', cmd_str)
        print 'using emulated command name: %s' % cmd_str

    info = {'cmd' : cmd_str}

    # start stress, get it spinning for one min to get a confirmed load
    # measurement, then run our own load, then kill stress.
    if  LOAD > 0:
        rsu.logger.info ("creating system load %s" % LOAD)
        os.popen ("killall -9 stress 2>&1 > /dev/null")
        os.popen ('stress --cpu %s &' % LOAD)
        time.sleep (60)

    load_1 = float(os.popen (LOAD_CMD).read())
    start  = rsu.timestamp()

    os.environ['_RADICAL_SYNAPSE_PROFILED'] = 'TRUE'

    # run the profiled function/command in a separate process
    if callable (command):

        proc = mp.Process (target = command,
                           args   = args,
                           kwargs = kwargs)
        proc.start ()

    else:

        proc = sp.Popen (command.split(),
                        stdout = sp.PIPE,
                        stderr = sp.STDOUT)

    watch_mode = os.environ.get('RADICAL_SYNAPSE_WATCHMODE', 'full').lower()
    watchers   = list()

    if watch_mode == 'full':
        watchers.append (rsw.WatcherCPU (proc.pid))
        watchers.append (rsw.WatcherSto (proc.pid))
        watchers.append (rsw.WatcherMem (proc.pid))

    # watchmode 'basic'
    watchers.append (rsw.WatcherSys (proc.pid))


    if callable (command):

        proc.join()
        out = ""
        ret = None

    else:
        out = proc.communicate()[0]
        ret = proc.returncode

    stop = rsu.timestamp()

    info['time'] = dict()
    info['time']['start'] = rsu.time_zero()
    info['time']['real']  = stop-start

    for watcher in reversed(watchers):
        watcher.stop ()
        watcher.join ()
        ru.dict_merge (info, watcher.get_data())

    # allow watchers to finalize some stuff, now having data from other watchers
    # available
    for watcher in reversed(watchers):
        watcher.finalize(info)

    time_2 = rsu.timestamp()
    load_2 = float(os.popen (LOAD_CMD).read())
    info['cpu']['load'] = max(load_1, load_2)
    rsu.logger.info ("system load %s: %s" % (LOAD, info['cpu']['load']))
   
    if  LOAD > 0:
        rsu.logger.info ("stopping system load")
        os.popen ("killall -9 stress 2>&1 > /dev/null")
        rsu.logger.info ("stopped  system load")

    return info, ret, out