From debbugs-submit-bounces@debbugs.gnu.org Wed Nov 11 13:47:49 2020 Received: (at 44460) by debbugs.gnu.org; 11 Nov 2020 18:47:49 +0000 Received: from localhost ([127.0.0.1]:42841 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kcv9p-0005tZ-8D for submit@debbugs.gnu.org; Wed, 11 Nov 2020 13:47:49 -0500 Received: from mail-pl1-f180.google.com ([209.85.214.180]:40785) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kcv9n-0005tK-Ng for 44460@debbugs.gnu.org; Wed, 11 Nov 2020 13:47:48 -0500 Received: by mail-pl1-f180.google.com with SMTP id j5so1428287plk.7 for <44460@debbugs.gnu.org>; Wed, 11 Nov 2020 10:47:47 -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=215ukSSHYrZV7ucb7ZXIvmRnsxjJpm1QOrKlpsctBd8=; b=Odrb7k1mS2tn8BtXgc5cGFq7XpKuEEQrGVfTwLDFtctrrkFS0DBlG10796mr0qIaQl V8duxvXeWmL6q3gEKvrv+iLMBSbPvIYTwGzGQu397+4RF18PUDRHCxyKG+E86B6rAss1 xCfiDjBu2eIV61n/fnNmDVo5m9OGOATTTwzym4JLDLAq6dxO2tteK2iUqVPCqAzN9/x1 q86RGhkc/puUzrLWpIua8VvK48zNdxo31yrC78FqEH2Lm6VP6Vo4GOrGpSl8J8mYg246 VYAfNKiyIozsuWr7gNLHdevvSokvu5VdWZ0vF9wXMxMYX3jjjygAjFg8fj0Lfl9OM/Xh hNSg== 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=215ukSSHYrZV7ucb7ZXIvmRnsxjJpm1QOrKlpsctBd8=; b=OE5HLvRu5br7lTrfjSCPbiHzFtebGRKW77lVuNxOWvivCpc5dDdn2ZzLgPOSWWWjUl aLVLfvin8GLccHqjqSzmeQhZBbfA3xu+fSUdkqcUUzLOfwVRk8FvJOqwaUbdTpzh/sMJ KJCvyIR0opDjsJZfwBOaCf8GAoQdQ1I3DzrI3zhGrsD5k5A4InqbdC+9mn2H5BslYUuo jybJxDH0FARelvytWdRzOm5sC3CwOc0R/uEee3xFbher7v6cSQs0xIh7O7N7ysrXj4r6 WW9nWvLiVYebdM+40AgXDa0NJ1f2kxFv009ZIV/5kUBoz0SodR9peHAPR5RtkLLpZTx+ 5j7g== X-Gm-Message-State: AOAM53028LghhvGo1VcXLH44ZVSsXgA0yR6OEd3E0CGPNpL+Q56o1GYz SVLD5OnBuAFDC945AVOw3P9CVjIy01Wktw== X-Google-Smtp-Source: ABdhPJz6vFHs8t5szl3ftsjxfBkETbajWd8fIrb1psI4dFrGYChbWnKk4RdC1pkeTXCoJbuMvyufIw== X-Received: by 2002:a17:902:758d:b029:d6:65a6:c70b with SMTP id j13-20020a170902758db02900d665a6c70bmr8804485pll.30.1605120461495; Wed, 11 Nov 2020 10:47:41 -0800 (PST) Received: from ecenter ([2600:1700:83b0:8bd0::7a8]) by smtp.gmail.com with ESMTPSA id h127sm3500462pfe.16.2020.11.11.10.47.40 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Nov 2020 10:47:40 -0800 (PST) From: John Soo To: Ludovic =?utf-8?Q?Court=C3=A8s?= Subject: Re: [bug#44460] Add copyright lines References: <87o8kcv30a.fsf@asu.edu> <878sbeoya2.fsf@asu.edu> <87k0usn9jk.fsf@gnu.org> <87imabok8j.fsf@asu.edu> <87blg3ojuh.fsf@asu.edu> Date: Wed, 11 Nov 2020 10:47:39 -0800 In-Reply-To: <87blg3ojuh.fsf@asu.edu> (John Soo's message of "Wed, 11 Nov 2020 09:59:34 -0800") Message-ID: <877dqrohmc.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-Debbugs-Envelope-To: 44460 Cc: 44460@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --=-=-= Content-Type: text/plain Oops! I also forget to change the flag names in the docs and the commit message. Fixing those here. - 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 6b3bdfcee7644b36f4e70d9f2529af11e7098333 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 "format" and "list-formats" flag --- doc/guix.texi | 39 +++++++++++ guix/scripts/processes.scm | 132 +++++++++++++++++++++++++++++++------ 2 files changed, 152 insertions(+), 19 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 5e3e0435b4..5dc51a1111 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,44 @@ ClientPID: 19419 ClientCommand: cuirass --cache-directory /var/cache/cuirass @dots{} @end example =20 +Additional options are listed below. + +@table @code +@item --format=3D@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=3Drecutils-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 =20 diff --git a/guix/scripts/processes.scm b/guix/scripts/processes.scm index b4ca7b1687..02515b1c1d 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")) + (display (G_ " + --list-formats display available formats")) + (newline) (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 --=-=-=--