* bug#48548: 28.0.50; Some process attributes on macOS are missing @ 2021-05-20 20:24 Filipp Gunbin 2021-05-20 20:35 ` Filipp Gunbin 0 siblings, 1 reply; 11+ messages in thread From: Filipp Gunbin @ 2021-05-20 20:24 UTC (permalink / raw) To: 48548 On macOS, system_process_attributes() could provide more attributes ("args", in particular). Will post patch here. Thanks ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#48548: 28.0.50; Some process attributes on macOS are missing 2021-05-20 20:24 bug#48548: 28.0.50; Some process attributes on macOS are missing Filipp Gunbin @ 2021-05-20 20:35 ` Filipp Gunbin 2021-05-20 20:39 ` Filipp Gunbin 0 siblings, 1 reply; 11+ messages in thread From: Filipp Gunbin @ 2021-05-20 20:35 UTC (permalink / raw) To: 48548 tags 48548 + patch quit On 20/05/2021 23:24 +0300, Filipp Gunbin wrote: > On macOS, system_process_attributes() could provide more attributes > ("args", in particular). Will post patch here. > > Thanks ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#48548: 28.0.50; Some process attributes on macOS are missing 2021-05-20 20:35 ` Filipp Gunbin @ 2021-05-20 20:39 ` Filipp Gunbin 2021-05-20 20:49 ` Filipp Gunbin 2021-05-25 4:08 ` Lars Ingebrigtsen 0 siblings, 2 replies; 11+ messages in thread From: Filipp Gunbin @ 2021-05-20 20:39 UTC (permalink / raw) To: 48548 Improve system_process_attributes on macOS (Bug#48548) * src/sysdep.c (system_process_attributes): Fix misprint in 'tty' attr - should be 'ttname' instead. Change 'utime', 'stime', 'time', 'majflt' attrs to obtain them from proc_pid_rusage, as sysctl call used before doesn't give correct values; remove 'minflt' because it's not available. Obtain 'vsize' / 'rss' / 'thcount' from proc_pidinfo. Use sysctl with KERN_PROCARGS2 to obtain args: value contains both argc and argv, so argv can be reliably cut out. diff --git a/src/sysdep.c b/src/sysdep.c index d940acc4e0..f899bb7532 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -3898,20 +3898,19 @@ system_process_attributes (Lisp_Object pid) Lisp_Object system_process_attributes (Lisp_Object pid) { - int proc_id; + int proc_id, i; struct passwd *pw; struct group *gr; char *ttyname; struct timeval starttime; struct timespec t, now; - struct rusage *rusage; dev_t tdev; uid_t uid; gid_t gid; int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID}; struct kinfo_proc proc; - size_t proclen = sizeof proc; + size_t len = sizeof proc; Lisp_Object attrs = Qnil; Lisp_Object decoded_comm; @@ -3920,7 +3919,7 @@ system_process_attributes (Lisp_Object pid) CONS_TO_INTEGER (pid, int, proc_id); mib[3] = proc_id; - if (sysctl (mib, 4, &proc, &proclen, NULL, 0) != 0 || proclen == 0) + if (sysctl (mib, 4, &proc, &len, NULL, 0) != 0 || len == 0) return attrs; uid = proc.kp_eproc.e_ucred.cr_uid; @@ -3957,8 +3956,8 @@ system_process_attributes (Lisp_Object pid) decoded_comm = (code_convert_string_norecord (build_unibyte_string (comm), Vlocale_coding_system, 0)); - attrs = Fcons (Fcons (Qcomm, decoded_comm), attrs); + { char state[2] = {'\0', '\0'}; switch (proc.kp_proc.p_stat) @@ -3994,27 +3993,24 @@ system_process_attributes (Lisp_Object pid) ttyname = tdev == NODEV ? NULL : devname (tdev, S_IFCHR); unblock_input (); if (ttyname) - attrs = Fcons (Fcons (Qtty, build_string (ttyname)), attrs); + attrs = Fcons (Fcons (Qttname, build_string (ttyname)), attrs); attrs = Fcons (Fcons (Qtpgid, INT_TO_INTEGER (proc.kp_eproc.e_tpgid)), attrs); - rusage = proc.kp_proc.p_ru; - if (rusage) + rusage_info_current ri; + if (proc_pid_rusage(proc_id, RUSAGE_INFO_CURRENT, (rusage_info_t *) &ri) == 0) { - attrs = Fcons (Fcons (Qminflt, INT_TO_INTEGER (rusage->ru_minflt)), - attrs); - attrs = Fcons (Fcons (Qmajflt, INT_TO_INTEGER (rusage->ru_majflt)), - attrs); - - attrs = Fcons (Fcons (Qutime, make_lisp_timeval (rusage->ru_utime)), - attrs); - attrs = Fcons (Fcons (Qstime, make_lisp_timeval (rusage->ru_stime)), - attrs); - t = timespec_add (timeval_to_timespec (rusage->ru_utime), - timeval_to_timespec (rusage->ru_stime)); - attrs = Fcons (Fcons (Qtime, make_lisp_time (t)), attrs); - } + struct timespec utime = make_timespec (ri.ri_user_time / TIMESPEC_HZ, + ri.ri_user_time % TIMESPEC_HZ); + struct timespec stime = make_timespec (ri.ri_system_time / TIMESPEC_HZ, + ri.ri_system_time % TIMESPEC_HZ); + attrs = Fcons (Fcons (Qutime, make_lisp_time (utime)), attrs); + attrs = Fcons (Fcons (Qstime, make_lisp_time (stime)), attrs); + attrs = Fcons (Fcons (Qtime, make_lisp_time (timespec_add (utime, stime))), attrs); + + attrs = Fcons (Fcons (Qmajflt, INT_TO_INTEGER (ri.ri_pageins)), attrs); + } starttime = proc.kp_proc.p_starttime; attrs = Fcons (Fcons (Qnice, make_fixnum (proc.kp_proc.p_nice)), attrs); @@ -4024,6 +4020,50 @@ system_process_attributes (Lisp_Object pid) t = timespec_sub (now, timeval_to_timespec (starttime)); attrs = Fcons (Fcons (Qetime, make_lisp_time (t)), attrs); + struct proc_taskinfo taskinfo; + if (proc_pidinfo (proc_id, PROC_PIDTASKINFO, 0, &taskinfo, sizeof (taskinfo)) > 0) + { + attrs = Fcons (Fcons (Qvsize, make_fixnum (taskinfo.pti_virtual_size / 1024)), attrs); + attrs = Fcons (Fcons (Qrss, make_fixnum (taskinfo.pti_resident_size / 1024)), attrs); + attrs = Fcons (Fcons (Qthcount, make_fixnum (taskinfo.pti_threadnum)), attrs); + } + +#ifdef KERN_PROCARGS2 + char args[ARG_MAX]; + mib[1] = KERN_PROCARGS2; + mib[2] = proc_id; + len = sizeof args; + + if (sysctl (mib, 3, &args, &len, NULL, 0) == 0 && len != 0) + { + char *start, *end; + + int argc = *(int*)args; /* argc is the first int */ + start = args + sizeof (int); + + start += strlen (start) + 1; /* skip executable name and any '\0's */ + while ((start - args < len) && ! *start) start++; + + /* skip argv to find real end */ + for (i = 0, end = start; i < argc && (end - args) < len; i++) + { + end += strlen (end) + 1; + } + + len = end - start; + for (int i = 0; i < len; i++) + { + if (! start[i] && i < len - 1) + start[i] = ' '; + } + + AUTO_STRING (comm, start); + decoded_comm = code_convert_string_norecord (comm, + Vlocale_coding_system, 0); + attrs = Fcons (Fcons (Qargs, decoded_comm), attrs); + } +#endif /* KERN_PROCARGS2 */ + return attrs; } ^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: bug#48548: 28.0.50; Some process attributes on macOS are missing 2021-05-20 20:39 ` Filipp Gunbin @ 2021-05-20 20:49 ` Filipp Gunbin 2021-05-21 5:53 ` Eli Zaretskii 2021-05-25 4:08 ` Lars Ingebrigtsen 1 sibling, 1 reply; 11+ messages in thread From: Filipp Gunbin @ 2021-05-20 20:49 UTC (permalink / raw) To: emacs-devel; +Cc: bug-gnu-emacs Hello, could someone please review this? (bug#48548) I'm kinda sure in syscalls I make (tested them on latest Big Sur 11.3.1 and on Yosemite from several years ago; running with this patch for several weeks now, using via M-x proced), but I'm not so sure in my C :-) Thanks. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: bug#48548: 28.0.50; Some process attributes on macOS are missing 2021-05-20 20:49 ` Filipp Gunbin @ 2021-05-21 5:53 ` Eli Zaretskii 2021-05-21 9:50 ` Filipp Gunbin 0 siblings, 1 reply; 11+ messages in thread From: Eli Zaretskii @ 2021-05-21 5:53 UTC (permalink / raw) To: Filipp Gunbin; +Cc: bug-gnu-emacs, emacs-devel > From: Filipp Gunbin <fgunbin@fastmail.fm> > Date: Thu, 20 May 2021 23:49:54 +0300 > Cc: bug-gnu-emacs@gnu.org > > Hello, could someone please review this? (bug#48548) Please be more patient: you posted the patch just 10 minutes before sending this ping. The patch will be reviewed soon enough, just give us some time. Thanks. ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: bug#48548: 28.0.50; Some process attributes on macOS are missing 2021-05-21 5:53 ` Eli Zaretskii @ 2021-05-21 9:50 ` Filipp Gunbin 0 siblings, 0 replies; 11+ messages in thread From: Filipp Gunbin @ 2021-05-21 9:50 UTC (permalink / raw) To: Eli Zaretskii; +Cc: bug-gnu-emacs, emacs-devel On 21/05/2021 08:53 +0300, Eli Zaretskii wrote: >> From: Filipp Gunbin <fgunbin@fastmail.fm> >> Date: Thu, 20 May 2021 23:49:54 +0300 >> Cc: bug-gnu-emacs@gnu.org >> >> Hello, could someone please review this? (bug#48548) > > Please be more patient: you posted the patch just 10 minutes before > sending this ping. The patch will be reviewed soon enough, just give > us some time. > > Thanks. Pinging wasn't my intent, I just wanted to ask for review on emacs-devel.. Thanks. ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#48548: 28.0.50; Some process attributes on macOS are missing 2021-05-20 20:39 ` Filipp Gunbin 2021-05-20 20:49 ` Filipp Gunbin @ 2021-05-25 4:08 ` Lars Ingebrigtsen 2021-05-25 17:13 ` Filipp Gunbin 2021-05-26 6:52 ` Alan Third 1 sibling, 2 replies; 11+ messages in thread From: Lars Ingebrigtsen @ 2021-05-25 4:08 UTC (permalink / raw) To: 48548; +Cc: Alan Third, Filipp Gunbin Filipp Gunbin <fgunbin@fastmail.fm> writes: > Improve system_process_attributes on macOS (Bug#48548) Looks good to me, but I've added Alan to the CCs -- perhaps he'll have some comments. Just one small comment: > - size_t proclen = sizeof proc; > + size_t len = sizeof proc; Any reason for this change? -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#48548: 28.0.50; Some process attributes on macOS are missing 2021-05-25 4:08 ` Lars Ingebrigtsen @ 2021-05-25 17:13 ` Filipp Gunbin 2021-05-25 19:32 ` Lars Ingebrigtsen 2021-05-26 6:52 ` Alan Third 1 sibling, 1 reply; 11+ messages in thread From: Filipp Gunbin @ 2021-05-25 17:13 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: 48548, Alan Third On 25/05/2021 06:08 +0200, Lars Ingebrigtsen wrote: > Filipp Gunbin <fgunbin@fastmail.fm> writes: > >> Improve system_process_attributes on macOS (Bug#48548) > > Looks good to me, but I've added Alan to the CCs -- perhaps he'll have > some comments. Thanks, will wait. > Just one small comment: > >> - size_t proclen = sizeof proc; >> + size_t len = sizeof proc; > > Any reason for this change? Yes, the usage of len for different purpose below: + len = sizeof args; Filipp ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#48548: 28.0.50; Some process attributes on macOS are missing 2021-05-25 17:13 ` Filipp Gunbin @ 2021-05-25 19:32 ` Lars Ingebrigtsen 0 siblings, 0 replies; 11+ messages in thread From: Lars Ingebrigtsen @ 2021-05-25 19:32 UTC (permalink / raw) To: Filipp Gunbin; +Cc: 48548, Alan Third Filipp Gunbin <fgunbin@fastmail.fm> writes: >> Any reason for this change? > > Yes, the usage of len for different purpose below: > > + len = sizeof args; Oops; didn't read the patch carefully enough. -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#48548: 28.0.50; Some process attributes on macOS are missing 2021-05-25 4:08 ` Lars Ingebrigtsen 2021-05-25 17:13 ` Filipp Gunbin @ 2021-05-26 6:52 ` Alan Third 2021-05-26 14:12 ` Filipp Gunbin 1 sibling, 1 reply; 11+ messages in thread From: Alan Third @ 2021-05-26 6:52 UTC (permalink / raw) To: Lars Ingebrigtsen; +Cc: 48548, Filipp Gunbin On Tue, May 25, 2021 at 06:08:56AM +0200, Lars Ingebrigtsen wrote: > Filipp Gunbin <fgunbin@fastmail.fm> writes: > > > Improve system_process_attributes on macOS (Bug#48548) > > Looks good to me, but I've added Alan to the CCs -- perhaps he'll have > some comments. No comments from me. -- Alan Third ^ permalink raw reply [flat|nested] 11+ messages in thread
* bug#48548: 28.0.50; Some process attributes on macOS are missing 2021-05-26 6:52 ` Alan Third @ 2021-05-26 14:12 ` Filipp Gunbin 0 siblings, 0 replies; 11+ messages in thread From: Filipp Gunbin @ 2021-05-26 14:12 UTC (permalink / raw) To: 48548; +Cc: Lars Ingebrigtsen, Alan Third tags 48548 fixed close 48548 28.1 quit On 26/05/2021 07:52 +0100, Alan Third wrote: > On Tue, May 25, 2021 at 06:08:56AM +0200, Lars Ingebrigtsen wrote: >> Filipp Gunbin <fgunbin@fastmail.fm> writes: >> >> > Improve system_process_attributes on macOS (Bug#48548) >> >> Looks good to me, but I've added Alan to the CCs -- perhaps he'll have >> some comments. > > No comments from me. > -- > Alan Third Pushed to master. 6d51805154 2021-05-26T16:15:03+03:00 "Improve system_process_attributes on macOS (Bug#48548)" https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=6d51805154ef7591917c5727b905b4080e18b888 ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2021-05-26 14:12 UTC | newest] Thread overview: 11+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-05-20 20:24 bug#48548: 28.0.50; Some process attributes on macOS are missing Filipp Gunbin 2021-05-20 20:35 ` Filipp Gunbin 2021-05-20 20:39 ` Filipp Gunbin 2021-05-20 20:49 ` Filipp Gunbin 2021-05-21 5:53 ` Eli Zaretskii 2021-05-21 9:50 ` Filipp Gunbin 2021-05-25 4:08 ` Lars Ingebrigtsen 2021-05-25 17:13 ` Filipp Gunbin 2021-05-25 19:32 ` Lars Ingebrigtsen 2021-05-26 6:52 ` Alan Third 2021-05-26 14:12 ` Filipp Gunbin
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).