def synaptic(load_compute, load_memory, load_input, load_output):

    start = time.time()

    # create containers for different system workload types
    atoms = dict()
    atoms['c'] = rsa.Compute()
    atoms['m'] = rsa.Memory()
    atoms['i'] = rsa.Storage()
    atoms['o'] = rsa.Storage()

    # the atoms below are executed concurrently (in their own threads)
    atoms['c'].run(info={'n': load_compute})
    atoms['m'].run(info={'n': load_memory})
    atoms['i'].run(info={'size': load_input, 'mode': 'r', 'tgt': '/tmp/src'})
    atoms['o'].run(info={'size': load_output, 'mode': 'w'})

    # wait for all atom threads to be done
    info_c = atoms['c'].wait()
    info_m = atoms['m'].wait()
    info_i = atoms['i'].wait()
    info_o = atoms['o'].wait()

    for info in [info_c, info_m, info_i, info_o]:
        for line in info['out']:
            l = ru.ReString(line)
            if l // '^(ru.\S+)\s+:\s+(\S+)$':
                info[l.get()[0]] = l.get()[1]

    print "------------------------------"
    pprint.pprint(info_i)
    print "------------------------------"
    pprint.pprint(info_o)
    print "------------------------------"
Exemplo n.º 2
0
def synaptic (x, y, z, load_compute, load_memory, load_storage) :

    load_instances = 1

  # load_id = 'EMU.%04d' % x
  # print 'synaptic: %s %s %s' % (x, y, z)
  # print      '%8s: %s %s %s' % (load_id, load_compute, load_memory, load_storage)

    start = time.time()

    # create containers for different system workload types
    atoms = dict()
    atoms['c'] = rsa.Compute ()
    atoms['m'] = rsa.Memory  ()
    atoms['s'] = rsa.Storage ()

    # the atoms below are executed concurrently (in their own threads)
    atoms['c'].run (info={'n'   : load_compute})
    atoms['m'].run (info={'n'   : load_memory})
    atoms['s'].run (info={'n'   : load_storage,
                          'tgt' : '%(tmp)s/synapse_storage.tmp.%(pid)s'})

    # wait for all atom threads to be done
    info_c = atoms['c'].wait ()
    info_m = atoms['m'].wait ()
    info_s = atoms['s'].wait ()

    for info in [info_c, info_m, info_s] :
        for line in info['out'] :
            l = ru.ReString (line)
            if  l // '^(ru.\S+)\s+:\s+(\S+)$' :
                info[l.get()[0]] = l.get()[1]

    return {'c':info_c, 'm':info_m, 's':info_s}
Exemplo n.º 3
0
def test_re_string():
    """
    Test regex matching
    """

    txt = ru.ReString("The quick brown fox jumps over the lazy dog")
    tgt_l = [' qu', 'ick brown fox jumps']
    tgt_d = {'x': 'ick brown fox jumps'}

    with txt // '(\s.u)(?P<x>.*?j\S+)' as res:
        assert (res)
        assert (len(res) == len(tgt_l))
        assert (res == tgt_l), "%s != %s" % (str(res), str(tgt_l))
        assert (res[0] == tgt_l[0])
        assert (res[1] == tgt_l[1])
        assert (res['x'] == tgt_d['x'])
        assert (res.x == tgt_d['x'])
        for i, r in enumerate(res):
            assert (r == tgt_l[i])

    if txt // '(rabbit)':
        assert (False)

    elif txt // '((?:\s).{12,15}?(\S+))':  # support for full Python regex slang
        assert (True)

    else:
        assert (False)
Exemplo n.º 4
0
def human_to_number(h, prefix=PREFIX_BIN):

    rs = ru.ReString(h)

    with rs // '^\s*([\d\.]+)\s*(\D+)\s*$' as match:
        if not match:
            # print 'incorrect format: %s' % h
            return float(h)

        p = match[1].upper()[0]

        if not p in prefix:
            # print 'unknown prefix: %s' % h
            return float(h)

        return float(match[0]) * prefix[p]
Exemplo n.º 5
0
def time_to_seconds(t):

    rs = ru.ReString(t)

    with rs // '^(?:\s*(\d+)\s*[:])+\s*([\d\.]+)\s*$' as match:

        if not match:
            return t

        seconds = 0
        if len(match) == 1: seconds = float(match[0])
        if len(match) == 2: seconds = float(match[0]) * 60 + float(match[1])
        if len(match) == 3:
            seconds = float(match[0]) * 60 * 60 + float(match[1]) * 60 + float(
                match[2])

        return seconds
    def _parse_perf_sample(self, perf_out):

        if isinstance(perf_out, basestring):
            perf_out = perf_out.split('\n')

        # prepare to dig data from perf output lines
        perf_keys = {  # "task-clock"              : "utilization",
            # "context-switches"        : "context_switches",
            # "cpu-migrations"          : "cpu_migrations",
            "instructions": "ops",
            # "page-faults"             : "page_faults",
            "branches": "branches",
            "branch-misses": "branch_misses",
            "cycles": "cycles",
            "stalled-cycles-frontend": "cycles_stalled_front",
            "stalled-cycles-backend": "cycles_stalled_back"
        }
        ored_keys = '|'.join(perf_keys.keys()).replace(' ', '\s')
        perf_patstr = r"""
           ^(?P<lead>\s+)                # lead-in
            (?P<time>[\d\.,]+)           # timestamp
            \s+                          # skip
            (?P<val>[\d\.,]+)            # value (ignore warnings)
            \s+                          # skip
            (?P<key>%s)                  # key
            \s*                          # skip
            (\[(?P<perc>[\d\.]+)%%\])?   # percentage (optional)
            \s*                          # skip
            (?P<rest>.*)$                # lead-out
        """ % ored_keys
        perf_pat = re.compile(perf_patstr, re.VERBOSE)

        sample = dict()
        last_ts = None
        ts = None

        # and go
        for line in perf_out:

            l = ru.ReString(line)

            # print "line: %s" % line

            while l // (perf_pat):

                ts = float(l.get('time'))
                key = perf_keys[l.get('key')]
                val = l.get('val')
                perc = l.get('perc')

                if not perc:
                    perc = '-1.0'

            # print " ->  %s/%s  %s  %s  %s" % (ts, last_ts, key, val, perc)

                if ts != last_ts:
                    if last_ts != None:
                        # print "append %s" % last_ts
                        self._data['cpu']['sequence'].append([last_ts, sample])
                        sample = dict()
                    last_ts = ts

                sample[key] = float(val.replace(',', ''))
                if perc != None:
                    sample['%s_perc' % key] = float(perc.replace(',', ''))

            # print "rest: %s" % l.get ('rest')
                l = ru.ReString(l.get('rest'))

        if ts and sample:
            # print "append %s" % ts
            self._data['cpu']['sequence'].append([ts, sample])
    def _parse_perf_total(self, perf_out):

        if isinstance(perf_out, basestring):
            perf_out = perf_out.split('\n')

        # prepare to dig data from perf output lines
        perf_keys = {  # "CPUs utilized"           : "utilization",
            "instructions": "ops",
            "branches": "branches",
            "branch-misses": "branch_misses",
            "cycles": "cycles",
            "stalled-cycles-frontend": "cycles_stalled_front",
            "stalled-cycles-backend": "cycles_stalled_back",
            "frontend cycles idle": "cycles_idle_front",
            "backend  cycles idle": "cycles_idle_back",
            "insns per cycle": "ops_per_cycle"
        }
        ored_keys = '|'.join(perf_keys.keys()).replace(' ', '\s')
        perf_patstr = r"""
            ^(?P<lead>.*?\s+)            # lead-in
            (?P<val>[\d\.,]+)%%?         # value
            \s+                          # skip
            (?P<key>%s)                  # key
            \s*                          # skip
            (\[(?P<perc>[\d\.]+)%%\])?   # percentage (optional)
            \s*                          # skip
            (?P<rest>.*)$                # lead-out
        """ % ored_keys
        perf_pat = re.compile(perf_patstr, re.VERBOSE)

        # and go
        for line in perf_out:

            l = ru.ReString(line)

            # print "line: %s" % line

            while l // (perf_pat):

                key = perf_keys[l.get('key')]
                val = l.get('val')
                perc = l.get('perc', '-1.0')

                if not perc:
                    perc = '-1.0'

            # print " ->  %s  %s  %s" % (key, val, perc)

                self._data['cpu']['%s' % key] = float(val.replace(',', ''))
                self._data['cpu']['%s_perc' % key] = float(
                    perc.replace(',', ''))

                # print "rest: %s" % l.get ('rest')
                l = ru.ReString(l.get('rest'))

        # must haves
        if not self._data['cpu'].get('ops'): self._data['cpu']['ops'] = 1
        if not self._data['cpu'].get('cycles_idle_front'):
            self._data['cpu']['cycles_idle_front'] = 0
        if not self._data['cpu'].get('cycles_idle_back'):
            self._data['cpu']['cycles_idle_back'] = 0
        if not self._data['cpu'].get('cycles_stalled_front'):
            self._data['cpu']['cycles_stalled_front'] = 0
        if not self._data['cpu'].get('cycles_stalled_back'):
            self._data['cpu']['cycles_stalled_back'] = 0

        self._data['cpu']['efficiency']  = self._data['cpu']['ops']                       \
                              / ( self._data['cpu']['ops']                   \
                                + self._data['cpu']['cycles_stalled_front']  \
                                + self._data['cpu']['cycles_stalled_back']   \
                                )
                    iter_1_mean_sys,
                    iter_1_std_sys,
                    iter_1_mean_mem,
                    iter_1_std_mem,
                    iter_1_mean_io,
                    iter_1_std_io
                   )
        print stat


# ------------------------------------------------------------------------------
#
#
cfg_list = list()

if not len(sys.argv) > 1:
    print "\n\tusage: %s <cfg_file> \n\n" % sys.argv[0]
    sys.exit(-1)

with open(sys.argv[1]) as fin:
    lines = fin.readlines()

for line in lines:
    line = line.replace('\n', '')
    re = ru.ReString(line)
    if re // r'(MEAN_PRO)':
        print line
        cfg_list.append(line.split())

main(cfg_list)