def run(self,pretend=True): try: while True: if self.iowait_checker(): self.thr_level+=1 data=self.psg.get_stats("delayacct_blkio_ticks") data.update(self.psg.get_stats("state")) if debug: data_debug=self.psg.get_stats("comm") #for i in range(min(self.throtte_range,len(data["delayacct_blkio_ticks"]))): # pid=data['delayacct_blkio_ticks'][i][0] # self._check_add(pid) for s in data['state']: if s[1]in "DT": self._check_add(s[0]) else: self.thr_level-=1 self.thr_level=min(max(0,self.thr_level),4) self.pthr.controller=self self.pthr.throttle(self.thr_level,pretend=pretend) sleep(self.sleeptime) except Exception as e: ptb(e) self.pthr.__del__()
def _stop_pid(self,pid): try: check_call(['kill','-V'],stderr=DEVNULL,stdout=DEVNULL) cmd=['kill','-sSIGCONT',str(pid)] sudocmd=['sudo']+cmd if pid not in self.need_restore_sigcont: a=True if cmd not in self.need_restore_sigcont_cmds: b=True if sudocmd not in self.need_restore_sigcont_cmds_sudo: c=True with open('/proc/'+str(pid)+'/stat','rb',buffering=0) as f: data=b'' while True: data+=f.read(10) fields=data.split(b" ") if len(fields) >= 4: break if not fields[2] in b'TZX': if self.debug or self.verbose: print("SIGSTOP->"+str(pid),end=';') kill(pid,SIGSTOP) self.need_restore_sigcont.append(pid) self.need_restore_sigcont_cmds.append(cmd) self.need_restore_sigcont_cmds_sudo.append(sudocmd) except Exception as e: ptb(e)
def tr_method_stop(self,level,pid,pretend=True): if self.verbose: print("lvl="+str(level),end=';') try: if random_bool_of_num(level,self.number_levels): if pretend: print("would send SIGSTOP to pid",pid,file=stderr) print(file=stderr) else: self._stop_pid(pid) else: if pretend: print("would send SIGCONT to pid:",pid,file=stderr) print(file=stderr) else: try: if self.debug or self.verbose: print("SIGCONT->"+str(pid),end=";") kill(pid,SIGCONT) except Exception as e: ptb(e) except ProcessLookupError: if self.debug: print("pid not found, removing pid: "+str(pid),file=stderr) self.remove_pid(pid)
def kill_signal_X_on_skyscraper(sigstr, timeout=10): t0 = time() xpids = get_xpids(timeout=timeout) if len(xpids) > 0: cmd = ['ssh', 'root@skyscraper', '/bin/kill', '--signal', sigstr ] + list(str(pid) for pid in xpids) timeout = timeout - time() + t0 try: check_call(cmd, stdout=stdout, stderr=stderr, timeout=timeout, loglevel=DEBUG) except CalledProcessError as e: print(e) print(cmd) ptb(e)
def _cleanup(self): try: for pid in self.need_restore_sigcont: try: kill(pid,SIGCONT) except Exception as e: ptb(e) except Exception as e: ptb(e) try: for cmd in self.need_restore_sigcont_cmds: try: check_call(cmd) except Exception as e: ptb(e) except Exception as e: ptb(e) try: for sudocmd in self.need_restore_sigcont_cmds_sudo: try: check_call(sudocmd) except Exception as e: ptb(e) except Exception as e: ptb(e)