Example #1
0
class TestTaskStats(object):

    def setup(self):
        self.ts = TaskStats()

    def teardown(self):
        self.ts.release()

    def test_get_pid_stat(self):
        require_user('root')
        ret = self.ts.get_pid_stat(1)[0]
        assert ret.get_attr('TASKSTATS_TYPE_AGGR_PID').\
            get_attr('TASKSTATS_TYPE_PID') == 1
class _TestTaskStats(object):
    def setup(self):
        self.ts = TaskStats()
        self.ts.bind()

    def teardown(self):
        self.ts.close()

    def test_get_pid_stat(self):
        require_user('root')
        ret = self.ts.get_pid_stat(1)[0]
        assert ret.get_attr('TASKSTATS_TYPE_AGGR_PID').\
            get_attr('TASKSTATS_TYPE_PID') == 1
Example #3
0
'''
Simple taskstats sample.

Usage:
    python taskstats.py [pid]
'''
import os
import sys
from pyroute2 import TaskStats
from pyroute2.common import hexdump

pid = sys.argv[-1] if len(sys.argv) > 1 else os.getpid()
ts = TaskStats()
ret = ts.get_pid_stat(int(pid))[0]
# raw hex structure to check alignment
print(hexdump(ret.raw))
# parsed structure
print(ret)
Example #4
0
'''
Simple taskstats sample.
'''
import os
from pyroute2 import TaskStats
from pyroute2.common import hexdump

pid = os.getpid()
ts = TaskStats()
# bind is required in the case of generic netlink
ts.bind()
ret = ts.get_pid_stat(int(pid))[0]
# raw hex structure to check alignment
print(hexdump(ret.raw))
# parsed structure
print(ret)
ts.close()