예제 #1
0
 def _GetPerformanceDataThread(self):
     while True:
         cpuRate = info.top()[0]
         mem = info.top()[1]
         print("cpu is {}% mem is {}M".format(cpuRate, mem))
         self._CpuUseRateQueue.appendleft(cpuRate)
         self._MemUseQueue.appendleft(mem)
예제 #2
0
    def StartMonitor(self):
        count = 0
        # 创建一个workbook 设置编码
        workbook = xlwt.Workbook(encoding='utf-8')
        while True:
            top_info = info.top()
            cpuRate = top_info[0]
            mem = top_info[1]

            now = datetime.datetime.now()
            now = now.strftime("%H:%M:%S")

            if count % 30 == 0:
                print('-----------------------------{}'.format(count + 1))
            if count == 0:
                # 创建一个worksheet
                worksheet = workbook.add_sheet(self._devicesName)
                worksheet.write(0, 0, label='时间')
                worksheet.write(0, 1, label='CPU占用率(%)')
                worksheet.write(0, 2, label='内存占用(M)')
            # 入excel
            # 参数对应 行, 列, 值
            worksheet.write(count + 1, 0, label=str(now))
            worksheet.write(count + 1, 1, label=cpuRate)
            worksheet.write(count + 1, 2, label=mem)
            workbook.save('./Data/per_{}.xlsx'.format(self._devicesName))
            print("cpu is {}% mem is {}M".format(cpuRate, mem))
            # time.sleep(0.2)
            count += 1
    def StartMonitor(self):

        # 开启新线程获取cpu内存值
        # _thread.start_new_thread(self._GetPerformanceDataThread, ())

        count = 0
        # 创建一个workbook 设置编码
        workbook = xlwt.Workbook(encoding='utf-8')
        while 1:
            # if len(self._MemUseQueue) == 0 and len(self._CpuUseRateQueue) == 0:
            #     # print('the data queue is empty!')
            #     # time.sleep(0.5)
            #     continue
            # # show x axis
            # # cpu use rate data
            # if not len(self._CpuUseRateQueue) == 0:
            #     self._CurrentCpuUseRate = self._CpuUseRateQueue.popleft()
            # # Mem use
            # if not len(self._MemUseQueue) == 0:
            #     self._CurrentMemUse = self._MemUseQueue.popleft()

            top_info = info.top()
            cpuRate = top_info[0]
            mem = top_info[1]
            print("cpu is {}% mem is {}M".format(cpuRate, mem))
            # self._CpuUseRateQueue.appendleft(cpuRate)
            # self._MemUseQueue.appendleft(mem)

            now = datetime.datetime.now()
            now = now.strftime("%H:%M:%S")

            if count % 30 == 0:
                print('-----------------------------{}'.format(count + 1))
            if count == 0:
                # 创建一个worksheet
                worksheet = workbook.add_sheet(self._devicesName)
                worksheet.write(0, 0, label='时间')
                worksheet.write(0, 1, label='CPU占用率(%)')
                worksheet.write(0, 2, label='内存占用(M)')

            # 入excel
            # 参数对应 行, 列, 值
            worksheet.write(count + 1, 0, label=str(now))
            worksheet.write(count + 1, 1, label=cpuRate)
            worksheet.write(count + 1, 2, label=mem)
            workbook.save('./Data/per_{}.xlsx'.format(self._devicesName))
            # time.sleep(0.2)
            count += 1
예제 #4
0
    def writedata(self):
        format1 = self.wd.add_format({'bold':True,'align':'center','valign':'vcenter','border':1})
        sheet = str(info.devices())
        worksheet = self.wd.add_worksheet(sheet)
        worksheet.write('A1','cpu',format1)
        worksheet.write('B1','mem',format1)

        #写mem cpu信息到表格中
        mem,cpu=info.top()
        for i in range(len(mem)):
            worksheet.write(i+1,0,mem[i],format1)

        for i in range(len(mem)):
            worksheet.write(i+1,1,cpu[i],format1)

        self.chart(worksheet,sheet,'cpu',len(cpu))
        self.chart(worksheet,sheet,'mem',len(mem))