def on_just_this_thread_clicked(self, button): self.regex_edit.set_sensitive(False) self.process_list_store.clear() info = self.process_list_store.append() cmdline = procfs.process_cmdline(self.pid_info) self.process_list_store.set(info, self.PROCESS_COL_PID, self.pid, self.PROCESS_COL_NAME, cmdline)
def _get_cmdline(self, process): if not isinstance(process, procfs.process): pid = process process = procfs.process(pid) cmdline = procfs.process_cmdline(process) if self._is_kthread(process): cmdline = "[" + cmdline + "]" return cmdline
def refresh_match_pids(self, cmdline_regex): self.process_list_store.clear() for match_pid in self.ps.find_by_cmdline_regex(cmdline_regex): info = self.process_list_store.append() pid_info = self.ps[match_pid] cmdline = procfs.process_cmdline(pid_info) self.process_list_store.set(info, self.PROCESS_COL_PID, match_pid, self.PROCESS_COL_NAME, cmdline)
def on_all_these_threads_clicked(self, button): self.regex_edit.set_sensitive(False) self.process_list_store.clear() info = self.process_list_store.append() cmdline = procfs.process_cmdline(self.ps[self.pid]) self.process_list_store.set(info, self.PROCESS_COL_PID, self.pid, self.PROCESS_COL_NAME, cmdline) for tid in self.ps[self.pid]["threads"].keys(): child = self.process_list_store.append() self.process_list_store.set(child, self.PROCESS_COL_PID, tid, self.PROCESS_COL_NAME, cmdline)
def thread_help(self, tid): if not self.ps: self.ps = procfs.pidstats() if not ps.has_key(tid): print "tuna: " + _("thread %d doesn't exists!") % tid return pinfo = ps[tid] cmdline = procfs.process_cmdline(pinfo) help, title = tuna.kthread_help_plain_text(tid, cmdline) print "%s\n\n%s" % (title, _(help))
def thread_help(tid): global ps if not ps: ps = procfs.pidstats() if not ps.has_key(tid): print "tuna: " + _("thread %d doesn't exists!") % tid return pinfo = ps[tid] cmdline = procfs.process_cmdline(pinfo) help, title = tuna.kthread_help_plain_text(tid, cmdline) print "%s\n\n%s" % (title, _(help))
def __init__(self, ps, pid, pid_info, nr_cpus, gladefile): self.ps = ps self.pid = pid self.pid_info = pid_info self.nr_cpus = nr_cpus self.window = gtk.glade.XML(gladefile, "set_process_attributes", "tuna") self.dialog = self.window.get_widget("set_process_attributes") pixbuf = self.dialog.render_icon(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_SMALL_TOOLBAR) self.dialog.set_icon(pixbuf) event_handlers = { "on_cmdline_regex_changed": self.on_cmdline_regex_changed, "on_affinity_text_changed": self.on_affinity_text_changed, "on_sched_policy_combo_changed": self.on_sched_policy_combo_changed, "on_command_regex_clicked": self.on_command_regex_clicked, "on_all_these_threads_clicked": self.on_all_these_threads_clicked, "on_just_this_thread_clicked": self.on_just_this_thread_clicked } self.window.signal_autoconnect(event_handlers) self.sched_pri = self.window.get_widget("sched_pri_spin") self.sched_policy = self.window.get_widget("sched_policy_combo") self.regex_edit = self.window.get_widget("cmdline_regex") self.affinity = self.window.get_widget("affinity_text") self.just_this_thread = self.window.get_widget("just_this_thread") self.all_these_threads = self.window.get_widget("all_these_threads") processes = self.window.get_widget("matching_process_list") self.sched_pri.set_value(int(pid_info["stat"]["rt_priority"])) cmdline_regex = procfs.process_cmdline(pid_info) self.affinity_text = tuna.list_to_cpustring( schedutils.get_affinity(pid)) self.affinity.set_text(self.affinity_text) self.create_matching_process_model(processes) self.create_policy_model(self.sched_policy) self.sched_policy.set_active(schedutils.get_scheduler(pid)) self.regex_edit.set_text(cmdline_regex) self.just_this_thread.set_active(True) self.regex_edit.set_sensitive(False) if not ps.has_key(pid) or not ps[pid].has_key("threads"): self.all_these_threads.hide() self.on_just_this_thread_clicked(None)
def set_thread_columns(self, iter, tid, thread_info): new_value = [ None ] * self.nr_columns new_value[self.COL_PRI] = int(thread_info["stat"]["rt_priority"]) new_value[self.COL_POL] = schedutils.schedstr(schedutils.get_scheduler(tid))[6:] thread_affinity_list = schedutils.get_affinity(tid) new_value[self.COL_PID] = tid new_value[self.COL_AFF] = tuna.list_to_cpustring(thread_affinity_list) try: new_value[self.COL_VOLCTXT] = int(thread_info["status"]["voluntary_ctxt_switches"]) new_value[self.COL_NONVOLCTXT] = int(thread_info["status"]["nonvoluntary_ctxt_switches"]) new_value[self.COL_CGROUP] = thread_info["cgroups"] except: pass new_value[self.COL_CMDLINE] = procfs.process_cmdline(thread_info) gui.set_store_columns(self.tree_store, iter, new_value)
def print_sockets(pid, indent=0): header_printed = False dirname = "/proc/%d/fd" % pid try: filenames = os.listdir(dirname) except: # Process died return for filename in filenames: pathname = os.path.join(dirname, filename) try: linkto = os.readlink(pathname) except: # Process died continue inode_match = inode_re.match(linkto) if not inode_match: continue inode = int(inode_match.group(1)) if not inodes.has_key(inode): continue if not header_printed: try: print "\n%s%d: %s" % (indent * " ", pid, procfs.process_cmdline(ps[pid])) except: return print " %-*s %-6s %-6s %*s:%-5s %*s:%-5s %-*s %-*s %-5s %-3s" % \ (state_width, "State", "Recv-Q", "Send-Q", addr_width, "Local Address", "Port", addr_width, "Peer Address", "Port", owner_width, "Owner", timer_width, "Timer", "(ms)", "Rtm") header_printed = True s = inodes[inode] owner = pwd.getpwuid(s.uid())[0] print " %-*s %-6d %-6d %*s:%-5d %*s:%-5d %-*s %-*s %-5d %-3d" % \ (state_width, s.state(), s.receive_queue(), s.write_queue(), addr_width, s.saddr(), s.sport(), addr_width, s.daddr(), s.dport(), owner_width, owner, timer_width, s.timer(), s.timer_expiration(), s.retransmissions())
def print_sockets(pid, indent = 0): header_printed = False dirname = "/proc/%d/fd" % pid try: filenames = os.listdir(dirname) except: # Process died return for filename in filenames: pathname = os.path.join(dirname, filename) try: linkto = os.readlink(pathname) except: # Process died continue inode_match = inode_re.match(linkto) if not inode_match: continue inode = int(inode_match.group(1)) if not inodes.has_key(inode): continue if not header_printed: try: print "\n%s%d: %s" % (indent * " ", pid, procfs.process_cmdline(ps[pid])) except: return print " %-*s %-6s %-6s %*s:%-5s %*s:%-5s %-*s %-*s %-5s %-3s" % \ (state_width, "State", "Recv-Q", "Send-Q", addr_width, "Local Address", "Port", addr_width, "Peer Address", "Port", owner_width, "Owner", timer_width, "Timer", "(ms)", "Rtm") header_printed = True s = inodes[inode] owner = pwd.getpwuid(s.uid())[0] print " %-*s %-6d %-6d %*s:%-5d %*s:%-5d %-*s %-*s %-5d %-3d" % \ (state_width, s.state(), s.receive_queue(), s.write_queue(), addr_width, s.saddr(), s.sport(), addr_width, s.daddr(), s.dport(), owner_width, owner, timer_width, s.timer(), s.timer_expiration(), s.retransmissions())
def set_thread_columns(self, iter, tid, thread_info): new_value = [None] * self.nr_columns new_value[self.COL_PRI] = int(thread_info["stat"]["rt_priority"]) new_value[self.COL_POL] = schedutils.schedstr( schedutils.get_scheduler(tid))[6:] thread_affinity_list = schedutils.get_affinity(tid) new_value[self.COL_PID] = tid new_value[self.COL_AFF] = tuna.list_to_cpustring(thread_affinity_list) try: new_value[self.COL_VOLCTXT] = int( thread_info["status"]["voluntary_ctxt_switches"]) new_value[self.COL_NONVOLCTXT] = int( thread_info["status"]["nonvoluntary_ctxt_switches"]) new_value[self.COL_CGROUP] = thread_info["cgroups"] except: pass new_value[self.COL_CMDLINE] = procfs.process_cmdline(thread_info) gui.set_store_columns(self.tree_store, iter, new_value)
def __init__(self, ps, pid, pid_info, nr_cpus, gladefile): self.ps = ps self.pid = pid self.pid_info = pid_info self.nr_cpus = nr_cpus self.window = gtk.glade.XML(gladefile, "set_process_attributes", "tuna") self.dialog = self.window.get_widget("set_process_attributes") pixbuf = self.dialog.render_icon(gtk.STOCK_PREFERENCES, gtk.ICON_SIZE_SMALL_TOOLBAR) self.dialog.set_icon(pixbuf) event_handlers = { "on_cmdline_regex_changed" : self.on_cmdline_regex_changed, "on_affinity_text_changed" : self.on_affinity_text_changed, "on_sched_policy_combo_changed" : self.on_sched_policy_combo_changed, "on_command_regex_clicked" : self.on_command_regex_clicked, "on_all_these_threads_clicked" : self.on_all_these_threads_clicked, "on_just_this_thread_clicked" : self.on_just_this_thread_clicked } self.window.signal_autoconnect(event_handlers) self.sched_pri = self.window.get_widget("sched_pri_spin") self.sched_policy = self.window.get_widget("sched_policy_combo") self.regex_edit = self.window.get_widget("cmdline_regex") self.affinity = self.window.get_widget("affinity_text") self.just_this_thread = self.window.get_widget("just_this_thread") self.all_these_threads = self.window.get_widget("all_these_threads") processes = self.window.get_widget("matching_process_list") self.sched_pri.set_value(int(pid_info["stat"]["rt_priority"])) cmdline_regex = procfs.process_cmdline(pid_info) self.affinity_text = tuna.list_to_cpustring(schedutils.get_affinity(pid)) self.affinity.set_text(self.affinity_text) self.create_matching_process_model(processes) self.create_policy_model(self.sched_policy) self.sched_policy.set_active(schedutils.get_scheduler(pid)) self.regex_edit.set_text(cmdline_regex) self.just_this_thread.set_active(True) self.regex_edit.set_sensitive(False) if not ps.has_key(pid) or not ps[pid].has_key("threads"): self.all_these_threads.hide() self.on_just_this_thread_clicked(None)