From: Emily Shaffer <emilyshaffer@google.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: Jeff Hostetler <git@jeffhostetler.com>,
git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Bagas Sanjaya <bagasdotme@gmail.com>,
"Randall S. Becker" <rsbecker@nexbridge.com>
Subject: Re: [PATCH v5] tr2: log parent process name
Date: Wed, 21 Jul 2021 17:21:07 -0700 [thread overview]
Message-ID: <YPi58/qRPQWhZkiI@google.com> (raw)
In-Reply-To: <87a6n7g9np.fsf@evledraar.gmail.com>
On Wed, Jun 30, 2021 at 08:10:59AM +0200, Ævar Arnfjörð Bjarmason wrote:
>
>
> On Tue, Jun 29 2021, Emily Shaffer wrote:
>
> > On Mon, Jun 28, 2021 at 12:45:24PM -0400, Jeff Hostetler wrote:
> >> On 6/8/21 6:10 PM, Emily Shaffer wrote:
> >> > Range-diff against v4:
> >> > 1: efb0a3ccb4 ! 1: 7a7e1ebbfa tr2: log parent process name
> >> > @@ compat/procinfo.c (new)
> >> > + strbuf_addf(&procfs_path, "/proc/%d/comm", getppid());
> >> > + if (strbuf_read_file(&name, procfs_path.buf, 0)) {
> >> > + strbuf_release(&procfs_path);
> >> > ++ strbuf_trim_trailing_newline(&name);
> >> > + strvec_push(names, strbuf_detach(&name, NULL));
> >> > + }
> >> > +
> >>
> >> You're only getting the name of the command (argv[0]) and not the
> >> full command line, right? That is a good thing.
> >
> > Roughly. The name can be reset by the process itself (that's what
> > happened, I guess, in the tmux case I pasted below) but by default it's
> > argv[0]. It's also truncated to 15ch or something.
>
> 16 including the \0. See prctl(2). Linux has two different ways to
> set/get the name, one is the argv method, the other is
> prctl(PR_SET_NAME). They don't need to match at all. The ps(1) utility
> and some top-like utilities allow you to switch between viewing the two
> versions.
>
> As noted in the linked manual pages you'll also potentially need to deal
> with multithreaded programs having different names for each thread.
>
> I don't think we use this now, but FWIW one thing I've wanted to do for
> a while was to have the progress.c code update this, so you see if git's
> at N% counting objects or whatever in top.
>
> >> > +#ifdef HAVE_PROCFS_LINUX
> >> > + /*
> >> > + * NEEDSWORK: We could gather the entire pstree into an array to match
> >> > + * functionality with compat/win32/trace2_win32_process_info.c.
> >> > + * To do so, we may want to examine /proc/<pid>/stat. For now, just
> >> > + * gather the immediate parent name which is readily accessible from
> >> > + * /proc/$(getppid())/comm.
> >> > + */
> >> > + struct strbuf procfs_path = STRBUF_INIT;
> >> > + struct strbuf name = STRBUF_INIT;
> >> > +
> >> > + /* try to use procfs if it's present. */
> >> > + strbuf_addf(&procfs_path, "/proc/%d/comm", getppid());
> >> > + if (strbuf_read_file(&name, procfs_path.buf, 0)) {
> >> > + strbuf_release(&procfs_path);
> >> > + strbuf_trim_trailing_newline(&name);
> >> > + strvec_push(names, strbuf_detach(&name, NULL));
> >> > + }
> >> > +
> >> > + return;
> >> > +#endif
> >> > + /* NEEDSWORK: add non-procfs-linux implementations here */
> >> > +}
> >>
> >> Perhaps this has already been discussed, but would it be better
> >> to have a "compat/linux/trace2_linux_process_info.c"
> >> or "compat/procfs/trace2_procfs_process_info.c" source file and
> >> only compile it in Linux-compatible builds -- rather than #ifdef'ing
> >> the source. This is a highly platform-specific feature.
> >>
> >> For example, if I convert the Win32 version to use your new event,
> >> I wouldn't want to move the code.
> >>
> >> I just noticed that you have both "BASIC_CFLAGS+=" and a "COMPAT_OBSJ+="
> >> lines. If you made this source file procfs-specific, you wouldn't need
> >> the ifdef and you could avoid the new CFLAG.
>
>
> In general we've preferred not using ifdefs at all except for the small
> bits that absolutely need it.
>
> So e.g. in this case the whole code should compile on non-Linux, we just
> need a small boolean guard somewhere to check what the platform is.
>
> It means we don't have significant pieces of code that don't compile
> except on platform X. It's easy to get into your code not compiling if
> you overuse ifdefs.
Hmm. I see what you mean.
However, since win32 is already using some conditionally compiling code,
that's the approach I went for. It's still running CI to make sure I
didn't break Windows in the process, but I'll post it (and the Actions
runs) later today, assuming it passed.
Yes, the implementation I wrote would compile on any platform, but as I
understand it, other platforms may need drastically different
implementations which may not compile as easily as this. So, I'm not
sure if it's really appropriate to do run-time platform checks here
(which is what I think you were describing).
Anyway, I'll look forward to seeing what you folks think of the next
iteration (again, hopefully later today).
- Emily
next prev parent reply other threads:[~2021-07-22 0:21 UTC|newest]
Thread overview: 87+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-07 0:29 [PATCH] tr2: log parent process name Emily Shaffer
2021-05-07 3:25 ` Bagas Sanjaya
2021-05-07 17:09 ` Emily Shaffer
2021-05-10 12:29 ` Ævar Arnfjörð Bjarmason
2021-05-11 21:31 ` Junio C Hamano
2021-05-14 22:06 ` Emily Shaffer
2021-05-16 3:48 ` Junio C Hamano
2021-05-17 20:17 ` Emily Shaffer
2021-05-11 17:28 ` Jeff Hostetler
2021-05-14 22:07 ` Emily Shaffer
2021-05-20 21:05 ` [PATCH v2] " Emily Shaffer
2021-05-20 21:36 ` Randall S. Becker
2021-05-20 23:23 ` Emily Shaffer
2021-05-21 13:20 ` Randall S. Becker
2021-05-21 16:24 ` Randall S. Becker
2021-05-21 2:09 ` Junio C Hamano
2021-05-21 19:02 ` Emily Shaffer
2021-05-21 23:22 ` Junio C Hamano
2021-05-24 18:37 ` Emily Shaffer
2021-05-21 19:15 ` Jeff Hostetler
2021-05-21 20:05 ` Emily Shaffer
2021-05-21 20:23 ` Randall S. Becker
2021-05-22 11:18 ` Jeff Hostetler
2021-05-24 23:33 ` Ævar Arnfjörð Bjarmason
2021-05-24 20:10 ` [PATCH v3] " Emily Shaffer
2021-05-24 20:49 ` Emily Shaffer
2021-05-25 3:54 ` Junio C Hamano
2021-05-25 13:33 ` Randall S. Becker
2021-06-08 18:58 ` [PATCH v4] " Emily Shaffer
2021-06-08 20:56 ` Emily Shaffer
2021-06-08 22:10 ` [PATCH v5] " Emily Shaffer
2021-06-08 22:16 ` Randall S. Becker
2021-06-08 22:24 ` Emily Shaffer
2021-06-08 22:39 ` Randall S. Becker
2021-06-09 20:17 ` Emily Shaffer
2021-06-16 8:42 ` Junio C Hamano
2021-06-28 16:45 ` Jeff Hostetler
2021-06-29 23:51 ` Emily Shaffer
2021-06-30 6:10 ` Ævar Arnfjörð Bjarmason
2021-07-22 0:21 ` Emily Shaffer [this message]
2021-07-22 1:27 ` [PATCH v6 0/2] " Emily Shaffer
2021-07-22 1:27 ` [PATCH v6 1/2] tr2: make process info collection platform-generic Emily Shaffer
2021-08-02 9:34 ` Ævar Arnfjörð Bjarmason
2021-07-22 1:27 ` [PATCH v6 2/2] tr2: log parent process name Emily Shaffer
2021-07-22 21:02 ` Junio C Hamano
2021-08-02 9:38 ` Ævar Arnfjörð Bjarmason
2021-08-02 12:45 ` Ævar Arnfjörð Bjarmason
2021-08-02 10:22 ` Ævar Arnfjörð Bjarmason
2021-08-02 12:47 ` Ævar Arnfjörð Bjarmason
2021-08-02 15:23 ` Jeff Hostetler
2021-08-02 16:10 ` Randall S. Becker
2021-08-02 18:41 ` Ævar Arnfjörð Bjarmason
2021-08-25 23:19 ` [PATCH 0/6] tr2: plug memory leaks + logic errors + Win32 & Linux feature parity Ævar Arnfjörð Bjarmason
2021-08-25 23:19 ` [PATCH 1/6] tr2: remove NEEDSWORK comment for "non-procfs" implementations Ævar Arnfjörð Bjarmason
2021-08-25 23:19 ` [PATCH 2/6] tr2: clarify TRACE2_PROCESS_INFO_EXIT comment under Linux Ævar Arnfjörð Bjarmason
2021-08-25 23:19 ` [PATCH 3/6] tr2: stop leaking "thread_name" memory Ævar Arnfjörð Bjarmason
2021-08-26 3:09 ` Taylor Blau
2021-08-25 23:19 ` [PATCH 4/6] tr2: fix memory leak & logic error in 2f732bf15e6 Ævar Arnfjörð Bjarmason
2021-08-26 3:21 ` Taylor Blau
2021-08-25 23:19 ` [PATCH 5/6] tr2: do compiler enum check in trace2_collect_process_info() Ævar Arnfjörð Bjarmason
2021-08-26 3:23 ` Taylor Blau
2021-08-25 23:19 ` [PATCH 6/6] tr2: log N parent process names on Linux Ævar Arnfjörð Bjarmason
2021-08-25 23:49 ` Eric Sunshine
2021-08-26 4:07 ` Taylor Blau
2021-08-26 12:24 ` "I don't know what the author meant by that..." (was "Re: [PATCH 6/6] tr2: log N parent process names on Linux") Ævar Arnfjörð Bjarmason
2021-08-26 12:22 ` [PATCH v2 0/6] tr2: plug memory leaks + logic errors + Win32 & Linux feature parity Ævar Arnfjörð Bjarmason
2021-08-26 12:22 ` [PATCH v2 1/6] tr2: remove NEEDSWORK comment for "non-procfs" implementations Ævar Arnfjörð Bjarmason
2021-08-26 12:22 ` [PATCH v2 2/6] tr2: clarify TRACE2_PROCESS_INFO_EXIT comment under Linux Ævar Arnfjörð Bjarmason
2021-08-26 12:22 ` [PATCH v2 3/6] tr2: stop leaking "thread_name" memory Ævar Arnfjörð Bjarmason
2021-08-26 12:22 ` [PATCH v2 4/6] tr2: fix memory leak & logic error in 2f732bf15e6 Ævar Arnfjörð Bjarmason
2021-08-26 15:58 ` Eric Sunshine
2021-08-26 16:42 ` Junio C Hamano
2021-08-26 12:22 ` [PATCH v2 5/6] tr2: do compiler enum check in trace2_collect_process_info() Ævar Arnfjörð Bjarmason
2021-08-26 12:22 ` [PATCH v2 6/6] tr2: log N parent process names on Linux Ævar Arnfjörð Bjarmason
2021-08-26 22:38 ` [PATCH v2 0/6] tr2: plug memory leaks + logic errors + Win32 & Linux feature parity Taylor Blau
2021-08-27 8:02 ` [PATCH v3 " Ævar Arnfjörð Bjarmason
2021-08-27 8:02 ` [PATCH v3 1/6] tr2: remove NEEDSWORK comment for "non-procfs" implementations Ævar Arnfjörð Bjarmason
2021-08-27 8:02 ` [PATCH v3 2/6] tr2: clarify TRACE2_PROCESS_INFO_EXIT comment under Linux Ævar Arnfjörð Bjarmason
2021-08-27 8:02 ` [PATCH v3 3/6] tr2: stop leaking "thread_name" memory Ævar Arnfjörð Bjarmason
2021-08-27 8:02 ` [PATCH v3 4/6] tr2: leave the parent list empty upon failure & don't leak memory Ævar Arnfjörð Bjarmason
2021-08-27 8:02 ` [PATCH v3 5/6] tr2: do compiler enum check in trace2_collect_process_info() Ævar Arnfjörð Bjarmason
2021-08-27 8:02 ` [PATCH v3 6/6] tr2: log N parent process names on Linux Ævar Arnfjörð Bjarmason
2021-08-31 0:17 ` [PATCH v3 0/6] tr2: plug memory leaks + logic errors + Win32 & Linux feature parity Taylor Blau
2021-08-02 10:30 ` [PATCH v6 2/2] tr2: log parent process name Ævar Arnfjörð Bjarmason
2021-08-02 16:24 ` Junio C Hamano
2021-08-02 18:42 ` Ævar Arnfjörð Bjarmason
2021-07-22 16:59 ` [PATCH v6 0/2] " Jeff Hostetler
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YPi58/qRPQWhZkiI@google.com \
--to=emilyshaffer@google.com \
--cc=avarab@gmail.com \
--cc=bagasdotme@gmail.com \
--cc=git@jeffhostetler.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=rsbecker@nexbridge.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).