Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2218727pxu; Sun, 13 Dec 2020 18:08:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJxU1l8N2SNmnnk8w6JHR2gUJat1tlkmaaFwHNRThoTK9rNspqw5/pHoFNOzA83a/eEGAomz X-Received: by 2002:a17:906:1a19:: with SMTP id i25mr20244193ejf.206.1607911705700; Sun, 13 Dec 2020 18:08:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607911705; cv=none; d=google.com; s=arc-20160816; b=DN92h08ug8uOlZU8ArPpAr8zJ0OM/rUT+UDdBWLuUCa0YQ5CCVflrJYiu+JI1fCmr3 fP0PUfI/YlJk+gQFd/8CcFCZc5/s6tWbqpQYL1LE2iFOS6n9wJTg7WkarWamdIUdjxXq 5+UKY4l0t3daMlaOCIbvVnfpo4FYV1zMh7D/n1oOLJgGJvnVjCLVV49jFQm9YpIlmmCQ nSEhp3kBGdvT7ZmvbUJOOWoyY9GFsmkSsF6aVK6WMNAi1eQHKwXnqxXg5lVFQkaecj+x BIJeQOIa2PrSK28cWKIvMkdIBnlNfqCrhVO/jjsh+AxZ2CJ0xuExtju5Djm3ZTX/iZrf Q43g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=1Dqb5eh+0qJXfkP9YGpQQxZBn4XZP+btHiE1BBe8k0Q=; b=GeHFrOLtSHul1P7PE9nZiBjQWZbBBrwO+Gy9lqEVEqOcdiz8zGc6N5oodOQv6HvFEw s7Mv6nQdiza+CZZ/IGT6nl3w8SRh0XCR2KMAh1+cJA22NEHQVfx0444c5wCLZQpolVuG cF4OI0VaXvqtKlwWjfhFjvw+ocRLJ76G7zTnZFBHuc1LgNqbDEW84TdBkn4zQVU8/ayu SAP/O23+YTEmGo84+J4IJWaoYSWIIWzi0mnRVjPv6fVWIvpxMk0jR6lOPlzoZUa2rz8o 7CR/PnuaItuQWIpxJtrCFJjYAS8l2onzg0b3vLAguf5+wGYQcKD9shFGS8mPI62WRB/r POsA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 38si9562222edr.163.2020.12.13.18.07.46; Sun, 13 Dec 2020 18:08:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438681AbgLLKpl convert rfc822-to-8bit (ORCPT + 99 others); Sat, 12 Dec 2020 05:45:41 -0500 Received: from us-smtp-delivery-44.mimecast.com ([207.211.30.44]:57803 "EHLO us-smtp-delivery-44.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2407387AbgLLKpL (ORCPT ); Sat, 12 Dec 2020 05:45:11 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-239-SdKfkgReOQ2d_GF2LQ-0LQ-1; Sat, 12 Dec 2020 05:44:13 -0500 X-MC-Unique: SdKfkgReOQ2d_GF2LQ-0LQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 65BEA10054FF; Sat, 12 Dec 2020 10:44:11 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 544FC7086C; Sat, 12 Dec 2020 10:44:08 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Namhyung Kim , Alexander Shishkin , Michael Petlan , Ian Rogers , Stephane Eranian , Alexei Budankov Subject: [PATCH 2/8] perf tools: Add debug_set_display_time function Date: Sat, 12 Dec 2020 11:43:52 +0100 Message-Id: <20201212104358.412065-3-jolsa@kernel.org> In-Reply-To: <20201212104358.412065-1-jolsa@kernel.org> References: <20201212104358.412065-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset=WINDOWS-1252 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Allow to display time in perf debug output via new debug_set_display_time function. It will be used in perf daemon command to get verbose output into log file. The debug time format is: [2020-12-03 18:25:31.822152] affinity: SYS [2020-12-03 18:25:31.822164] mmap flush: 1 [2020-12-03 18:25:31.822175] comp level: 0 [2020-12-03 18:25:32.002047] mmap size 528384B Signed-off-by: Jiri Olsa --- tools/perf/util/debug.c | 34 +++++++++++++++++++++++++++++++--- tools/perf/util/debug.h | 1 + 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 50fd6a4be4e0..dc148b08814b 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c @@ -10,6 +10,7 @@ #include #include #include +#include #ifdef HAVE_BACKTRACE_SUPPORT #include #endif @@ -31,21 +32,48 @@ int debug_ordered_events; static int redirect_to_stderr; int debug_data_convert; static FILE *debug_file; +bool debug_display_time; void debug_set_file(FILE *file) { debug_file = file; } +void debug_set_display_time(bool set) +{ + debug_display_time = set; +} + +static int fprintf_time(FILE *file) +{ + struct timeval tod; + struct tm ltime; + char date[64]; + + if (!debug_display_time) + return 0; + + if (gettimeofday(&tod, NULL) != 0) + return 0; + + if (localtime_r(&tod.tv_sec, <ime) == NULL) + return 0; + + strftime(date, sizeof(date), "%F %H:%M:%S", <ime); + return fprintf(file, "[%s.%06lu] ", date, tod.tv_usec); +} + int veprintf(int level, int var, const char *fmt, va_list args) { int ret = 0; if (var >= level) { - if (use_browser >= 1 && !redirect_to_stderr) + if (use_browser >= 1 && !redirect_to_stderr) { ui_helpline__vshow(fmt, args); - else - ret = vfprintf(debug_file, fmt, args); + } else { + ret = fprintf_time(debug_file); + ret += vfprintf(debug_file, fmt, args); + } } return ret; diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index 43f712295645..48f631966067 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h @@ -64,6 +64,7 @@ int veprintf(int level, int var, const char *fmt, va_list args); int perf_debug_option(const char *str); void debug_set_file(FILE *file); +void debug_set_display_time(bool set); void perf_debug_setup(void); int perf_quiet_option(void); -- 2.26.2