Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp3007288ybe; Sun, 15 Sep 2019 05:39:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqylrQu/zSp1E2xyCE25WoBB1yCC3jJ4UiC9JMOKVejgSZBV2UhKbTFUiYJmGRxJjN8D8FFV X-Received: by 2002:aa7:d9d2:: with SMTP id v18mr2318245eds.177.1568551189204; Sun, 15 Sep 2019 05:39:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568551189; cv=none; d=google.com; s=arc-20160816; b=eZGiaTJNO6KVyQyqPcjXfAPdxpQLlN5o+fb+susyhaYLRSG+VCli3XikKtJhbbpvK2 RwRBD9azroz2ipZhvOTFeoxgqvMvmW04rngvVRRif5Jp5GKBirnuTW0w+nuF+ylxfvs5 74sHwS5JkoBvsc5ma16BQxc8YdexNRic0Fdrat74bGNbazI/cpapIgI7C7mnbPBKVUFh +SYDF+lxWX+Ev3PoS+JSyAREXy8m+uFqU/j5lfspum9ApqiHizoro6p8Ixpf1CPCemoM v2Ce26Wk/efb+dpPovnbmZwV6DaBFYi2aEw3ODRQYNEaNYhYdBHLd4Mf4QpIrD7onFoL 76Ag== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=+DlVioqK5uRpVVeZFyNBzYhv8CboJoJINHakxoF0V8I=; b=jsyc3W0QFePjNFtvCpeNXcTaGAFGJqAqEhbdCwd5JmQ0esJb4t2vtyrC7OImh1CIcU w53vuglIpFopOpJOwi9oV0xqaWrfCoAOSmTJIJ4sfOh6kEmCc7QMfVrhU8roUispvZJ9 J3ssrWT8fZbacX1Ox4Ez8tZ7onm12kPV+XzXEea0JmtYcUEqfVBH8DjyoCfHbqDJB0g5 qNp0Qz7pbhBPDVFuJh5TnPFfqqohhma9Vbc/evcCSqqotEQcEZr3WYKi8zFsQOkiAKIJ vwnoBhcjeEsRE0pPGLmDTEgCX+T6yEVEd+oM0Yj0F4no5JaKN2+EeW5RJGvK6UtWjv63 es0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=W7J6BIuq; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qp4si4191250ejb.171.2019.09.15.05.39.00; Sun, 15 Sep 2019 05:39: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=@gmail.com header.s=20161025 header.b=W7J6BIuq; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727984AbfIOK1z (ORCPT + 99 others); Sun, 15 Sep 2019 06:27:55 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:37722 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726264AbfIOK1y (ORCPT ); Sun, 15 Sep 2019 06:27:54 -0400 Received: by mail-pg1-f196.google.com with SMTP id c17so9888471pgg.4 for ; Sun, 15 Sep 2019 03:27:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=+DlVioqK5uRpVVeZFyNBzYhv8CboJoJINHakxoF0V8I=; b=W7J6BIuqiJqwOVGySU2/2sLo7n4L6vpQ8koOf7tgML2ci44KuW7+Z+QeF4EtGlNWor nap+mTsX2lJxE8BN/MkQw+Sa00gHBTpMFqTV5eMQz382sLbN7m6H6TTXn6N9n1vCxOU/ GgVksaLYVvAwgbMcd712Y47yGFFkSXV+mMYKGeo2LWgxdca92htSSarGwomadLnRnveR bD4BquVLrcThJ5BjkiUAVZ1Q/w802R4JsiiuPyIFw1xw6Ba8Y8ySR7eGkvbLC4q8glCZ PHNiumU7GQtEXMWU1XFU8MAUuNJMi3BnBOd0cyx6HrrRB8g0wVxofpxUZMgoH2cBG889 /AGw== 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:mime-version :content-transfer-encoding; bh=+DlVioqK5uRpVVeZFyNBzYhv8CboJoJINHakxoF0V8I=; b=rDRDANOKYuz6lPJBZKWIid6ODsCQOmVSD0Qd+R+VqWdZ3tQtk+YdCD29D/jdDgRiFZ nCy/Qb4cglAXW0jTSoOBb/jHyU/WQ5Gf9E6xPE8/QxgxKBmzcuKdiPe7t38wVOyzXCec QU7Anm3E/3QsVFTX8Ts25LqohGHboCRt0iFIpYYTesiUfhbI6nMXePVQ0LaST5neslLi laGoY+lcykO0zpx6zjdITok+S8aL1FK5KwHHwFQkU97Aj/M48Hi5CQvXWBPhqIUPlQxH RIWDvnGP02j2nacuWUaZAiL1ztqZAHdOyLND4faL4iVhhTyYkR37g/HiHTP5olqHtT7m OTmA== X-Gm-Message-State: APjAAAUbe8Ppeyh/doUAT6TEfdVAgV3L2wlCjWX2s08gg/R5l5yRrPqm XUakKNVxB6lfGwteqVQCOfQ= X-Received: by 2002:a63:6d0:: with SMTP id 199mr20262117pgg.299.1568543273794; Sun, 15 Sep 2019 03:27:53 -0700 (PDT) Received: from localhost.localdomain ([149.28.153.17]) by smtp.gmail.com with ESMTPSA id d190sm10875510pgc.25.2019.09.15.03.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Sep 2019 03:27:51 -0700 (PDT) From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa Cc: Alexander Shishkin , Namhyung Kim , linux-kernel@vger.kernel.org, Changbin Du Subject: [PATCH] perf: add support for logging debug messages to file Date: Sun, 15 Sep 2019 18:27:40 +0800 Message-Id: <20190915102740.24209-1-changbin.du@gmail.com> X-Mailer: git-send-email 2.20.1 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 When in TUI mode, it is impossible to show all the debug messages to console. This make it hard to debug perf issues using debug messages. This patch adds support for logging debug messages to file to resolve this problem. The usage is: perf -debug verbose=2 --debug file=1 COMMAND And the path of log file is '~/perf.log'. Signed-off-by: Changbin Du --- tools/perf/Documentation/perf.txt | 4 +++- tools/perf/util/debug.c | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf.txt b/tools/perf/Documentation/perf.txt index 401f0ed67439..45db7b22d1a5 100644 --- a/tools/perf/Documentation/perf.txt +++ b/tools/perf/Documentation/perf.txt @@ -16,7 +16,8 @@ OPTIONS Setup debug variable (see list below) in value range (0, 10). Use like: --debug verbose # sets verbose = 1 - --debug verbose=2 # sets verbose = 2 + --debug verbose=2 --debug file=1 + # sets verbose = 2 and save log to file List of debug variables allowed to set: verbose - general debug messages @@ -24,6 +25,7 @@ OPTIONS data-convert - data convert command debug messages stderr - write debug output (option -v) to stderr in browser mode + file - write debug output to log file ~/perf.log --buildid-dir:: Setup buildid cache directory. It has higher priority than diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 3780fe42453b..f0b4346a0efa 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -28,6 +29,8 @@ int verbose; bool dump_trace = false, quiet = false; int debug_ordered_events; static int redirect_to_stderr; +static int log_to_file; +static FILE *log_file; int debug_data_convert; int veprintf(int level, int var, const char *fmt, va_list args) @@ -39,6 +42,9 @@ int veprintf(int level, int var, const char *fmt, va_list args) ui_helpline__vshow(fmt, args); else ret = vfprintf(stderr, fmt, args); + + if (log_file) + vfprintf(log_file, fmt, args); } return ret; @@ -180,6 +186,7 @@ static struct debug_variable { { .name = "verbose", .ptr = &verbose }, { .name = "ordered-events", .ptr = &debug_ordered_events}, { .name = "stderr", .ptr = &redirect_to_stderr}, + { .name = "file", .ptr = &log_to_file}, { .name = "data-convert", .ptr = &debug_data_convert }, { .name = NULL, } }; @@ -219,6 +226,19 @@ int perf_debug_option(const char *str) v = -1; *var->ptr = v; + + if (log_to_file) { + char log_path[PATH_MAX]; + + strcat(strcpy(log_path, getenv("HOME")), "/perf.log"); + log_file = fopen(log_path, "a"); + if (!log_file) { + pr_err("Can not create log file: %s\n", strerror(errno)); + free(s); + return -1; + } + } + free(s); return 0; } -- 2.20.1