From patchwork Mon Sep 18 00:47:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9955363 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3CEE96028A for ; Mon, 18 Sep 2017 00:48:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2B92B28AD7 for ; Mon, 18 Sep 2017 00:48:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D9D128ADA; Mon, 18 Sep 2017 00:48:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C07EA28AD3 for ; Mon, 18 Sep 2017 00:47:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752039AbdIRAri (ORCPT ); Sun, 17 Sep 2017 20:47:38 -0400 Received: from mout.gmx.net ([212.227.15.15]:58724 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751295AbdIRArh (ORCPT ); Sun, 17 Sep 2017 20:47:37 -0400 Received: from localhost.localdomain ([45.32.39.184]) by mail.gmx.com (mrgmx001 [212.227.17.184]) with ESMTPSA (Nemesis) id 0Lrviw-1dPjrv25za-013fKv; Mon, 18 Sep 2017 02:47:34 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH v2] btrfs-progs: Output time elapsed for each major tree it checked Date: Mon, 18 Sep 2017 09:47:29 +0900 Message-Id: <20170918004729.5871-1-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.3 X-Provags-ID: V03:K0:6Ni0P0iOoWdFULf1OsDz6peD6vA4FDNly7uTtShHaOkVddVF3E1 Bwbd9N70ZaQPa60WZ+NC5oqk328sx8BUHPj7PkxpEsvBRV8vuQQb18kW3DrJvN/+cNfXHpL 5+6Sv7Y22fZDDToePggupWuv5WUid+VjkTsqQUOqLrZqtHbMLjBiSUrBCwZzw1bNpnJnkIp Os3q0uJJL09hCk+n5TJZQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:dsYJ9r09xcQ=:f7pk3BfFrhD/hLxd5s7Ocw 0DrxhL/BUax4EsPIkOURnSjuzph8LaaV4flYzaKubaTIB+T0XSEwgCLnNHy762k8rv3MUHsKl vkn4uWQ+9tq1FLF5eQUKDqhqrCbBzoAG6xra43WkIiaQvVodpDm5FEOpvgSGgjVzInSGrbnpK Nkc2/rdFV5bJnvWbXDn+rHq1BsPFqjAADMmwIuI1+T4OKgpPt67JMMZlEbBFoTt2+CFI1i4Ss FNIlpnRYPSv9jazMpS0vMWvfObD5DtVf9SQl50PKpnrwNhIBjGIl8rcfNv8xECNuN0MxOc2mm XwwpcQ7MSryX/HyCsm9oTPGz9pLlGnz4Qv+XiQTHdIuGN10F3IgFO8ZUiz8fckZBWe1Q4b634 AimhdPAQbQG6MMmi5dJZmmAC5lNcEm0ymVbYKsxpfX87VaS9A2PewVg4SZPl49upYd9XYu6le FLa9PvH+ut8kBXFn27gpc2KbVhFQLedEurLgTduoAz+k5jlKhWGAt4jBzvEDNeutUGguAEUM4 mLJ8xxWq8wzyXZ/sqDLLviy3qhVJ30cn+ZU7N2G0xSmlBwH8Bq4xsyK3OuMN/Whv6XH9X+Oql yJEGwCsYfstQAntev1LKpkMnmFuYYtLUfhaPa5tm6qNdW45anPGJLFgtCZCxZWiIxhFTLkBuD Qz5NilPmyBshrC9CNIAoqvgf8COWBj7dkS2///1vrbQn356jj9VCTRWaWQ80FWwjMaRBhbYGw AGeHYocKOUn3xw94KmThV2ELluCoJelNVL0ICEylLzPNkjNVjv8KAyvWstqGTy2fFGqPFic4g ZnR5tJAP+BAVEhA25jeusD2elFk0g== Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Marc reported that "btrfs check --repair" runs much faster than "btrfs check", which is quite weird. This patch will add time elapsed for each major tree it checked, for both original mode and lowmem mode, so we can have a clue what's going wrong. Reported-by: Marc MERLIN Signed-off-by: Qu Wenruo Reviewed-by: Satoru Takeuchi --- v2: Add prefix for each time report, as error message may make the output hard to understand. Suggested by Satoru. --- cmds-check.c | 21 +++++++++++++++++++-- utils.h | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/cmds-check.c b/cmds-check.c index 006edbde..f1074c73 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -5318,13 +5318,16 @@ static int do_check_fs_roots(struct btrfs_fs_info *fs_info, struct cache_tree *root_cache) { int ret; + struct timer timer; if (!ctx.progress_enabled) fprintf(stderr, "checking fs roots\n"); + start_timer(&timer); if (check_mode == CHECK_MODE_LOWMEM) ret = check_fs_roots_v2(fs_info); else ret = check_fs_roots(fs_info, root_cache); + printf("fs roots checked in %d seconds\n", stop_timer(&timer)); return ret; } @@ -11584,14 +11587,16 @@ out: static int do_check_chunks_and_extents(struct btrfs_fs_info *fs_info) { int ret; + struct timer timer; if (!ctx.progress_enabled) fprintf(stderr, "checking extents\n"); + start_timer(&timer); if (check_mode == CHECK_MODE_LOWMEM) ret = check_chunks_and_extents_v2(fs_info); else ret = check_chunks_and_extents(fs_info); - + printf("extents checked in %d seconds\n", stop_timer(&timer)); return ret; } @@ -12772,6 +12777,7 @@ int cmd_check(int argc, char **argv) int qgroups_repaired = 0; unsigned ctree_flags = OPEN_CTREE_EXCLUSIVE; int force = 0; + struct timer timer; while(1) { int c; @@ -12953,8 +12959,11 @@ int cmd_check(int argc, char **argv) if (repair) ctree_flags |= OPEN_CTREE_PARTIAL; + printf("opening btrfs filesystem\n"); + start_timer(&timer); info = open_ctree_fs_info(argv[optind], bytenr, tree_root_bytenr, chunk_root_bytenr, ctree_flags); + printf("btrfs filesystem opened in %d seconds\n", stop_timer(&timer)); if (!info) { error("cannot open file system"); ret = -EIO; @@ -13115,8 +13124,10 @@ int cmd_check(int argc, char **argv) else fprintf(stderr, "checking free space cache\n"); } + start_timer(&timer); ret = check_space_cache(root); err |= !!ret; + printf("free space cache (tree) checked in %d seconds\n", stop_timer(&timer)); if (ret) { if (btrfs_fs_compat_ro(info, FREE_SPACE_TREE)) error("errors found in free space tree"); @@ -13140,18 +13151,22 @@ int cmd_check(int argc, char **argv) } fprintf(stderr, "checking csums\n"); + start_timer(&timer); ret = check_csums(root); err |= !!ret; + printf("csums tree checked in %d seconds\n", stop_timer(&timer)); if (ret) { error("errors found in csum tree"); goto out; } - fprintf(stderr, "checking root refs\n"); /* For low memory mode, check_fs_roots_v2 handles root refs */ if (check_mode != CHECK_MODE_LOWMEM) { + fprintf(stderr, "checking root refs\n"); + start_timer(&timer); ret = check_root_refs(root, &root_cache); err |= !!ret; + printf("root refs checked in %d seconds\n", stop_timer(&timer)); if (ret) { error("errors found in root refs"); goto out; @@ -13186,8 +13201,10 @@ int cmd_check(int argc, char **argv) if (info->quota_enabled) { fprintf(stderr, "checking quota groups\n"); + start_timer(&timer); ret = qgroup_verify_all(info); err |= !!ret; + printf("quota groups checked in %d seconds\n", stop_timer(&timer)); if (ret) { error("failed to check quota groups"); goto out; diff --git a/utils.h b/utils.h index d28a05a6..159487db 100644 --- a/utils.h +++ b/utils.h @@ -172,4 +172,28 @@ u64 rand_u64(void); unsigned int rand_range(unsigned int upper); void init_rand_seed(u64 seed); +/* Utils to report time duration */ +struct timer { + time_t start; +}; + +static inline void start_timer(struct timer *t) +{ + time(&t->start); +} + +/* + * Stop timer and return the time elapsed in int + * + * int should be large enough to "btrfs check" and avoid + * type converting. + */ +static inline int stop_timer(struct timer *t) +{ + time_t end; + + time(&end); + + return (int)(difftime(end, t->start)); +} #endif