From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id Rwy8K73dpV/XNQAA0tVLHw (envelope-from ) for ; Fri, 06 Nov 2020 23:35:25 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id UCcqJ73dpV8gbgAA1q6Kng (envelope-from ) for ; Fri, 06 Nov 2020 23:35:25 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 055A69401BE for ; Fri, 6 Nov 2020 23:35:24 +0000 (UTC) Received: from localhost ([::1]:53318 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kbBGM-00041I-AW for larch@yhetil.org; Fri, 06 Nov 2020 18:35:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60260) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kbBG2-000417-6h for guix-patches@gnu.org; Fri, 06 Nov 2020 18:35:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:46048) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kbBG1-0002TC-St for guix-patches@gnu.org; Fri, 06 Nov 2020 18:35:01 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kbBG1-0004n1-Pp for guix-patches@gnu.org; Fri, 06 Nov 2020 18:35:01 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#44460] Add copyright lines References: <87o8kcv30a.fsf@asu.edu> In-Reply-To: <87o8kcv30a.fsf@asu.edu> Resent-From: John Soo Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 06 Nov 2020 23:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44460 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 44460@debbugs.gnu.org Received: via spool by 44460-submit@debbugs.gnu.org id=B44460.160470566518365 (code B ref 44460); Fri, 06 Nov 2020 23:35:01 +0000 Received: (at 44460) by debbugs.gnu.org; 6 Nov 2020 23:34:25 +0000 Received: from localhost ([127.0.0.1]:57594 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kbBFQ-0004m8-IT for submit@debbugs.gnu.org; Fri, 06 Nov 2020 18:34:25 -0500 Received: from mail-pf1-f170.google.com ([209.85.210.170]:34821) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kbBFO-0004lu-9Z for 44460@debbugs.gnu.org; Fri, 06 Nov 2020 18:34:23 -0500 Received: by mail-pf1-f170.google.com with SMTP id g7so2878589pfc.2 for <44460@debbugs.gnu.org>; Fri, 06 Nov 2020 15:34:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asu-edu.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version; bh=6TBqU/FJKpkzZMPJLXaVevTBLWEydoAKWMiknqVQPE4=; b=SneIfqOnQDN6RUwP6rOL5AkRZp9P9cEAHSiC8hL2V8buJJa903Bm++r7Q01+d5kcAk ZLl572HxMWhxcOvh+U3ugLvR7IJLOHvwaRqV1GTstmtz2Il9wri9Uaf+P9l7kwB9+7iB p908IDCnPpEh6gOz2XSkd7lsZJoGAbt09s59zJ51DcwFULEGh4Dtb3rJVI+wtPkqvUA2 RYPO3lttMg0MBtlqhVpRN9j+xstXM6WqiW7fa7HPJN0+UmoBK9tRJG5bwH7U0DBaZ/Y0 eb7TK3aGX4xJ+XDqCaWYfEuz7+4mOBXFzF5J1Rmu8/MUbbkZr3Svu/eSdI/ZKSehconl cYZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=6TBqU/FJKpkzZMPJLXaVevTBLWEydoAKWMiknqVQPE4=; b=JYR7R8s1einktqQ5BdidolnW8+qOYpEE9pJm8bHUBu2vMkkro5VXvOZ26be7/XRMxW I4rv8c+/gZAbpLTACjYetvSOTitKoDXwSrJDxhwkVwSOd8gfYmAUvnkK9E2BFUmJvCM5 fIypDC4SD/vPisB6g7wVDvz4OLrPW/j3r1eZ8Sx4mV+dYEXN8NV41rdnUgSsyqXvl0M/ eiE86QsPX7N8OUqeA1iw0Bjx519bnsrmI3keKSfmKjVbzqOYSmQNaflZ3nQu4SfMZhdy 6LSQThXLZTO3FEzWYxmVKvpyKdOr3QW1naPESLB5Etur8KTj9E9syYmz//8AFBBYBnXS sbzw== X-Gm-Message-State: AOAM530hCPjzou1C/oe/EYHUrVwQRoq3ZEVbgPo65hwd0rBRJCl3eAQb 0dB+zSvZ9LIoxCjKDwYcIVc6OORoxIXcoA== X-Google-Smtp-Source: ABdhPJyKp9eIQuACm0dc6VxjWUpn6d3c7RO3xVwtTXKM3jD46K6DYdChgAfPQna9B4REYCq9do3CwQ== X-Received: by 2002:a17:90a:4a95:: with SMTP id f21mr1786296pjh.223.1604705655572; Fri, 06 Nov 2020 15:34:15 -0800 (PST) Received: from ecenter ([2600:1700:83b0:8bd0::7a8]) by smtp.gmail.com with ESMTPSA id b4sm3255622pfi.208.2020.11.06.15.34.14 for <44460@debbugs.gnu.org> (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 06 Nov 2020 15:34:14 -0800 (PST) From: John Soo Date: Fri, 06 Nov 2020 15:34:13 -0800 Message-ID: <878sbeoya2.fsf@asu.edu> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-Spam-Score: -1.0 (-) X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Scanner: ns3122888.ip-94-23-21.eu Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=asu-edu.20150623.gappssmtp.com header.s=20150623 header.b=SneIfqOn; dmarc=fail reason="SPF not aligned (relaxed)" header.from=asu.edu (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Spam-Score: 0.09 X-TUID: jj8yBC9O7qdM --=-=-= Content-Type: text/plain Sorry, forgot to add my copyright information. - John --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: attachment; filename=0001-processes-Optionally-normalize-recutils-output.patch Content-Transfer-Encoding: quoted-printable >From 48945997d9139ddc5e288512de3dda8d5accaf44 Mon Sep 17 00:00:00 2001 From: John Soo Date: Wed, 4 Nov 2020 07:51:52 -0800 Subject: [PATCH] processes: Optionally normalize recutils output. * guix/scripts/processes.scm: Add "normalize" flag --- doc/guix.texi | 27 ++++++++++ guix/scripts/processes.scm | 105 ++++++++++++++++++++++++++++++++----- 2 files changed, 120 insertions(+), 12 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 5e3e0435b4..116706224e 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -82,6 +82,7 @@ Copyright @copyright{} 2020 Pierre Langlois@* Copyright @copyright{} 2020 pinoaffe@* Copyright @copyright{} 2020 Andr=C3=A9 Batista@* Copyright @copyright{} 2020 Alexandru-Sergiu Marton@* +Copyright @copyright{} 2020 John Soo@* =20 Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -12691,6 +12692,32 @@ ClientPID: 19419 ClientCommand: cuirass --cache-directory /var/cache/cuirass @dots{} @end example =20 +Additional options are listed below. + +@table @code +@item --normalize +Normalize the output records into record sets (@pxref{Record Sets,,, +recutils, GNU recutils manual}). Normalizing into record sets allows +joins across record types. + +@example +$ guix processes --normalize | \ + recsel \ + -j Session \ + -t ChildProcess \ + -p Session.PID,PID \ + -e 'Session.ClientCommand ~ build' +Session_PID: 4278 +PID: 4435 + +Session_PID: 4278 +PID: 4554 + +Session_PID: 4278 +PID: 4646 +@end example +@end table + @node System Configuration @chapter System Configuration =20 diff --git a/guix/scripts/processes.scm b/guix/scripts/processes.scm index b4ca7b1687..10fda9f223 100644 --- a/guix/scripts/processes.scm +++ b/guix/scripts/processes.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright =C2=A9 2018, 2019, 2020 Ludovic Court=C3=A8s +;;; Copyright =C2=A9 2020 John Soo ;;; ;;; This file is part of GNU Guix. ;;; @@ -176,6 +177,9 @@ active sessions, and the master 'guix-daemon' process." (values (filter-map child-process->session children) master))) =20 +(define (lock->record lock port) + (format port "LockHeld: ~a~%" lock)) + (define (daemon-session->recutils session port) "Display SESSION information in recutils format on PORT." (format port "SessionPID: ~a~%" @@ -184,8 +188,7 @@ active sessions, and the master 'guix-daemon' process." (process-id (daemon-session-client session))) (format port "ClientCommand:~{ ~a~}~%" (process-command (daemon-session-client session))) - (for-each (lambda (lock) - (format port "LockHeld: ~a~%" lock)) + (for-each (lambda (lock) (lock->record lock port)) (daemon-session-locks-held session)) (for-each (lambda (process) (format port "ChildProcess: ~a:~{ ~a~}~%" @@ -193,6 +196,81 @@ active sessions, and the master 'guix-daemon' process." (process-command process))) (daemon-session-children session))) =20 +(define (format-single-record port) + "Display denormalized session information to PORT." + (for-each (lambda (session) + (daemon-session->recutils session port) + (newline port)) + (daemon-sessions))) + +(define session-rec-type + ;; Also includes ClientCommand and LockHeld but it doesn't seem to be + ;; possible to express a plain string field (the default) without further + ;; restrictions + "%rec: Session +%type: PID int +%type: ClientPID int +%key: PID") + +(define child-process-rec-type + ;; Also includes Command but it doesn't seem to be possible to + ;; express a plain string field (the default) without further restrictio= ns + "%rec: ChildProcess +%type: Session rec Session +%type: PID int +%key: PID") + +(define (session-key->field session port) + "Display SESSION PID as field on PORT." + (format + port "Session: ~a" + (process-id (daemon-session-process session)))) + +(define (session-scalars->normalized-record session port) + "Display SESSION scalar fields to PORT in normalized form." + (format port "PID: ~a~%" + (process-id (daemon-session-process session))) + (format port "ClientPID: ~a~%" + (process-id (daemon-session-client session))) + (format port "ClientCommand:~{ ~a~}~%" + (process-command (daemon-session-client session)))) + +(define (child-process->normalized-record process port) + "Display PROCESS record on PORT in normalized form" + (format port "PID: ~a" (process-id process)) + (newline port) + (format port "Command:~{ ~a~}" (process-command process))) + +(define (format-normalized port) + (define sessions (daemon-sessions)) + + (format port session-rec-type) + (newline port) + (newline port) + (for-each + (lambda (session) + (session-scalars->normalized-record session port) + (for-each + (lambda (lock) (lock->record lock port)) + (daemon-session-locks-held session)) + (newline port)) + sessions) + + (format port child-process-rec-type) + (newline port) + (newline port) + (for-each + (lambda (session) + (for-each + (lambda (process) + (session-key->field session port) + (newline port) + (child-process->normalized-record process port) + (newline port) + (newline port)) + (daemon-session-children session))) + sessions)) + ;;; ;;; Options. @@ -205,7 +283,10 @@ active sessions, and the master 'guix-daemon' process." (exit 0))) (option '(#\V "version") #f #f (lambda args - (show-version-and-exit "guix processes"))))) + (show-version-and-exit "guix processes"))) + (option '("normalize") #f #f + (lambda (opt name arg result) + (alist-cons 'normalize #t result))))) =20 (define (show-help) (display (G_ "Usage: guix processes @@ -216,8 +297,13 @@ List the current Guix sessions and their processes.")) (display (G_ " -V, --version display version information and exit")) (newline) + (display (G_ " + --normalize display results as normalized record sets")) + (newline) (show-bug-report-information)) =20 +(define %default-options '()) + ;;; ;;; Entry point. @@ -227,17 +313,12 @@ List the current Guix sessions and their processes.")) (category plumbing) (synopsis "list currently running sessions") (define options - (args-fold* args %options - (lambda (opt name arg result) - (leave (G_ "~A: unrecognized option~%") name)) - cons - '())) + (parse-command-line args %options (list %default-options))) =20 (with-paginated-output-port port - (for-each (lambda (session) - (daemon-session->recutils session port) - (newline port)) - (daemon-sessions)) + (match (assoc-ref options 'normalize) + (#t (format-normalized port)) + (_ (format-single-record port))) =20 ;; Pass 'R' (instead of 'r') so 'less' correctly estimates line length. #:less-options "FRX")) --=20 2.29.1 --=-=-=--