def get_gprof_callgraph(self, dir1,response_lines=None): scriptid = get_scriptid("gprof_1") print("dir1"+str(dir1)) response_lines = script_execute(scriptid) # print("response_line" + str(response_lines)) return response_lines
def get_callgraph(self, dir1, dir2, response_lines=None): # scriptid = get_scriptid("callgraph") # print("scriptid=" + str(scriptid)) # test = script_execute(scriptid) scriptid = get_scriptid("callgraph_1") # command = "sudo ruby /home/lxia/lxr/callgraph-sql.rb -2 /usr/local/share/cg-rtl/lxr/source1/linux-3.5.4/x86_32/ -d ipc mm -o /home/lxia/lxr/real-ipc-mm-1.graph http://124.16.141.130/lxr/watchlist linux-3.5.4 x86_32 http://124.16.141.130/lxr/call/ real" command = "ruby /home/lxia/lxr/callgraph-sql.rb -2 /usr/local/share/cg-rtl/lxr/source1/linux-3.5.4/x86_32/ " \ "-d " + str(dir1) + " " + str(dir2) + " -o /home/lxia/lxr/real-"+str(dir1)+"-"+str(dir2)+".graph " \ "http://124.16.141.130/lxr/watchlist linux-3.5.4 x86_32 http://124.16.141.130/lxr/call/ real" # print("commad"+str(command)) script_update(scriptid, command) script_execute(scriptid) scriptid = get_scriptid("callgraph_2") command ="cd /home/lxia/lxr;" \ "sudo dot -Tsvg real-"+str(dir1)+"-"+str(dir2)+".graph -o real-"+str(dir1)+"-"+str(dir2)+".svg" script_update(scriptid, command) script_execute(scriptid) scriptid = get_scriptid("callgraph_3") command = "cd /home/lxia/lxr;" \ "sudo sh callgraph_3.sh "+"real-"+str(dir1)+"-"+str(dir2)+"" script_update(scriptid, command) response_lines = script_execute(scriptid) print("response_line" + str(response_lines)) # script_execute_2() # script_execute(scriptid) # response_lines = 'http://192.168.253.134/lxr/6.svg' # cannot # scriptid = get_scriptid("callgraph_4") # print("scriptid=" + str(scriptid)) # script_execute(scriptid) # response_lines = test # print("callgraph-4-" + str(response_lines)) # python get the svg data from the file named ftp # file_object = open('/home/lxia/git/lepv/app/ftp/6.svg') # try: # all_the_text = file_object.read() # print("success open 6.svg") # finally: # file_object.close() # response_lines = all_the_text # if len(response_lines) == 0: # return {} # # response_data = {} # # column_header_line_prefix = '# Overhead' # # try: # while not response_lines[0].startswith(column_header_line_prefix): # response_lines.pop(0) # response_lines.pop(0) # response_lines.pop(0) # response_lines.pop(0) # except Exception as e: # print(response_lines," ----------- GetCmdPerfCpuclock") # return {} # # result_list = [] # for line in response_lines: # if line.strip() == '': # continue # # line_values = line.split() # # if len(line_values) < 5: # continue # # if '%' not in line_values[0]: # continue # # result_line = {} # result_line['Overhead'] = line_values[0] # result_line["Command"] = line_values[1] # result_line["Shared Object"] = line_values[2] # result_line['Symbol'] = ' '.join([str(x) for x in line_values[3:]]) # # result_list.append(result_line) # if len(result_list) >= self.dataCount: # # print('now the length of the array is greater than the max, break here') # break # # response_data['data'] = result_list # print("callgraph-1-"+str(response_data)) return response_lines
def get_status(self): scriptid = get_scriptid("io") print("scriptid=" + str(scriptid)) test = script_execute(scriptid) # test = script_execute(11) resultLines = test.split('\n') # 'Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util' # 'vda 9.31 0.44 0.24 0.42 38.76 4.04 129.68 0.00 6331.59 14163.45 1931.28 1.58 0.10' for i in range(len(resultLines)): if (not resultLines[i].startswith('Device:')): continue # return resultLines[i:] result = resultLines[i:] start_time = datetime.datetime.now() # result = self.client.getIostatResult() if not result: return {} end_time = datetime.datetime.now() raw_results = result[:] headerline = result.pop(0) duration = "%.1f" % ((end_time - start_time).total_seconds()) io_status = { 'lepdDuration': duration, 'disks': {}, 'diskCount': 0, 'ratio': 0 } for line in result: if (line.strip() == ""): continue line_values = line.split() device_name = line_values[0] io_status['diskCount'] += 1 io_status['disks'][device_name] = {} io_status['disks'][device_name]['rkbs'] = line_values[5] io_status['disks'][device_name]['wkbs'] = line_values[6] io_status['disks'][device_name]['ratio'] = line_values[-1] this_disk_ratio = float(line_values[-1]) print("this_disk_ratio" + str(this_disk_ratio) + "line_values[-1]" + str(line_values[-1])) if this_disk_ratio > io_status['ratio']: io_status['ratio'] = this_disk_ratio end_time_2 = datetime.datetime.now() duration = "%.1f" % ((end_time_2 - end_time).total_seconds()) io_status['lepvParsingDuration'] = duration response_data = {'data': io_status, 'rawResult': raw_results} print("IO-status-" + str(response_data)) return response_data
def get_io_top(self, ioTopLines=None): scriptid = get_scriptid("iotop") print("scriptid=" + str(scriptid)) test = script_execute(scriptid) # test = script_execute(12) ioTopLines = test.split('\n') # if (ioTopLines == None): # ioTopLines = self.client.getResponse('GetCmdIotop') print("IOtop-1-" + str(ioTopLines)) ioTopResults = {} ioTopResults['data'] = {} ioTopResults['rawResult'] = ioTopLines[:] # print(len(ioTopLines)) if (len(ioTopLines) < 2): return ioTopResults dataLineStartingIndex = 0 for line in ioTopLines: if (re.match( r'\W*TID\W+PRIO\W+USER\W+DISK READ\W+DISK WRITE\W+SWAPIN\W+IO\W+COMMAND\W*', line.strip(), re.M | re.I)): break else: dataLineStartingIndex += 1 while (dataLineStartingIndex >= 0): ioTopLines.pop(0) dataLineStartingIndex -= 1 # for line in ioTopLines: # print(line) # print('--------------------') orderIndex = 0 for line in ioTopLines: # print(line) if (line.strip() == ''): continue try: # find the 'M/s" or 'B/s', they are for disk read and write matches = re.findall('\s*\d+\.\d{2}\s*[G|M|K|B]\/s\s+', line) diskRead = matches[0].strip() diskWrite = matches[1].strip() # find the "0.00 %" occurrences, they are for swapin and io matches = re.findall('\s*\d+\.\d{2}\s*\%\s+', line) swapin = matches[0].strip() io = matches[1].strip() lineValues = line.split() pid = lineValues[0].strip() prio = lineValues[1].strip() user = lineValues[2].strip() lastPercentIndex = line.rfind('%') command = line[lastPercentIndex + 1:] ioTopItem = {} ioTopItem['TID'] = pid ioTopItem['PRIO'] = prio ioTopItem['USER'] = user ioTopItem['READ'] = diskRead ioTopItem['WRITE'] = diskWrite ioTopItem['SWAPIN'] = swapin ioTopItem['IO'] = io ioTopItem['COMMAND'] = command except Exception as err: print(err, "------- GetCmdIotop") continue # use an incremental int as key, so we keey the order of the items. ioTopResults['data'][orderIndex] = ioTopItem orderIndex += 1 print("iotop-2-" + str(ioTopResults)) return ioTopResults
def get_perf_cpu_clock(self, response_lines=None): # lepd_command = 'GetCmdPerfCpuclock' # if not response_lines: # response_lines = self.client.getResponse(lepd_command) # print("perf-4-" + str(response_lines)) # elif isinstance(response_lines, str): # response_lines = self.client.split_to_lines(response_lines) scriptid = get_scriptid("perf") print("scriptid=" + str(scriptid)) # test = script_execute(9) test = script_execute(scriptid) # test = script_execute(13) response_lines = test.split('\n') print("perf-4-" + str(response_lines)) if len(response_lines) == 0: return {} response_data = {} # if self.config == 'debug': # response_data['rawResult'] = response_lines[:] # response_data['lepd_command'] = lepd_command # print("perf-2-" + str(response_data)) column_header_line_prefix = '# Overhead' try: while not response_lines[0].startswith(column_header_line_prefix): response_lines.pop(0) response_lines.pop(0) response_lines.pop(0) response_lines.pop(0) except Exception as e: print(response_lines," ----------- GetCmdPerfCpuclock") return {} result_list = [] for line in response_lines: if line.strip() == '': continue line_values = line.split() if len(line_values) < 5: # print(' --------------- skip it.') continue if '%' not in line_values[0]: # print(' --------------- skip it.') continue result_line = {} result_line['Overhead'] = line_values[0] result_line["Command"] = line_values[1] result_line["Shared Object"] = line_values[2] result_line['Symbol'] = ' '.join([str(x) for x in line_values[3:]]) result_list.append(result_line) if len(result_list) >= self.dataCount: # print('now the length of the array is greater than the max, break here') break response_data['data'] = result_list print("perf-1-"+str(response_data)) return response_data
def get_procrank(self): procrankData = {} scriptid = get_scriptid("memory") print("scriptid=" + str(scriptid)) test = script_execute(scriptid) # test = script_execute(10) resultLines = test.split('\n') # resultLines.pop() # resultLines = self.client.getResponse('GetCmdProcrank') if (len(resultLines) == 0): return {} while ("cmdline" not in resultLines[0]): resultLines.pop(0) print("getProcrank-2-" + str(resultLines)) # if (self.config == 'debug'): # procrankData['rawResult'] = resultLines[:] procrankData['data'] = {} procrankData['data']['procranks'] = {} headerLine = resultLines.pop(0) lineIndex = 0 for line in resultLines: if (re.match(r'\W+-+\W+-+\W-+.*', line, re.M | re.I)): break lineValues = line.split() procrankData['data']['procranks'][lineIndex] = {} procrankData['data']['procranks'][lineIndex][ 'pid'] = lineValues.pop(0) # procrankData['data']['procranks'][lineIndex]['vss'] = self.client.toDecimal( # Decimal(Decimal(lineValues.pop(0)[:-1]))) # procrankData['data']['procranks'][lineIndex]['rss'] = self.client.toDecimal( # Decimal(Decimal(lineValues.pop(0)[:-1]))) # procrankData['data']['procranks'][lineIndex]['pss'] = self.client.toDecimal( # Decimal(Decimal(lineValues.pop(0)[:-1]))) # procrankData['data']['procranks'][lineIndex]['uss'] = self.client.toDecimal( # Decimal(Decimal(lineValues.pop(0)[:-1]))) procrankData['data']['procranks'][lineIndex]['vss'] = float( Decimal(Decimal(lineValues.pop(0)[:-1]))) procrankData['data']['procranks'][lineIndex]['rss'] = float( Decimal(Decimal(lineValues.pop(0)[:-1]))) procrankData['data']['procranks'][lineIndex]['pss'] = float( Decimal(Decimal(lineValues.pop(0)[:-1]))) procrankData['data']['procranks'][lineIndex]['uss'] = float( Decimal(Decimal(lineValues.pop(0)[:-1]))) procrankData['data']['procranks'][lineIndex]['cmdline'] = ' '.join( [str(x) for x in lineValues]) lineIndex += 1 if (len(procrankData) >= self.dataCount): break # now parse from end, which contains summary info lastLine = resultLines[-1] procrankData['data']['sum'] = {} if (lastLine.startswith('RAM:')): lastLine = lastLine.replace("RAM:", '') lastLineValuePairs = lastLine.split(", ") for valuePair in lastLineValuePairs: keyValuePair = valuePair.split() keyName = keyValuePair[1].strip() keyValue = keyValuePair[0].strip() procrankData['data']['sum'][keyName + "Unit"] = keyValue[-1:] # procrankData['data']['sum'][keyName] = self.client.toDecimal(Decimal(Decimal(keyValue[:-1]))) procrankData['data']['sum'][keyName] = float( Decimal(Decimal(keyValue[:-1]))) xssSumLine = resultLines[-3].strip() if (xssSumLine.endswith('TOTAL')): xssValues = xssSumLine.split() ussTotalString = xssValues[-2] procrankData['data']['sum']['ussTotalUnit'] = ussTotalString[-1:] # procrankData['data']['sum']['ussTotal'] = self.client.toDecimal(Decimal(Decimal(ussTotalString[:-1]))) procrankData['data']['sum']['ussTotal'] = float( Decimal(Decimal(ussTotalString[:-1]))) pssTotalString = xssValues[-3] procrankData['data']['sum']['pssTotalUnit'] = pssTotalString[-1:] # procrankData['data']['sum']['pssTotal'] = self.client.toDecimal(Decimal(Decimal(pssTotalString[:-1]))) procrankData['data']['sum']['pssTotal'] = float( Decimal(Decimal(pssTotalString[:-1]))) return procrankData