def collect(measures):
    cur = defaultdict(dict)
    prev = measures['data']


    # Collect CPU statistics
    if 'cpuacct' in CGROUP_MOUNTPOINTS:
        # list all "folders" under mountpoint
        for cgroup in cgroups(CGROUP_MOUNTPOINTS['cpuacct']):
            collect_ensure_common(cur[cgroup.name], cgroup)

            # Collect CPU stats
            cur[cgroup.name]['cpuacct.stat'] = cgroup['cpuacct.stat']
            cur[cgroup.name]['cpuacct.stat.diff'] = {'user':0, 'system':0}

            # Collect CPU increase on run > 1
            if cgroup.name in prev:
                for key, value in cur[cgroup.name]['cpuacct.stat'].items():
                    cur[cgroup.name]['cpuacct.stat.diff'][key] = value - prev[cgroup.name]['cpuacct.stat'][key]

    # Collect BlockIO statistics
    if 'blkio' in CGROUP_MOUNTPOINTS:
        # list all "folders" under mountpoint
        for cgroup in cgroups(CGROUP_MOUNTPOINTS['blkio']):
            collect_ensure_common(cur[cgroup.name], cgroup)

            # Collect BlockIO stats
            try:
                cur[cgroup.name]['blkio.throttle.io_service_bytes'] = cgroup['blkio.throttle.io_service_bytes']
                cur[cgroup.name]['blkio.throttle.io_service_bytes.diff'] = {'total':0}
            except IOError as e:
                # Workaround broken systems (see #15)
                if e.errno == errno.ENOENT:
                    continue
                raise

            # Collect BlockIO increase on run > 1
            if cgroup.name in prev:
                cur_val = cur[cgroup.name]['blkio.throttle.io_service_bytes']['Total']
                prev_val = prev[cgroup.name]['blkio.throttle.io_service_bytes']['Total']
                cur[cgroup.name]['blkio.throttle.io_service_bytes.diff']['total'] = cur_val - prev_val

    # Collect memory statistics
    if 'memory' in CGROUP_MOUNTPOINTS:
        # list all "folders" under mountpoint
        for cgroup in cgroups(CGROUP_MOUNTPOINTS['memory']):
            collect_ensure_common(cur[cgroup.name], cgroup)
            cur[cgroup.name]['memory.usage_in_bytes'] = cgroup['memory.usage_in_bytes']
            cur[cgroup.name]['memory.limit_in_bytes'] = min(int(cgroup['memory.limit_in_bytes']), measures['global']['total_memory'])

    # Collect PIDs constraints. Root cgroup does *not* have the controller files
    if 'pids' in CGROUP_MOUNTPOINTS:
        # list all "folders" under mountpoint
        for cgroup in cgroups(CGROUP_MOUNTPOINTS['pids']):
            if cgroup.name == "/":
                continue
            collect_ensure_common(cur[cgroup.name], cgroup)
            cur[cgroup.name]['pids.max'] = cgroup['pids.max']

    #Collect memory statistics for openvz
    if HAS_OPENVZ:
        user_beancounters = get_user_beacounts()
        # We have lines like -
        #      1202     202419    2457600
        #      1203     299835    2457600
        #      1207      54684    2457600
        #      1210     304939    2457600
        #1000001212      13493    2457600
        for line in user_beancounters.split('\n'):
            if line == '':
                continue
            line = re.sub(r'^\s+', '', line)
            splited_line = re.split('\s+', line)
            if len(splited_line) != 3:
                continue
            ctid, privvmpages, limit = splited_line
            ctid = '/' + ctid
            if 'tasks' not in cur[ctid]:
                continue
            privvmpages = int(privvmpages)
            privvmpages = privvmpages * 4096
            limit = int(limit)
            limit = limit * 4096
            cur[ctid]['memory.usage_in_bytes'] = privvmpages
            cur[ctid]['memory.limit_in_bytes'] = min(limit, measures['global']['total_memory'])

    # Sanity check: any data at all ?
    if not len(cur):
        raise KeyboardInterrupt()

    # Apply
    measures['data'] = cur
dataset/ETHPy150Open yadutaf/ctop/cgroup_top.py/collect/original