Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp767692img; Mon, 18 Mar 2019 13:50:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqLEsZRD6E2JzBtm6hHjcB4zmC/wv/J0DOEVj4Wr/Ncjcv6N3/2puEPK/poUK8yhOxnWFK X-Received: by 2002:a17:902:8c81:: with SMTP id t1mr9331564plo.309.1552942249298; Mon, 18 Mar 2019 13:50:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552942249; cv=none; d=google.com; s=arc-20160816; b=Ir4sMEeyBpjAK6imjAz/wJXQ66Rlu6dVi3NzGPB8qKmnjRT2rXrq00eCAzQcqdBY5J TZ7ZhtuH5E3f7v8CXHsTK5DP0X4DE1rDUcTIHDMntPbjxWdyJ5VgKKYAp6Or34nC8A1p qZ5YdrdWUnTesqqin/z5YrHiujbROm7skvXOEusH3sUswdGJUznpdQ0xkDDV6Tr8tQHA 91MM24tnD50V7oHUSVD0cBDHn5w7k+cJGM+2FastKNzzsISvwe2EkJp9OiJLlzfgTqgj JvFKpcImyQTXTP56/r8chDljdqFUIwFv0GBiXb+y3w9YIe6OYRCkuIEY4GlPgfQTKcnV +gLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nmY39NqjbJjPMzWIg+Tj7pvCw+EDxtYkJ2n1A8J3RZI=; b=yH20WV5LNfTLJfdfmwlKHmNxxkqvHLe3Adu9TW6LfrJFw/Bw8Bt5Zv8GzisKWKsPK1 4yxgNa3PPTQNcPdshJxqJ17liDV2unP6CZ816Qe9MZu1W0s3DQN4fuLKRkstIP8HX3rr p0yWaLVne5KGCLrv/kcUp70WmfmOirEaw+Zf9d9XaEYXlt0n2NUeYbYly8YmtFc0GBk8 r0i56JPeEE51v/hQVvNmwym5Z9SIpgMNIO69NQ/jm6MqbFqS9Kwuy18FMZfIEaYa8Qiv nyj6zkclWChveUknrCxtG6igGx/dFjyHYWm20iBqL1fEG1Lr0aG9Qb4WcAi7W4tyBPuC /frg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=g7ekm0lk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x9si9589127pgp.216.2019.03.18.13.50.34; Mon, 18 Mar 2019 13:50:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=g7ekm0lk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727851AbfCRUr4 (ORCPT + 99 others); Mon, 18 Mar 2019 16:47:56 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:44057 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727815AbfCRUrt (ORCPT ); Mon, 18 Mar 2019 16:47:49 -0400 Received: by mail-pf1-f194.google.com with SMTP id a3so12065258pff.11 for ; Mon, 18 Mar 2019 13:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nmY39NqjbJjPMzWIg+Tj7pvCw+EDxtYkJ2n1A8J3RZI=; b=g7ekm0lkyAWpPBPoJ5x2jgD+5JYl3+eEVOuZ8NxH9nWCiIX5MjaySo2KT7YHTORu5z 2pivMG0mF6kyOGWjZVYNdhIZLEDIJfocZjZA9DOVRc/xmmhHblyii+doItc+3C9rBIvM 2/QS29e4+n1nQGlt4UsxgKPuVtE9vDfCgc69M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nmY39NqjbJjPMzWIg+Tj7pvCw+EDxtYkJ2n1A8J3RZI=; b=LcpV/GX9p+pN+2/uO+Q8jWr1dEO3PmaAfr5Zp/O2xl7QHOZWa8pjEpmBirOZ+W43/Y bE3FalT8AYNLTsjGCHlOhUxpfBhF0wYk+no+d++vsLwBsGL/1LX0rpQpgUvko6O0U1bJ GB0enVLS41WbXRTSBf+rQnB3EgX2eR2egMhUMgn5jsTupSfGX0AqVU6+J3G9odgQkpl9 FW7nHV1sp96dHLG48suiE21utY76X2nuKEigk1VGSpJLEhqrQVvOjxmDRnNGYeeGapWu C1XZHLevGXU5nLyHp1x53gkGDRIaQha64xw3+0Tw2w3AHGj0RSDiC2R+qftgPhEo+PEh C5OA== X-Gm-Message-State: APjAAAUp/ARQI1M9i6jg9CCd1F6Xtb998uqQ+dczx6IzVXb19D/JHMw0 CxGSa+cCoqrNxhRJRExhXpKt3g== X-Received: by 2002:a17:902:8f81:: with SMTP id z1mr22219543plo.265.1552942069180; Mon, 18 Mar 2019 13:47:49 -0700 (PDT) Received: from tictac2.mtv.corp.google.com ([2620:15c:202:1:24fa:e766:52c9:e3b2]) by smtp.gmail.com with ESMTPSA id u14sm16835807pfm.66.2019.03.18.13.47.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Mar 2019 13:47:48 -0700 (PDT) From: Douglas Anderson To: Steven Rostedt , Ingo Molnar , Jason Wessel , Daniel Thompson Cc: kgdb-bugreport@lists.sourceforge.net, Brian Norris , Douglas Anderson , linux-kernel@vger.kernel.org Subject: [PATCH v5 3/3] tracing: kdb: Allow ftdump to skip all but the last few entries Date: Mon, 18 Mar 2019 13:47:41 -0700 Message-Id: <20190318204741.116550-3-dianders@chromium.org> X-Mailer: git-send-email 2.21.0.225.g810b269d1ac-goog In-Reply-To: <20190318204741.116550-1-dianders@chromium.org> References: <20190318204741.116550-1-dianders@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The 'ftdump' command in kdb is currently a bit of a last resort, at least if you have lots of traces turned on. It's going to print a whole boatload of data out your serial port which is probably running at 115200. This could easily take many, many minutes. Usually you're most interested in what's at the _end_ of the ftrace buffer, AKA what happened most recently. That means you've got to wait the full time for the dump. The 'ftdump' command does attempt to help you a little bit by allowing you to skip a fixed number of entries. Unfortunately it provides no way for you to know how many entries you should skip. Let's do similar to python and allow you to use a negative number to indicate that you want to skip all entries except the last few. This allows you to quickly see what you want. Note that we also change the printout in ftdump to print the (positive) number of entries actually skipped since that could be helpful to know when you've specified a negative skip count. Signed-off-by: Douglas Anderson Acked-by: Daniel Thompson --- Changes in v5: - Only print skipping info if we skipped something (Daniel/Steven) - Add Daniel Thompson Ack. Changes in v4: - Now uses trace_total_entries() / trace_total_entries_cpu(). - Based upon new patch that renames "lines" to "entries". Changes in v3: - Optimize counting as per Steven Rostedt. - Down to 1 patch since patch #1 from v2 landed. kernel/trace/trace_kdb.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/kernel/trace/trace_kdb.c b/kernel/trace/trace_kdb.c index 4b666643d69f..a9fc4f828036 100644 --- a/kernel/trace/trace_kdb.c +++ b/kernel/trace/trace_kdb.c @@ -40,6 +40,8 @@ static void ftrace_dump_buf(int skip_entries, long cpu_file) tr->trace_flags &= ~TRACE_ITER_SYM_USEROBJ; kdb_printf("Dumping ftrace buffer:\n"); + if (skip_entries) + kdb_printf("(skipping %d entries)\n", skip_entries); /* reset all but tr, trace, and overruns */ memset(&iter.seq, 0, @@ -109,6 +111,7 @@ static int kdb_ftdump(int argc, const char **argv) int skip_entries = 0; long cpu_file; char *cp; + int cnt; if (argc > 2) return KDB_ARGCOUNT; @@ -129,6 +132,16 @@ static int kdb_ftdump(int argc, const char **argv) } kdb_trap_printk++; + + /* A negative skip_entries means skip all but the last entries */ + if (skip_entries < 0) { + if (cpu_file == RING_BUFFER_ALL_CPUS) + cnt = trace_total_entries(NULL); + else + cnt = trace_total_entries_cpu(NULL, cpu_file); + skip_entries = max(cnt + skip_entries, 0); + } + ftrace_dump_buf(skip_entries, cpu_file); kdb_trap_printk--; @@ -138,7 +151,8 @@ static int kdb_ftdump(int argc, const char **argv) static __init int kdb_ftrace_register(void) { kdb_register_flags("ftdump", kdb_ftdump, "[skip_#entries] [cpu]", - "Dump ftrace log", 0, KDB_ENABLE_ALWAYS_SAFE); + "Dump ftrace log; -skip dumps last #entries", 0, + KDB_ENABLE_ALWAYS_SAFE); return 0; } -- 2.21.0.225.g810b269d1ac-goog