From patchwork Mon Sep 11 05:26:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9946671 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 BBE436035D for ; Mon, 11 Sep 2017 05:26:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFB9728AF0 for ; Mon, 11 Sep 2017 05:26:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A485E28AF2; Mon, 11 Sep 2017 05:26:38 +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 9509528AF0 for ; Mon, 11 Sep 2017 05:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750927AbdIKF0d (ORCPT ); Mon, 11 Sep 2017 01:26:33 -0400 Received: from mout.gmx.net ([212.227.17.21]:60871 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750715AbdIKF0c (ORCPT ); Mon, 11 Sep 2017 01:26:32 -0400 Received: from localhost.localdomain ([45.32.39.184]) by mail.gmx.com (mrgmx102 [212.227.17.174]) with ESMTPSA (Nemesis) id 0Me5Q2-1e53yE0bBW-00PqmW; Mon, 11 Sep 2017 07:26:28 +0200 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, marc@merlins.org Subject: [PATCH] btrfs-progs: Output time elapsed for each major tree it checked Date: Mon, 11 Sep 2017 14:26:23 +0900 Message-Id: <20170911052623.31999-1-quwenruo.btrfs@gmx.com> X-Mailer: git-send-email 2.13.3 X-Provags-ID: V03:K0:IUuhuLCjkoDcIDL4ViUdRhoxE0P6e1l0eZ5654rJ21zJ/OarTwN uGXft/0Ijy2yaOhZ3Y+ugKQrFNDHckPlTO/w5SfhYsJOfldiswgK+OOcMdN+741mNwFyymZ 9LOT3jyZh4XCreRdxN6ORELv8ZcwMMLMVyMbol1Cm6B7eQNSKnSmszqDUP+bap2GDksF1Q2 60o/NGrGliP5TYNqTFRqA== X-UI-Out-Filterresults: notjunk:1; V01:K0:7MJN8A7LnrY=:LPbQVpK+WiIirONvvrFlTE md5MSIhYWwuwHOY89RUujQZvYrTp5KEabT4CW2jm1Jse3Z0btC/EWjzXWUHVOc82Cw4nYkOcS I6TjKIdAtThF5F/n3wg4SgY1KphDRBc5uniTyxjaMCxEVdasak068Ox8Mjx/NWIqLQwI1FWxz SE4bD1AaGh1hvWYrWUFsfPgT5LuuqCqp4x9hke/IWM89NqBupfFgJDmdCLk3nGAPA1FWm7AAU TMzc/I7SyZS+vjuB5izHopPTUdf+T2/g189Rkl3Xy9E5s3aQNpJjzVVnuVtEwqIvxth/+vrXK tuCYeRrNh/2+TT5xMQAn1yW00OPiIEhKxAdqcuxA50KlFJamH2dVMEiXJ4ihIru1zavK+NACo eE1HdwdLIYwYXt/AvpeHKNFwxLW+Xy1fLNwM6/De9RlmyHARkLIf8szCGjdFco8OnAvYBT5gL +r7GcZBJJzbpUyNvq+9zNG0SKU9sSKxGGY05lhO/PAKUWpNPjwZrZLmgaqzC4ukbVFd+l6GKF xFrjWdUHvNWuJjDqBBvsf1jUJFaGCEVzzkKWdloRlhv/32wZuh75SOYmbazj9N3vFyxUOF7CI tlBnlURYVdCE9frCDp9slFg177PmP0zqjg0Y+KMZHkztBthkqUy3MsEzpqhN+ZsA2waEJxNuV ABLdREzp8oo9xBSORfKcDK8Y8z4DDHhpvopIwAmDPSNoKrheCjrqWIyreAl7eH40g2x4kV4ac D1IbTpuQ3x87MZMQRzgX0Qra/gQLvgrSTP3Ce62se5K8MiLB4CvKFXwKDyuHlk2T91BN4wGCy xQWYBNz7tvDD0LSx7sJJoulplmMQw== 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 --- 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..fee806cd 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("done 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("done 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("done 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("done 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("done 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("done 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("done 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