示例#1
0
    def psmem_cmd(fast, cgroup):
        """Reports memory utilization details for given container."""
        if cgroup:
            pids = cgutils.pids_in_cgroup('memory', cgroup)
        else:
            pids = [int(pid) for pid in os.listdir('/proc') if pid.isdigit()]

        use_pss = not fast
        memusage = psmem.get_memory_usage(pids, use_pss=use_pss)

        columns = (['name', 'count', 'private', 'shared', 'total'])
        table = prettytable.PrettyTable(columns)
        for column in columns:
            table.align[column] = 'l'

        table.set_style(prettytable.PLAIN_COLUMNS)
        table.left_padding_width = 0
        table.right_padding_width = 2

        readable = lambda value: utils.bytes_to_readable(value, power='B')
        for proc, info in sorted(memusage.iteritems()):
            table.add_row([proc, info['count']] + [
                readable(info[col]) for col in ['private', 'shared', 'total']
            ])

        total = sum([info['total'] for info in memusage.values()])
        table.add_row(['', '', '', '', ''])
        table.add_row(['Total:', '', '', '', readable(total)])
        print table

        memusage, softmem, hardmem = cgutils.cgrp_meminfo(cgroup)
        print ''
        print 'memory.usage     : ', readable(memusage)
        print 'memory.softlimit : ', readable(softmem)
        print 'memory.hardlimit : ', readable(hardmem)
示例#2
0
def read_psmem_stats(appname, allpids):
    """Reads per-proc memory details stats."""
    cgrp = os.path.join('treadmill/apps', appname)
    group_pids = set(cgutils.pids_in_cgroup('memory', cgrp))

    # Intersection of all /proc pids (allpids) and pid in .../tasks will give
    # the set we are interested in.
    #
    # "tasks" contain thread pids that we want to filter out.
    meminfo = psmem.get_memory_usage(allpids & group_pids, use_pss=True)
    return meminfo
示例#3
0
    def psmem_cmd(fast, app, verbose, percent):
        """Reports memory utilization details for given container."""
        if app.find('#') == -1:
            raise click.BadParameter('Specify full instance name: xxx#nnn')
        app = app.replace('#', '-')

        cgroup = None
        apps = os.listdir('/sys/fs/cgroup/memory/treadmill/apps')
        for entry in apps:
            if app in entry:
                cgroup = os.path.join('/treadmill/apps', entry)
        if not cgroup:
            raise click.BadParameter('Could not find corresponding cgroup')

        pids = cgutils.pids_in_cgroup('memory', cgroup)

        use_pss = not fast
        memusage = psmem.get_memory_usage(pids, verbose, use_pss=use_pss)

        proc_columns = ([
            'ppid', 'name', 'threads', 'private', 'shared', 'total'
        ])
        proc_table = prettytable.PrettyTable(proc_columns)
        proc_table.align = 'l'

        proc_table.set_style(prettytable.PLAIN_COLUMNS)
        proc_table.left_padding_width = 0
        proc_table.right_padding_width = 2

        total = sum([info['total'] for info in memusage.values()])

        readable = lambda value: utils.bytes_to_readable(value, power='B')
        percentage = lambda value, total: "{:.1%}".format(value / total)
        cols = proc_columns[3:]
        for proc, info in sorted(memusage.items()):
            row_base = [proc, info['name'], info['threads']]
            row_values = None
            if percent:
                row_values = [percentage(info[col], total) for col in cols]
            else:
                row_values = [readable(info[col]) for col in cols]
            proc_table.add_row(row_base + row_values)

        proc_table.add_row(['', '', '', '', '', ''])
        proc_table.add_row(['Total:', '', '', '', '', readable(total)])
        print(proc_table)

        metric = metrics.read_memory_stats(cgroup)

        total_table = prettytable.PrettyTable(['memory', 'value'])
        total_table.align['memory'] = 'l'
        total_table.align['value'] = 'r'

        total_table.set_style(prettytable.PLAIN_COLUMNS)
        total_table.header = False

        # Actual memory usage is without the disk cache
        memory_usage = readable(metric['memory.usage_in_bytes'] -
                                metric['memory.stats']['cache'])

        total_table.add_row(['usage', memory_usage])
        total_table.add_row([
            '',
            percentage(metric['memory.usage_in_bytes'],
                       metric['memory.limit_in_bytes'])
        ])
        total_table.add_row(
            ['diskcache',
             readable(metric['memory.stats']['cache'])])

        total_table.add_row(
            ['softlimit',
             readable(metric['memory.soft_limit_in_bytes'])])
        total_table.add_row(
            ['hardlimit',
             readable(metric['memory.limit_in_bytes'])])

        print('')
        print(total_table)
示例#4
0
    def psmem_cmd(fast, app, verbose, percent):
        """Reports memory utilization details for given container.
        """
        if app.find('#') == -1:
            raise click.BadParameter('Specify full instance name: xxx#nnn')
        app = app.replace('#', '-')

        cgroup = None
        apps = os.listdir('/sys/fs/cgroup/memory/treadmill/apps')
        for entry in apps:
            if app in entry:
                cgroup = os.path.join('/treadmill/apps', entry)
        if not cgroup:
            raise click.BadParameter('Could not find corresponding cgroup')

        pids = cgutils.pids_in_cgroup('memory', cgroup)

        use_pss = not fast
        memusage = psmem.get_memory_usage(pids, verbose, use_pss=use_pss)

        total = sum([info['total'] for info in memusage])

        def _readable(value):
            return utils.bytes_to_readable(value, power='B')

        def _percentage(value, total):
            return '{:.1%}'.format(value / total)

        to_format = ['private', 'shared', 'total']
        for info in memusage:
            for key, val in info.items():
                if key in to_format:
                    if percent:
                        info[key] = _percentage(val, total)
                    else:
                        info[key] = _readable(val)

        proc_table = PsmemProcPrettyFormatter()
        print(proc_table.format(memusage))

        metric = metrics.read_memory_stats(cgroup)

        total_list = []
        # Actual memory usage is without the disk cache
        total_list.append({
            'memory-type':
            'usage',
            'value':
            _readable(metric['memory.usage_in_bytes'] -
                      metric['memory.stat']['cache'])
        })
        total_list.append({
            'memory-type':
            '',
            'value':
            _percentage(metric['memory.usage_in_bytes'],
                        metric['memory.limit_in_bytes'])
        })
        total_list.append({
            'memory-type': 'diskcache',
            'value': _readable(metric['memory.stat']['cache'])
        })
        total_list.append({
            'memory-type':
            'softlimit',
            'value':
            _readable(metric['memory.soft_limit_in_bytes'])
        })
        total_list.append({
            'memory-type': 'hardlimit',
            'value': _readable(metric['memory.limit_in_bytes'])
        })

        total_table = PsmemTotalPrettyFormatter()

        print('')
        print(total_table.format(total_list))