From caf04251f7572e101507a5f2200189b2fa01a739 Mon Sep 17 00:00:00 2001 From: "guangshui.li" Date: Mon, 11 Apr 2022 15:52:33 +0800 Subject: [PATCH 1/2] fcachetop: Delete obsolete code Signed-off-by: guangshui.li --- source/tools/detect/fcachetop/fcachetop.py | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/source/tools/detect/fcachetop/fcachetop.py b/source/tools/detect/fcachetop/fcachetop.py index 07014e6c..546e9cb0 100755 --- a/source/tools/detect/fcachetop/fcachetop.py +++ b/source/tools/detect/fcachetop/fcachetop.py @@ -160,6 +160,7 @@ def threadStatListUpdata(interval): break sleep(interval - 1) +head_txt = "Name".ljust(48)+"Cached pages/size".ljust(24)+"Total pages".ljust(16)+"Hit percent".ljust(16)+"Comm:Pid" def topFileCache(interval, top): if interval == 0: threadStatListUpdata(0) @@ -186,23 +187,6 @@ def topFileCache(interval, top): sleep(interval) sys.exit(0) -head_txt = "Name".ljust(48)+"Cached pages/size".ljust(24)+"Total pages".ljust(16)+"Hit percent".ljust(16)+"Comm:Pid" -usage_txt = "usage: \n./fcachetop [option] Statistics the open files page cached\n\ --f, --file=filepath Statistics the file pages cached from specified file\n\ --i, --interval=n Display the file pages cached per N seconds(ctrl+c exit)\n\ --T, --top=n Display the file pages cached of TopN (default Top 10)\n\ --v Display the full path of the file\n\ - (By default, when the file path exceeds 48 characters, the full path of the file is hidden)\n\ne.g.\n\ -./fcachetop Display the file pages cached of Top10\n\ -./fcachetop -f /xxx/file\n\ - Statistics the file pages cached for \'/xxx/file\'\n\ -./fcachetop -i 2 Display the file pages cached per N seconds(ctrl+c exit)\n\ -./fcachetop -T 30 Display the file pages cached of Top30\n" - -def usage(err): - print(usage_txt) - sys.exit(err) - def main(): examples = """e.g. ./fcachetop Display the file pages cached of Top10\n\ -- Gitee From 012861bf15def5eb579d09f03ea1d8a30a4b4e44 Mon Sep 17 00:00:00 2001 From: "guangshui.li" Date: Mon, 11 Apr 2022 16:05:19 +0800 Subject: [PATCH 2/2] fcachetop: Hide long file path Signed-off-by: guangshui.li --- source/tools/detect/fcachetop/fcachetop.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/source/tools/detect/fcachetop/fcachetop.py b/source/tools/detect/fcachetop/fcachetop.py index 546e9cb0..3d816c58 100755 --- a/source/tools/detect/fcachetop/fcachetop.py +++ b/source/tools/detect/fcachetop/fcachetop.py @@ -74,11 +74,11 @@ class Filecachestat: self.nr_page = nr_page self.hit_percent = round(float(pagecached) * 100 / float(nr_page), 2) - def dumpStat(self, hide): + def dumpStat(self, verbose): len_filename = len(self.filename) filename = self.filename if len_filename > 48: - if hide == 1: + if verbose == 0: filename_end = (self.filename)[(len_filename-30):len_filename] filename_start = (self.filename)[0:13] filename = "%s...%s" % (filename_start, filename_end) @@ -177,7 +177,7 @@ def topFileCache(interval, top): global global_stat_list for stat in global_stat_list: if topDisplay <= top: - stat.dumpStat(hide_long_filepath) + stat.dumpStat(verbose_long_filepath) total_cached += (stat.pagecached * PAGESIZE) topDisplay += 1 if total_cached != 0: @@ -203,7 +203,7 @@ def main(): help='Statistics the file pages cached from specified file.') parser.add_argument('-i','--interval', help='Display the file pages cached per N seconds(CTRL+C exit).') parser.add_argument('-T','--top', help='Display the file pages cached of TopN (default Top 10).') - parser.add_argument('-v','--verbo', action='store_true',\ + parser.add_argument('-v','--verbose', action='store_true',\ help='Display the full path of the file(By default, when the file path exceeds 48 characters, the full path of the file is hidden).') args = parser.parse_args() @@ -212,8 +212,8 @@ def main(): top = int(args.top) if args.top else 10 interval = int(args.interval) if args.interval is not None else 0 - global hide_long_filepath - hide_long_filepath = False if args.verbo is None else True + global verbose_long_filepath + verbose_long_filepath = args.verbose signal.signal(signal.SIGINT, signal_exit_handler) signal.signal(signal.SIGHUP, signal_exit_handler) @@ -225,7 +225,7 @@ def main(): print(head_txt) stat = getCacheStat(filename, None) assert stat != 0, "getCacheStat() failed" - stat.dumpStat(hide_long_filepath) + stat.dumpStat(verbose_long_filepath) if __name__ == "__main__": main() -- Gitee