Пример #1
0
 def get(self,pid):
     self.s.send_cmd(self.prid,TASKSTATS_CMD_GET,TASKSTATS_TYPE_PID,c_uint32(pid))
     (l,msg) = self.s.recv()
     # hprint(msg,l)
     a = nlattr.from_address(addressof(msg.data))
     pid = nlattr.from_address(addressof(msg.data) + sizeof(a))
     stats = taskstatsmsg.from_address(addressof(msg.data) + sizeof(a) + NLMSG_ALIGN(pid.nla_len) + sizeof(nlattr))
     return stats
Пример #2
0
 def get(self, pid):
     self.s.send_cmd(self.prid, TASKSTATS_CMD_GET, TASKSTATS_TYPE_PID,
                     c_uint32(pid))
     (l, msg) = self.s.recv()
     # hprint(msg,l)
     a = nlattr.from_address(addressof(msg.data))
     pid = nlattr.from_address(addressof(msg.data) + sizeof(a))
     stats = taskstatsmsg.from_address(
         addressof(msg.data) + sizeof(a) + NLMSG_ALIGN(pid.nla_len) +
         sizeof(nlattr))
     return stats
Пример #3
0
    if len(sys.argv) > 1:
        try:
            pid = int(sys.argv[1])
        except ValueError:
            mask = sys.argv[1][1:]
    else:
        import os
        pid = os.getpid()

    if pid:
        s.send_cmd(prid, TASKSTATS_CMD_GET, TASKSTATS_CMD_ATTR_PID, c_uint32(pid))
        l, msg = s.recv()

    if mask:
        s.send_cmd(prid,
                   TASKSTATS_CMD_GET,
                   TASKSTATS_CMD_ATTR_REGISTER_CPUMASK,
                   create_string_buffer(mask, 8))
        l, msg = s.recv()

    a = nlattr.from_address(addressof(msg.data))
    assert a.nla_type == TASKSTATS_TYPE_AGGR_PID
    pid = nlattr.from_address(addressof(msg.data) + sizeof(a))
    assert pid.nla_type == TASKSTATS_TYPE_PID
    stats = taskstatsmsg.from_address(addressof(msg.data) + sizeof(a) +
                                      NLMSG_ALIGN(pid.nla_len) + sizeof(nlattr))

    print(stats)    # Taskstats structure.
    print("\n")
    hprint(msg, l)  # Raw packet dump.