From patchwork Fri Nov 13 05:33:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: John Soo X-Patchwork-Id: 25107 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 2532F27BBF6; Fri, 13 Nov 2020 05:35:11 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, T_DKIM_INVALID,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 85C8427BBF4 for ; Fri, 13 Nov 2020 05:35:09 +0000 (GMT) Received: from localhost ([::1]:59384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kdRjo-00063p-Nq for patchwork@mira.cbaines.net; Fri, 13 Nov 2020 00:35:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33558) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kdRji-00063j-9z for guix-patches@gnu.org; Fri, 13 Nov 2020 00:35:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:34894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kdRji-0003o3-0W for guix-patches@gnu.org; Fri, 13 Nov 2020 00:35:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kdRjh-0007fS-Uu for guix-patches@gnu.org; Fri, 13 Nov 2020 00:35:01 -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: Fri, 13 Nov 2020 05: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: Ludovic =?utf-8?q?Court=C3=A8s?= Cc: 44460@debbugs.gnu.org Received: via spool by 44460-submit@debbugs.gnu.org id=B44460.160524564629395 (code B ref 44460); Fri, 13 Nov 2020 05:35:01 +0000 Received: (at 44460) by debbugs.gnu.org; 13 Nov 2020 05:34:06 +0000 Received: from localhost ([127.0.0.1]:46439 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kdRin-0007e2-UE for submit@debbugs.gnu.org; Fri, 13 Nov 2020 00:34:06 -0500 Received: from mail-pg1-f178.google.com ([209.85.215.178]:41997) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kdRik-0007dV-1l for 44460@debbugs.gnu.org; Fri, 13 Nov 2020 00:34:04 -0500 Received: by mail-pg1-f178.google.com with SMTP id i13so6188753pgm.9 for <44460@debbugs.gnu.org>; Thu, 12 Nov 2020 21:34:01 -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=2nzcpuRH4B7VAFWKFqtmbPZhi1O8Mx8ARekMqjaSyKI=; b=LSZ5qBq9fgM8EhF6YgnsyLaEKrOsu9QAHSLqNexKnXhH3QzptD4CuREhjYA79WfMHY PxEo2rtieu6Ker9kqOR0Y31gVxZGSXttNZQncWtQbALpcewDpMYz2LAz/ZHXSYZCxNvX 0e7hI90y1nHNtDCoY67hIp6h8OLOx+uFdBi4Y1hZwwYPFXYObrGs4yGm/nRmf5pVBdoE bmgJDeef/VyfUFHx0BsNE+5udXKQ4TNK25i9LbZWg9Qz5s7+wzBeIm4UaApXOCDjlZmz toTRKf9myj0CY3+J9bimRI5d03RJE78Pl9+sVaGztFApdZ9LPi5loZdW3IPuopW2vKQ1 9bxQ== 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=2nzcpuRH4B7VAFWKFqtmbPZhi1O8Mx8ARekMqjaSyKI=; b=MI46t9tpiWhz+KJujZzLEOXONXqUkQYuKC9uLll+WjBZThzajBxrCi4Vvakw01zHzN ReXmdmxsqSOwPqewXSdBDISMwAflr50cbCZ1Bt+d5b0+HwnhnGkjeyBTmV4pGhuItukg KxRnXJRX4lRWZgqH23iM+O5paGcFfRFujcLodzcf2BSK8ObxnuuOBQvhTmrtg/ExDe8k aCZaRamrfTIXbkeT4w7srPiqD/TcB1zrSs4yuu2nN9G4nvWtblAk8er3QnswjRwhNhjl 25ogj65td579dJXG5cD/NyG0jZEpF1B2J8+CYKmOIPpVymCoi/W9ja+gLaiVYBwyIRnk XWOg== X-Gm-Message-State: AOAM5331IM+ldkbN4OWlVZGCJ0FGLn/rxnLQGoxzQnLW5l8ggZEY0MdI zNAims8O6B805zG/PhuwWek6zzYaadRv6A== X-Google-Smtp-Source: ABdhPJw8iRtO2c1BzHSHwTvzK7ABHmaujdxoGAZUdOO9EmbGlDKXG04YpD6YgR5w0+aVhzBc4ctZwA== X-Received: by 2002:a63:5509:: with SMTP id j9mr767280pgb.3.1605245635785; Thu, 12 Nov 2020 21:33:55 -0800 (PST) Received: from ecenter ([2600:1700:83b0:8bd0::7a8]) by smtp.gmail.com with ESMTPSA id e6sm8351075pfn.190.2020.11.12.21.33.53 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Nov 2020 21:33:54 -0800 (PST) From: John Soo References: <87o8kcv30a.fsf@asu.edu> <878sbeoya2.fsf@asu.edu> <87k0usn9jk.fsf@gnu.org> <87imabok8j.fsf@asu.edu> <87ft5elu45.fsf@gnu.org> <87361eoabg.fsf@asu.edu> <871rgyiajk.fsf@gnu.org> Date: Thu, 12 Nov 2020 21:33:52 -0800 In-Reply-To: <871rgyiajk.fsf@gnu.org> ("Ludovic =?utf-8?q?Court=C3=A8s?= "'s message of "Thu, 12 Nov 2020 21:29:19 +0100") Message-ID: <87pn4hn7lr.fsf@asu.edu> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Hi Ludo, Ludovic Courtès writes: > Yes it does! Initially I wondered if it was a term used in recutils, > but apparently it’s not. Do you think it is the best term to use? >> An aside - Probably to be entirely honest about normalizing the output, >> locks really would be in a separate record set too. > > Yeah. I made Lock a separate record set. This exposes a limitation with recutils. It is not possible to join more than two record sets together (though they mentioned it as a goal on IRC). >> Another challenge is making sure the user can understand what >> "normalized" means. I am not sure readers of the manual/cli help will >> be able to infer what it means from context. On the other hand, it is >> such a small use case that it seems imbalanced to provide a lot of >> background for the term "normal". What do you think? > > Sure. > > Thinking more about it, to me the appeal of recutils is that it’s both > human- and machine-readable. But here we end up having a specific > machine-readable variant. But yeah, maybe that’s unavoidable. I suppose the normalized version is a little less human-readable. It would be behind a flag, though. Is that a reasonable compromise? After some thought I realize that the normalized version isn't that much more useful than the default, but it does enable things like: ---- Example ---- $ guix processes -f normalized \ | recsel \ -t ChildProcess \ -j Session \ -p PID,Session.PID \ | recfmt '{{PID}} {{Session.PID}}' 23607 2356724713 2356725002 23576 ---- Example ---- This will format all the (PID, Session) pairs. Whereas the non-normalized version would only print one PID given the following. ---- Example ---- $ guix processes \ | recsel -p ChildPID,SessionPID \ | recfmt '{{ChildPID}} {{SessionPID}}' 23607 23567 --- >>>> 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. >>> >>> I would think it’s OK to break compatibility on just these >>> “ChildProcess” fields. >> >> Ok. Would it be ok if I put that in a separate commit? > > Yes (you mean in addition to ‘-f normalized’, right?). I changed ChildProcess: pid: command to ChildPID and ChildCommand in the default in a separate commit. Thanks again, John From 81cdc826a89b4f5ee480faa620f3e8f3e12d8979 Mon Sep 17 00:00:00 2001 From: John Soo Date: Wed, 4 Nov 2020 07:51:52 -0800 Subject: [PATCH 2/2] processes: Optionally normalize recutils output. * guix/scripts/processes.scm: Add "format" and "list-formats" flag. * doc/guix.texi: Document new flags. --- doc/guix.texi | 38 ++++++++++ guix/scripts/processes.scm | 144 ++++++++++++++++++++++++++++++++----- 2 files changed, 163 insertions(+), 19 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index e8814c686c..7da24977cc 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -12695,6 +12695,44 @@ ClientPID: 19419 ClientCommand: cuirass --cache-directory /var/cache/cuirass @dots{} @end example +Additional options are listed below. + +@table @code +@item --format=@var{format} +@itemx -f @var{format} +Produce output in the specified @var{format}, one of: + +@table @code +@item recutils +The default option. It outputs a set of Session recutils records +that include each ChildProcess as a field. + +@item recutils-normalized +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 --format=recutils-normalized | \ + 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 +@end table + @node System Configuration @chapter System Configuration diff --git a/guix/scripts/processes.scm b/guix/scripts/processes.scm index 3a7ea0b89c..bcc541badb 100644 --- a/guix/scripts/processes.scm +++ b/guix/scripts/processes.scm @@ -177,6 +177,9 @@ active sessions, and the master 'guix-daemon' process." (values (filter-map child-process->session children) master))) +(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~%" @@ -185,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 "ChildPID: ~a~%" @@ -195,19 +197,102 @@ active sessions, and the master 'guix-daemon' process." (process-command process))) (daemon-session-children session))) +(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") + +(define lock-rec-type + "%rec: Lock +%mandatory: LockHeld +%type: Session rec Session") + +(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) + (newline port)) + sessions) + + (display lock-rec-type port) + (newline port) + (newline port) + (for-each (lambda (session) + (for-each (lambda (lock) + (lock->recutils "testing testing" port) + (session-key->recutils session port) + (newline port) + (newline port)) + (daemon-session-locks-held session))) + 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. ;;; -(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" "normalized")) + +(define (list-formats) + (display (G_ "The available formats are:\n")) + (newline) + (for-each (lambda (f) + (format #t " - ~a~%" f)) + %available-formats)) (define (show-help) (display (G_ "Usage: guix processes @@ -218,8 +303,33 @@ List the current Guix sessions and their processes.")) (display (G_ " -V, --version display version information and exit")) (newline) + (display (G_ " + -f, --format=FORMAT display results as normalized record sets")) + (display (G_ " + --list-formats display available formats")) + (newline) (show-bug-report-information)) +(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. @@ -229,17 +339,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))) (with-paginated-output-port port - (for-each (lambda (session) - (daemon-session->recutils session port) - (newline port)) - (daemon-sessions)) + (match (assoc-ref options 'format) + ('normalized + (daemon-sessions->normalized-record port (daemon-sessions))) + (_ (daemon-sessions->recutils port (daemon-sessions)))) ;; Pass 'R' (instead of 'r') so 'less' correctly estimates line length. #:less-options "FRX")) -- 2.29.1