def run(self):
        """开始线程."""
        while not self.stop_flag:
            timestamp = time.time()
            cpu_percent = self.process.cpu_percent() / self.cpu_num
            # mem_percent = mem = self.process.memory_percent()
            mem_info = dict(self.process.memory_info()._asdict())
            mem_gb_num = mem_info.get('rss', 0) / 1024 / 1024
            # 记录类变量
            self.profile_data.append({"mem_gb_num": mem_gb_num, "cpu_percent": cpu_percent, "timestamp": timestamp})
            # 记录cpu和mem_gb_num
            time.sleep(self.interval)
def run ( self ) : while not self . stop_flag : timestamp = time . time ( ) cpu_percent = self . process . cpu_percent ( ) / self . cpu_num mem_info = dict ( self . process . memory_info ( ) . _asdict ( ) ) mem_gb_num = mem_info . get ( 'rss' , 0 ) / 1024 / 1024 self . profile_data . append ( { "mem_gb_num" : mem_gb_num , "cpu_percent" : cpu_percent , "timestamp" : timestamp } ) time . sleep ( self . interval )
开始线程.