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 UOFSMNckrF8pFQAA0tVLHw (envelope-from ) for ; Wed, 11 Nov 2020 17:52:23 +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 EJsyLNckrF9vXgAA1q6Kng (envelope-from ) for ; Wed, 11 Nov 2020 17:52:23 +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 0539D94014A for ; Wed, 11 Nov 2020 17:52:22 +0000 (UTC) Received: from localhost ([::1]:34748 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcuI9-0002x6-ON for larch@yhetil.org; Wed, 11 Nov 2020 12:52:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33596) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcuHv-0002vD-DA for guix-patches@gnu.org; Wed, 11 Nov 2020 12:52:12 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:59439) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kcuHq-0007qN-N7 for guix-patches@gnu.org; Wed, 11 Nov 2020 12:52:04 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kcuHq-0004Yx-JX for guix-patches@gnu.org; Wed, 11 Nov 2020 12:52:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#44460] Add copyright lines Resent-From: John Soo Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 11 Nov 2020 17:52:02 +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: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: 44460@debbugs.gnu.org Received: via spool by 44460-submit@debbugs.gnu.org id=B44460.160511708017488 (code B ref 44460); Wed, 11 Nov 2020 17:52:02 +0000 Received: (at 44460) by debbugs.gnu.org; 11 Nov 2020 17:51:20 +0000 Received: from localhost ([127.0.0.1]:42752 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kcuH9-0004Xu-9Z for submit@debbugs.gnu.org; Wed, 11 Nov 2020 12:51:19 -0500 Received: from mail-pf1-f175.google.com ([209.85.210.175]:46337) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kcuH7-0004XZ-0J for 44460@debbugs.gnu.org; Wed, 11 Nov 2020 12:51:18 -0500 Received: by mail-pf1-f175.google.com with SMTP id v12so2015332pfm.13 for <44460@debbugs.gnu.org>; Wed, 11 Nov 2020 09:51:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asu-edu.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=2bWkqLiIHppT1CQxGxRxwFF6pisUgimqOCnP6RbHm18=; b=YEZCsLDSv0jV7uxYoIi+QoSwLwtfWAFrVvpThABCd4LskzdF/OsTM5p4xHYqcG992D 6RNxqOLUwYkPA8IdsvgzKuKq5L1egIFeQuGq5r9Fco89mTJb1p5rcjd3eQXdwMKoB2cO rcc8oV7SDQmx2gfeJ4Ne5CwdsFzRNLS0MRtczqdwG+FX85j4DRV+g9wFCfGn1K4JiTlc zS0tDb7MjGq6BC+h4q8TZEg/FLqzxLyKICrwHl70VQ2Z2b0/cAsw1MetegU/rGjf34AP H8qOngj2sh5A7Ps+f2aLoDSBJyMesydN7g702en9nYntURhoWnS34idtk1cjN7WHp1YV ubHQ== 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:references:date:in-reply-to :message-id:user-agent:mime-version; bh=2bWkqLiIHppT1CQxGxRxwFF6pisUgimqOCnP6RbHm18=; b=ClQaKUoTKwiYRLWmK1OdDo7xEudDf8Rl/LzNEBjFMc6K3TNq5wOgR/kpuuN7igaFvZ /ToZq8nE4PLT0HC6k8iu9Fs66WY7he2l1T1NOlAipdAZIElts6IsjfEmKFDGnUxwRQbs aaj+BU9ouyOs+gL6Z8uUaLoLf7/pj6cMNXlABxeCGyy3/MDLPOF5hZvGSqoY9oFtBlL+ 6WjKnLlMtjwSIIF9aELyjHEjPcs9HF0MADAVmH01wJNRM0EHDrYO44hMQVqmG151e3VD Ws/34oJUDcDDFUdOrWuTzzONuYCcJn8PHW154qaTZaZgeYyH0Dka5OLb7dIp+cin9qhF DDvQ== X-Gm-Message-State: AOAM5312v50FEscw+hyNulYZjmNNHoPh1oZYFI0OeFyZjComSi21eGwv owhppomTTVllZMLBXtxOUJ03sDvtTERrVw== X-Google-Smtp-Source: ABdhPJyQOhsXiRfVcVTbw8WCl+yR9DaCCEDauznEuqbc8n68XOop0A7F9UpaX4Ly7awcAJXXx9fRhw== X-Received: by 2002:a05:6a00:2af:b029:18c:5a65:8e0f with SMTP id q15-20020a056a0002afb029018c5a658e0fmr7223351pfs.41.1605117070750; Wed, 11 Nov 2020 09:51:10 -0800 (PST) Received: from ecenter ([2600:1700:83b0:8bd0::7a8]) by smtp.gmail.com with ESMTPSA id a11sm3308493pfn.125.2020.11.11.09.51.08 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Nov 2020 09:51:09 -0800 (PST) From: John Soo References: <87o8kcv30a.fsf@asu.edu> <878sbeoya2.fsf@asu.edu> <87k0usn9jk.fsf@gnu.org> Date: Wed, 11 Nov 2020 09:51:08 -0800 In-Reply-To: <87k0usn9jk.fsf@gnu.org> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Tue, 10 Nov 2020 23:15:11 +0100") Message-ID: <87imabok8j.fsf@asu.edu> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) 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=YEZCsLDS; 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: I8ASGRp8W29j --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello Ludo, Ludovic Court=C3=A8s writes: >> +@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 > > Nice! Right above the example, I=E2=80=99d suggest adding a sentence lik= e =E2=80=9CThe > example below lists=E2=80=A6=E2=80=9D (what does it list actually? :-)). > > In the default format, I wonder if we could already change split > =E2=80=98ChildProcess=E2=80=99 into =E2=80=98ChildPID=E2=80=99 and =E2=80= =98ChildCommand=E2=80=99, as you had initially > proposed on IRC; would that work? I think we could do that, but I had two reasons to use the normalized format instead. * Backwards incompatibility - I didn't want to break any existing scripts that may exist. * Still not normalized - how can I search for just the child processes associated with a particular command? I wouldn't be opposed to splitting ChildProcess into ChildPID and ChildCommand. I would like it best if that change was made in addition to adding the normalized version, since the normalized version allows more functionality. >> +(define (lock->record lock port) >> + (format port "LockHeld: ~a~%" lock)) > > Maybe =E2=80=98lock->recutils=E2=80=99 for consistency and to avoid confu= sion with > Scheme =E2=80=9Crecords=E2=80=9D? Done. >> +(define (format-single-record port) > > Maybe =E2=80=98daemon-sessions->recutils=E2=80=99? Should =E2=80=98sessi= ons=E2=80=99 be a parameter for > clarity? Much better, thank you. I updated the normalized version too. > >> + "Display denormalized session information to PORT." >> + (for-each (lambda (session) >> + (daemon-session->recutils session port) >> + (newline port)) > ^ > Indentation is off. Fixed. >> +(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) > > Please add a docstring. Perhaps make =E2=80=98sessions=E2=80=99 a parame= ter? Done. >> + (define sessions (daemon-sessions)) >> + >> + (format port session-rec-type) > > As reported by =E2=80=98-Wformat=E2=80=99, passing a non-literal format s= tring is risky; > write this instead: > > (display session-rec-type port) Done. >> + (newline port) >> + (newline port) >> + (for-each >> + (lambda (session) > > Preferable indent =E2=80=98for-each=E2=80=99 like so: > > (for-each (lambda (session) Done. > Likewise below. > >> + (display (G_ " >> + --normalize display results as normalized record sets")) > > Should it be =E2=80=98--format=3Dnormalized=E2=80=99 (just like we have = =E2=80=98--format=E2=80=99 in > =E2=80=98guix describe=E2=80=99, for instance)? That makes sense. What do you think of Other changes: * Updated the record descriptors to include the possible fields for sessions. I got some nice guidance from the recutils irc on that. * Put the PID and Command first for the ChildProcess * Add a --list-formats like guix describe has. Thanks! 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 a19828e504288c03c7e17a88ac2a35eb70ab302c 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 | 29 ++++++++ guix/scripts/processes.scm | 132 +++++++++++++++++++++++++++++++------ 2 files changed, 142 insertions(+), 19 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 5e3e0435b4..5df6096f39 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,34 @@ 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. The example below lists the PID of each +ChildProcess and the associated PID for Session that spawned the +ChildProcess where the Session was started using guix build. + +@example +$ guix processes --normalize | \ + recsel \ + -j Session \ + -t ChildProcess \ + -p Session.PID,PID \ + -e 'Session.ClientCommand ~ "guix build'" +PID: 4435 +Session_PID: 4278 + +PID: 4554 +Session_PID: 4278 + +PID: 4646 +Session_PID: 4278 +@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..af1d220774 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->recutils 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->recutils lock port)) (daemon-session-locks-held session)) (for-each (lambda (process) (format port "ChildProcess: ~a:~{ ~a~}~%" @@ -193,19 +196,89 @@ active sessions, and the master 'guix-daemon' process= ." (process-command process))) (daemon-session-children session))) =20 +(define (daemon-sessions->recutils port sessions) + "Display denormalized SESSIONS information to PORT." + (for-each (lambda (session) + (daemon-session->recutils session port) + (newline port)) + sessions)) + +(define session-rec-type + "%rec: Session +%type: PID int +%type: ClientPID int +%key: PID +%mandatory: ClientPID ClientCommand +%allowed: LockHeld") + +(define child-process-rec-type + "%rec: ChildProcess +%type: PID int +%type: Session rec Session +%key: PID +%mandatory: Command") + +(define (session-key->recutils session port) + "Display SESSION PID as a recutils 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 (daemon-sessions->normalized-record port sessions) + "Display SESSIONS recutils on PORT in normalized form" + (display session-rec-type port) + (newline port) + (newline port) + (for-each (lambda (session) + (session-scalars->normalized-record session port) + (for-each (lambda (lock) + (lock->recutils lock port)) + (daemon-session-locks-held session)) + (newline port)) + sessions) + + (display child-process-rec-type port) + (newline port) + (newline port) + (for-each (lambda (session) + (for-each (lambda (process) + (child-process->normalized-record process port) + (newline port) + (session-key->recutils session port) + (newline port) + (newline port)) + (daemon-session-children session))) + sessions)) + ;;; ;;; Options. ;;; =20 -(define %options - (list (option '(#\h "help") #f #f - (lambda args - (show-help) - (exit 0))) - (option '(#\V "version") #f #f - (lambda args - (show-version-and-exit "guix processes"))))) +(define %available-formats + '("recutils" "recutils-normalized")) + +(define (list-formats) + (display (G_ "The available formats are:\n")) + (newline) + (for-each (lambda (f) + (format #t " - ~a~%" f)) + %available-formats)) =20 (define (show-help) (display (G_ "Usage: guix processes @@ -216,8 +289,33 @@ List the current Guix sessions and their processes.")) (display (G_ " -V, --version display version information and exit")) (newline) + (display (G_ " + -f, --format=3DFORMAT display results as normalized record sets")) + (newline) + (display (G_ " + --list-formats display available formats")) (show-bug-report-information)) =20 +(define %options + (list (option '(#\h "help") #f #f + (lambda args + (show-help) + (exit 0))) + (option '(#\V "version") #f #f + (lambda args + (show-version-and-exit "guix processes"))) + (option '(#\f "format") #t #f + (lambda (opt name arg result) + (unless (member arg %available-formats) + (leave (G_ "~a: unsupported output format~%") arg)) + (alist-cons 'format (string->symbol arg) result))) + (option '("list-formats") #f #f + (lambda (opt name arg result) + (list-formats) + (exit 0))))) + +(define %default-options '((format . recutils))) + ;;; ;;; Entry point. @@ -227,17 +325,13 @@ 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 'format) + ('recutils-normalized + (daemon-sessions->normalized-record port (daemon-sessions))) + (_ (daemon-sessions->recutils port (daemon-sessions)))) =20 ;; Pass 'R' (instead of 'r') so 'less' correctly estimates line length. #:less-options "FRX")) --=20 2.29.1 --=-=-=--