aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland Winkler2008-12-29 06:13:36 +0000
committerRoland Winkler2008-12-29 06:13:36 +0000
commit48152a7052db7c8a2af8d809aee6b1628a856305 (patch)
tree56106aa8d559b25b8ad7c3f0557b8c97db9c5aa1
parent53374291b7f24cdbd7653c447984c1dbd83fdebc (diff)
downloademacs-48152a7052db7c8a2af8d809aee6b1628a856305.tar.gz
emacs-48152a7052db7c8a2af8d809aee6b1628a856305.zip
(proced-temp-alist): Renamed from variable proced-children-alist.
(proced-process-tree, proced-toggle-tree): Fix docstring. (proced-tree): Fix docstring. Simplify. Use proced-temp-alist. (proced-temp-internal): Use proced-temp-alist.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/proced.el133
2 files changed, 85 insertions, 56 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index a388847b6b5..da44ee9d560 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12008-12-29 Roland Winkler <Roland.Winkler@physik.uni-erlangen.de>
2
3 * proced.el (proced-temp-alist): Renamed from variable
4 proced-children-alist.
5 (proced-process-tree, proced-toggle-tree): Fix docstring.
6 (proced-tree): Fix docstring. Simplify. Use proced-temp-alist.
7 (proced-temp-internal): Use proced-temp-alist.
8
12008-12-29 Dan Nicolaescu <dann@ics.uci.edu> 92008-12-29 Dan Nicolaescu <dann@ics.uci.edu>
2 10
3 * subr.el (mkdir): New defalias. 11 * subr.el (mkdir): New defalias.
diff --git a/lisp/proced.el b/lisp/proced.el
index 9b79a8046d8..cc453b526d1 100644
--- a/lisp/proced.el
+++ b/lisp/proced.el
@@ -31,9 +31,6 @@
31;; - interactive temporary customizability of flags in `proced-grammar-alist' 31;; - interactive temporary customizability of flags in `proced-grammar-alist'
32;; - allow "sudo kill PID", "renice PID" 32;; - allow "sudo kill PID", "renice PID"
33;; 33;;
34;; Wishlist
35;; - tree view like pstree(1)
36;;
37;; Thoughts and Ideas 34;; Thoughts and Ideas
38;; - Currently, `system-process-attributes' returns the list of 35;; - Currently, `system-process-attributes' returns the list of
39;; command-line arguments of a process as one concatenated string. 36;; command-line arguments of a process as one concatenated string.
@@ -402,8 +399,8 @@ Important: the match ends just after the marker.")
402 "Headers in Proced buffer as a string.") 399 "Headers in Proced buffer as a string.")
403(make-variable-buffer-local 'proced-header-line) 400(make-variable-buffer-local 'proced-header-line)
404 401
405(defvar proced-children-alist nil 402(defvar proced-temp-alist nil
406 "Children alist of process listing (internal variable).") 403 "Temporary alist (internal variable).")
407 404
408(defvar proced-process-tree nil 405(defvar proced-process-tree nil
409 "Proced process tree (internal variable).") 406 "Proced process tree (internal variable).")
@@ -903,11 +900,39 @@ Set variable `proced-filter' to SCHEME. Revert listing."
903 (setq proced-filter scheme) 900 (setq proced-filter scheme)
904 (proced-update t))) 901 (proced-update t)))
905 902
903(defun proced-filter-parents (process-alist pid &optional omit-pid)
904 "For PROCESS-ALIST return list of parent processes of PID.
905This list includes PID unless OMIT-PID is non-nil."
906 (let ((parent-list (unless omit-pid (list (assq pid process-alist))))
907 (process (assq pid process-alist))
908 ppid)
909 (while (and (setq ppid (cdr (assq 'ppid (cdr process))))
910 ;; Ignore a PPID that equals PID.
911 (/= ppid pid)
912 ;; Accept only PPIDs that correspond to members in PROCESS-ALIST.
913 (setq process (assq ppid process-alist)))
914 (setq pid ppid)
915 (push process parent-list))
916 parent-list))
917
918(defun proced-filter-children (process-alist ppid &optional omit-ppid)
919 "For PROCESS-ALIST return list of child processes of PPID.
920This list includes PPID unless OMIT-PPID is non-nil."
921 (let ((proced-temp-alist (proced-children-alist process-alist))
922 new-alist)
923 (dolist (pid (proced-children-pids ppid))
924 (push (assq pid process-alist) new-alist))
925 (if omit-ppid
926 (assq-delete-all ppid new-alist)
927 new-alist)))
928
929;;; Process tree
930
906(defun proced-children-alist (process-alist) 931(defun proced-children-alist (process-alist)
907 "Return children alist for PROCESS-ALIST. 932 "Return children alist for PROCESS-ALIST.
908The children alist has elements (PPID PID1 PID2 ...). 933The children alist has elements (PPID PID1 PID2 ...).
909PPID is a parent PID. PID1, PID2, ... are the child processes of PPID. 934PPID is a parent PID. PID1, PID2, ... are the child processes of PPID.
910The children alist inherits the sorting order from PROCESS-ALIST. 935The children alist inherits the sorting order of PROCESS-ALIST.
911The list of children does not include grandchildren." 936The list of children does not include grandchildren."
912 ;; The PPIDs inherit the sorting order of PROCESS-ALIST. 937 ;; The PPIDs inherit the sorting order of PROCESS-ALIST.
913 (let ((process-tree (mapcar (lambda (a) (list (car a))) process-alist)) 938 (let ((process-tree (mapcar (lambda (a) (list (car a))) process-alist))
@@ -929,11 +954,22 @@ The list of children does not include grandchildren."
929 (mapcar (lambda (a) (cons (car a) (nreverse (cdr a)))) 954 (mapcar (lambda (a) (cons (car a) (nreverse (cdr a))))
930 process-tree)))) 955 process-tree))))
931 956
957(defun proced-children-pids (ppid)
958 "Return list of children PIDs of PPID (including PPID)."
959 (let ((cpids (cdr (assq ppid proced-temp-alist))))
960 (if cpids
961 (cons ppid (apply 'append (mapcar 'proced-children-pids cpids)))
962 (list ppid))))
963
932(defun proced-process-tree (process-alist) 964(defun proced-process-tree (process-alist)
933 "Return process tree for PROCESS-ALIST." 965 "Return process tree for PROCESS-ALIST.
934 (let ((proced-children-alist (proced-children-alist process-alist)) 966It is an alist of alists where the car of each alist is a parent process
967and the cdr is a list of child processes according to the ppid attribute
968of these processes.
969The process tree inherits the sorting order of PROCESS-ALIST."
970 (let ((proced-temp-alist (proced-children-alist process-alist))
935 pid-alist proced-process-tree) 971 pid-alist proced-process-tree)
936 (while (setq pid-alist (pop proced-children-alist)) 972 (while (setq pid-alist (pop proced-temp-alist))
937 (push (proced-process-tree-internal pid-alist) proced-process-tree)) 973 (push (proced-process-tree-internal pid-alist) proced-process-tree))
938 (nreverse proced-process-tree))) 974 (nreverse proced-process-tree)))
939 975
@@ -941,12 +977,12 @@ The list of children does not include grandchildren."
941 "Helper function for `proced-process-tree'." 977 "Helper function for `proced-process-tree'."
942 (let ((cpid-list (cdr pid-alist)) cpid-alist cpid) 978 (let ((cpid-list (cdr pid-alist)) cpid-alist cpid)
943 (while (setq cpid (car cpid-list)) 979 (while (setq cpid (car cpid-list))
944 (if (setq cpid-alist (assq cpid proced-children-alist)) 980 (if (setq cpid-alist (assq cpid proced-temp-alist))
945 ;; Unprocessed part of process tree that needs to be 981 ;; Unprocessed part of process tree that needs to be
946 ;; analyzed recursively. 982 ;; analyzed recursively.
947 (progn 983 (progn
948 (setq proced-children-alist 984 (setq proced-temp-alist
949 (assq-delete-all cpid proced-children-alist)) 985 (assq-delete-all cpid proced-temp-alist))
950 (setcar cpid-list (proced-process-tree-internal cpid-alist))) 986 (setcar cpid-list (proced-process-tree-internal cpid-alist)))
951 ;; We already processed this subtree and take it "as is". 987 ;; We already processed this subtree and take it "as is".
952 (setcar cpid-list (assq cpid proced-process-tree)) 988 (setcar cpid-list (assq cpid proced-process-tree))
@@ -956,9 +992,18 @@ The list of children does not include grandchildren."
956 pid-alist) 992 pid-alist)
957 993
958(defun proced-toggle-tree (arg) 994(defun proced-toggle-tree (arg)
959 "Change whether this Proced buffer is displayed as process tree. 995 "Toggle the display of the process listing as process tree.
960With prefix ARG, display as process tree if ARG is positive, otherwise 996With prefix ARG, display as process tree if ARG is positive, otherwise
961do not display as process tree. Sets the variable `proced-tree-flag'." 997do not display as process tree. Sets the variable `proced-tree-flag'.
998
999The process tree is generated from the selected processes in the
1000Proced buffer (that is, the processes in `proced-process-alist').
1001All processes that do not have a parent process in this list
1002according to their ppid attribute become the root of a process tree.
1003Each parent process is followed by its child processes.
1004The process tree inherits the chosen sorting order of the process listing,
1005that is, child processes of the same parent process are sorted using
1006the selected sorting order."
962 (interactive (list (or current-prefix-arg 'toggle))) 1007 (interactive (list (or current-prefix-arg 'toggle)))
963 (setq proced-tree-flag 1008 (setq proced-tree-flag
964 (cond ((eq arg 'toggle) (not proced-tree-flag)) 1009 (cond ((eq arg 'toggle) (not proced-tree-flag))
@@ -969,26 +1014,35 @@ do not display as process tree. Sets the variable `proced-tree-flag'."
969 (if proced-tree-flag "enabled" "disabled"))) 1014 (if proced-tree-flag "enabled" "disabled")))
970 1015
971(defun proced-tree (process-alist) 1016(defun proced-tree (process-alist)
972 "Display Proced buffer as process tree if `proced-tree-flag' is non-nil. 1017 "Rearrange PROCESS-ALIST as process tree.
973If `proced-tree-flag' is non-nil, convert PROCESS-ALIST into a linear 1018If `proced-tree-flag' is non-nil, rearrange PROCESS-ALIST such that
974process tree with a time attribute. Otherwise, remove the tree attribute." 1019every processes is followed by its child processes. Each process
1020gets a tree attribute that specifies the depth of the process in the tree.
1021A root process is a process with no parent within PROCESS-ALIST according
1022to its value of the ppid attribute. It has depth 0.
1023
1024If `proced-tree-flag' is nil, remove the tree attribute.
1025Return the rearranged process list."
975 (if proced-tree-flag 1026 (if proced-tree-flag
976 ;; add tree attribute 1027 ;; add tree attribute
977 (let ((process-tree (proced-process-tree process-alist)) 1028 (let ((process-tree (proced-process-tree process-alist))
978 (proced-tree-indent 0) 1029 (proced-tree-indent 0)
1030 (proced-temp-alist process-alist)
979 proced-process-tree pt) 1031 proced-process-tree pt)
980 (while (setq pt (pop process-tree)) 1032 (while (setq pt (pop process-tree))
981 (proced-tree-insert pt)) 1033 (proced-tree-insert pt))
982 (nreverse proced-process-tree)) 1034 (nreverse proced-process-tree))
983 (let (new-alist) 1035 ;; remove tree attribute
984 ;; remove tree attribute 1036 (let ((process-alist process-alist))
985 (dolist (process process-alist) 1037 (while process-alist
986 (push (assq-delete-all 'tree process) new-alist)) 1038 (setcar process-alist
987 (nreverse new-alist)))) 1039 (assq-delete-all 'tree (car process-alist)))
1040 (pop process-alist)))
1041 process-alist))
988 1042
989(defun proced-tree-insert (process-tree) 1043(defun proced-tree-insert (process-tree)
990 "Helper function for `proced-tree'." 1044 "Helper function for `proced-tree'."
991 (let ((pprocess (assq (car process-tree) proced-process-alist))) 1045 (let ((pprocess (assq (car process-tree) proced-temp-alist)))
992 (push (append (list (car pprocess)) 1046 (push (append (list (car pprocess))
993 (list (cons 'tree proced-tree-indent)) 1047 (list (cons 'tree proced-tree-indent))
994 (cdr pprocess)) 1048 (cdr pprocess))
@@ -997,39 +1051,6 @@ process tree with a time attribute. Otherwise, remove the tree attribute."
997 (let ((proced-tree-indent (1+ proced-tree-indent))) 1051 (let ((proced-tree-indent (1+ proced-tree-indent)))
998 (mapc 'proced-tree-insert (cdr process-tree)))))) 1052 (mapc 'proced-tree-insert (cdr process-tree))))))
999 1053
1000(defun proced-filter-children (process-alist ppid &optional omit-ppid)
1001 "For PROCESS-ALIST return list of child processes of PPID.
1002This list includes PPID unless OMIT-PPID is non-nil."
1003 (let ((proced-children-alist (proced-children-alist process-alist))
1004 new-alist)
1005 (dolist (pid (proced-children-pids ppid))
1006 (push (assq pid process-alist) new-alist))
1007 (if omit-ppid
1008 (assq-delete-all ppid new-alist)
1009 new-alist)))
1010
1011(defun proced-children-pids (ppid)
1012 "Return list of children PIDs of PPID (including PPID)."
1013 (let ((cpids (cdr (assq ppid proced-children-alist))))
1014 (if cpids
1015 (cons ppid (apply 'append (mapcar 'proced-children-pids cpids)))
1016 (list ppid))))
1017
1018(defun proced-filter-parents (process-alist pid &optional omit-pid)
1019 "For PROCESS-ALIST return list of parent processes of PID.
1020This list includes PID unless OMIT-PID is non-nil."
1021 (let ((parent-list (unless omit-pid (list (assq pid process-alist))))
1022 (process (assq pid process-alist))
1023 ppid)
1024 (while (and (setq ppid (cdr (assq 'ppid (cdr process))))
1025 ;; Ignore a PPID that equals PID.
1026 (/= ppid pid)
1027 ;; Accept only PPIDs that correspond to members in PROCESS-ALIST.
1028 (setq process (assq ppid process-alist)))
1029 (setq pid ppid)
1030 (push process parent-list))
1031 parent-list))
1032
1033;; Refining 1054;; Refining
1034 1055
1035;; Filters are used to select the processes in a new listing. 1056;; Filters are used to select the processes in a new listing.