diff --git a/source/tools/detect/io/iowaitstat/iowaitstat.py b/source/tools/detect/io/iowaitstat/iowaitstat.py index 4680f7d9d5eb095a2265352072929e10c8c59a06..12a31658e7c75d7828bf4bb3a5b5afa8c7c104fa 100755 --- a/source/tools/detect/io/iowaitstat/iowaitstat.py +++ b/source/tools/detect/io/iowaitstat/iowaitstat.py @@ -95,7 +95,7 @@ class iowaitClass(): self.expression.append('r:r_%s_0 %s%s' % (kprobe, kprobe, commArgs)) self.kprobe.append('r_%s_0' % kprobe) if len(self.kprobe) == 0: - print "not available kprobe" + print("%s" % ("not available kprobe")) sys.exit(0) def config(self): @@ -115,7 +115,10 @@ class iowaitClass(): echoFile(self.tracingDir+"/trace", "") echoFile(self.tracingDir+"/tracing_on", "1") with open("/proc/stat") as fStat: - cpuStatList = map(long, fStat.readline().split()[1:]) + try: + cpuStatList = list(map(long, fStat.readline().split()[1:])) + except Exception: + cpuStatList = list(map(int, fStat.readline().split()[1:])) self.cpuStatIowait['sum'] = sum(cpuStatList) self.cpuStatIowait['iowait'] = cpuStatList[4] @@ -182,7 +185,10 @@ class iowaitClass(): commArgs = self.ftracePaserCommArgs with open("/proc/stat") as fStat: - statList = map(long, fStat.readline().split()[1:]) + try: + statList = list(map(long, fStat.readline().split()[1:])) + except Exception: + statList = list(map(int, fStat.readline().split()[1:])) gloabIowait = float(format( (statList[4]-self.cpuStatIowait['iowait'])*100.0 / (sum(statList)-self.cpuStatIowait['sum']), '.2f')) @@ -253,7 +259,7 @@ class iowaitClass(): if self.json == False: head = str(time.strftime('%Y/%m/%d %H:%M:%S', time.localtime()))+' -> global iowait%: '+str(gloabIowait) - print head + print(head) if stat: stat = OrderedDict(sorted(stat.items(), key=lambda e: e[1]["timeout"], reverse=True)) @@ -298,7 +304,7 @@ class iowaitClass(): def main(): if os.geteuid() != 0: - print "This program must be run as root. Aborting." + print("%s" % ("This program must be run as root. Aborting.")) sys.exit(0) examples = """e.g. ./iowaitstat.py diff --git a/source/tools/detect/mem/fcachetop/fcachetop.py b/source/tools/detect/mem/fcachetop/fcachetop.py old mode 100644 new mode 100755 index d329a2ffb5a06be59e95e3ef07107e6cd774c030..e4784c3cee8ec68cfb9642d38c3654c6d87ca6e7 --- a/source/tools/detect/mem/fcachetop/fcachetop.py +++ b/source/tools/detect/mem/fcachetop/fcachetop.py @@ -26,7 +26,7 @@ except ImportError: c_off_t = c_longlong if is_64bits else c_int if os.geteuid() != 0: - print "This program must be run as root. Aborting." + print("%s" % ("This program must be run as root. Aborting.")) sys.exit(1) MAP_FAILED = c_ulong(-1).value @@ -84,12 +84,12 @@ class Filecachestat: filename = "%s...%s" % (filename_start, filename_end) else: filename += ' ' - print "%s%s%-16d%-16s%s" \ + print("%s%s%-16d%-16s%s" \ % (filename.ljust(48),\ (str(self.pagecached)+'/'+hum_convert(self.pagecached*PAGESIZE)).ljust(24),\ self.nr_page,\ str(self.hit_percent)+"%",\ - self.comm) + self.comm)) def getCacheStat(filename, comm): if os.path.isfile(filename) and os.access(filename, os.R_OK): @@ -104,7 +104,7 @@ def getCacheStat(filename, comm): f.close() return 0 - nr_pages = (size + PAGESIZE - 1) / PAGESIZE + nr_pages = int((size + PAGESIZE - 1) / PAGESIZE) vec = (c_ubyte * nr_pages)() ret = _mincore(addr, size, cast(vec, POINTER(c_ubyte))) if ret != 0: @@ -172,7 +172,7 @@ def topFileCache(interval, top): topDisplay = 0 total_cached = 0 os.system("clear") - print "The top%d Max cached open files:" %top + print("The top%d Max cached open files:" %top) print(head_txt) global global_stat_list for stat in global_stat_list: @@ -181,7 +181,8 @@ def topFileCache(interval, top): total_cached += (stat.pagecached * PAGESIZE) topDisplay += 1 if total_cached != 0: - print "Total cached %s for all open files%s" %(hum_convert(total_cached),'(ctrl+c exit)' if interval else '') + print("Total cached %s for all open files%s" %( + hum_convert(total_cached),'(ctrl+c exit)' if interval else '')) if interval == 0: break sleep(interval)