From nobody Tue May 21 14:07:05 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1607406759; cv=none; d=zohomail.com; s=zohoarc; b=hysDypuQSYvr+4KUNkqrhWW7wlg/AjZFzTQEGUA6PUbahQSY93fdvt8nI78CZMGGso2MEFDsHBGF1NE7Tk02IE5umZ3eX+JTD9WnxYAZxgs12dE+grMYcsH5mIs19DQzuVcgSIHDVsarMaA7I5NjYTbu+/9fvYHrOWpx0ag4ges= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607406759; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=ItesgZKA2nD/xUa2XNEu0eqFuyuHd9edR9sJmEeeyII=; b=BzzMh6Y91Mz/kmZOyH8CftxdVXPQAAkDVM3A4ctOMYY0K/cgiaYjI1XjpmB0b+e4PA8WQ6zjQr8ZGePT+n/kmHXzViPIlc904X7vP79XRYxZBvLP1iY1KicDAf9+ALq2GAUIUxoNtBo0in0DN4RZc+WhvO+5koYcP7FD1T8Eb4M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160740675923438.83804200239831; Mon, 7 Dec 2020 21:52:39 -0800 (PST) Received: from localhost ([::1]:56800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kmVvR-0003JJ-HG for importer@patchew.org; Tue, 08 Dec 2020 00:52:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kmVtp-0002Z4-RU for qemu-devel@nongnu.org; Tue, 08 Dec 2020 00:50:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:55181) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kmVtn-0003Z8-Az for qemu-devel@nongnu.org; Tue, 08 Dec 2020 00:50:57 -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-547-RoNy10e1OFOrjNdiuDIBFw-1; Tue, 08 Dec 2020 00:50:52 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 813C28049C1 for ; Tue, 8 Dec 2020 05:50:51 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-112-30.ams2.redhat.com [10.36.112.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 89C925D9DE; Tue, 8 Dec 2020 05:50:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607406654; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ItesgZKA2nD/xUa2XNEu0eqFuyuHd9edR9sJmEeeyII=; b=CiplvzyRibiV1iArCIYrbDyxxL8kTJdki2ZDjg0vX7fjc2LNj3Ij706/54RpShbpOsGb6e Bq8qC4py5BIlxJa0jObkgMjWu5tet0meFAAZ7x/U6ZzVq2QIvIMj87UBYoJLX4KnqnjWwh ENNdm3r6Dbu5rdZCanBpMw/kdVuFSj0= X-MC-Unique: RoNy10e1OFOrjNdiuDIBFw-1 From: Laszlo Ersek To: qemu-devel@nongnu.org, virtio-fs@redhat.com Subject: [PATCH] virtiofsd: make the debug log timestamp on stderr more human-readable Date: Tue, 8 Dec 2020 06:50:43 +0100 Message-Id: <20201208055043.31548-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=lersek@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=216.205.24.124; envelope-from=lersek@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MIME_BASE64_TEXT=1.741, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Dr. David Alan Gilbert" , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The current timestamp format doesn't help me visually notice small jumps in time ("small" as defined on human scale, such as a few seconds or a few ten seconds). Replace it with a local time format where such differences stand out. Before: > [13316826770337] [ID: 00000004] unique: 62, opcode: RELEASEDIR (29), node= id: 1, insize: 64, pid: 1 > [13316826778175] [ID: 00000004] unique: 62, success, outsize: 16 > [13316826781156] [ID: 00000004] virtio_send_msg: elem 0: with 1 in desc o= f length 16 > [15138279317927] [ID: 00000001] virtio_loop: Got VU event > [15138279504884] [ID: 00000001] fv_queue_set_started: qidx=3D1 started=3D0 > [15138279519034] [ID: 00000003] fv_queue_thread: kill event on queue 1 - = quitting > [15138280876463] [ID: 00000001] fv_remove_watch: TODO! fd=3D9 > [15138280897381] [ID: 00000001] virtio_loop: Waiting for VU event > [15138280946834] [ID: 00000001] virtio_loop: Got VU event > [15138281175421] [ID: 00000001] virtio_loop: Waiting for VU event > [15138281182387] [ID: 00000001] virtio_loop: Got VU event > [15138281189474] [ID: 00000001] virtio_loop: Waiting for VU event > [15138309321936] [ID: 00000001] virtio_loop: Unexpected poll revents 11 > [15138309434150] [ID: 00000001] virtio_loop: Exit (Notice how you don't (easily) notice the gap in time after "virtio_send_msg", and especially the amount of time passed is hard to estimate.) After: > [2020-12-08 06:43:22.58+0100] [ID: 00000004] unique: 51, opcode: RELEASED= IR (29), nodeid: 1, insize: 64, pid: 1 > [2020-12-08 06:43:22.58+0100] [ID: 00000004] unique: 51, success, outs= ize: 16 > [2020-12-08 06:43:22.58+0100] [ID: 00000004] virtio_send_msg: elem 0: wit= h 1 in desc of length 16 > [2020-12-08 06:43:29.34+0100] [ID: 00000001] virtio_loop: Got VU event > [2020-12-08 06:43:29.34+0100] [ID: 00000001] fv_queue_set_started: qidx= =3D1 started=3D0 > [2020-12-08 06:43:29.34+0100] [ID: 00000003] fv_queue_thread: kill event = on queue 1 - quitting > [2020-12-08 06:43:29.34+0100] [ID: 00000001] fv_remove_watch: TODO! fd=3D9 > [2020-12-08 06:43:29.34+0100] [ID: 00000001] virtio_loop: Waiting for VU = event > [2020-12-08 06:43:29.34+0100] [ID: 00000001] virtio_loop: Got VU event > [2020-12-08 06:43:29.34+0100] [ID: 00000001] virtio_loop: Waiting for VU = event > [2020-12-08 06:43:29.34+0100] [ID: 00000001] virtio_loop: Got VU event > [2020-12-08 06:43:29.34+0100] [ID: 00000001] virtio_loop: Waiting for VU = event > [2020-12-08 06:43:29.37+0100] [ID: 00000001] virtio_loop: Unexpected poll= revents 11 > [2020-12-08 06:43:29.37+0100] [ID: 00000001] virtio_loop: Exit Cc: "Dr. David Alan Gilbert" Cc: Stefan Hajnoczi Signed-off-by: Laszlo Ersek Reviewed-by: Dr. David Alan Gilbert --- tools/virtiofsd/passthrough_ll.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tools/virtiofsd/passthrough_ll.c b/tools/virtiofsd/passthrough= _ll.c index 48a109d3f682..06543b20dcbb 100644 --- a/tools/virtiofsd/passthrough_ll.c +++ b/tools/virtiofsd/passthrough_ll.c @@ -3311,18 +3311,38 @@ static void setup_nofile_rlimit(unsigned long rlimi= t_nofile) static void log_func(enum fuse_log_level level, const char *fmt, va_list a= p) { g_autofree char *localfmt =3D NULL; + struct timespec ts; + struct tm tm; + char sec_fmt[sizeof "2020-12-07 18:17:54"]; + char zone_fmt[sizeof "+0100"]; =20 if (current_log_level < level) { return; } =20 if (current_log_level =3D=3D FUSE_LOG_DEBUG) { - if (!use_syslog) { - localfmt =3D g_strdup_printf("[%" PRId64 "] [ID: %08ld] %s", - get_clock(), syscall(__NR_gettid), = fmt); - } else { + if (use_syslog) { + /* no timestamp needed */ localfmt =3D g_strdup_printf("[ID: %08ld] %s", syscall(__NR_ge= ttid), fmt); + } else { + /* try formatting a broken-down timestamp */ + if (clock_gettime(CLOCK_REALTIME, &ts) !=3D -1 && + localtime_r(&ts.tv_sec, &tm) !=3D NULL && + strftime(sec_fmt, sizeof sec_fmt, "%Y-%m-%d %H:%M:%S", + &tm) !=3D 0 && + strftime(zone_fmt, sizeof zone_fmt, "%z", &tm) !=3D 0) { + localfmt =3D g_strdup_printf("[%s.%02ld%s] [ID: %08ld] %s", + sec_fmt, + ts.tv_nsec / (10L * 1000 * 1000= ), + zone_fmt, syscall(__NR_gettid), + fmt); + } else { + /* fall back to a flat timestamp */ + localfmt =3D g_strdup_printf("[%" PRId64 "] [ID: %08ld] %s= ", + get_clock(), syscall(__NR_getti= d), + fmt); + } } fmt =3D localfmt; } @@ -3452,6 +3472,9 @@ int main(int argc, char *argv[]) struct lo_map_elem *reserve_elem; int ret =3D -1; =20 + /* Initialize time conversion information for localtime_r(). */ + tzset(); + /* Don't mask creation mode, kernel already did that */ umask(0); =20 --=20 2.19.1.3.g30247aa5d201