[PATCH 4 of 4] chg: change server's process title

Yuya Nishihara yuya at tcha.org
Thu Aug 11 12:55:44 EDT 2016


On Thu, 11 Aug 2016 17:24:36 +0100, Jun Wu wrote:
> Excerpts from Yuya Nishihara's message of 2016-08-11 23:28:20 +0900:
> > On Wed, 10 Aug 2016 18:30:00 +0100, Jun Wu wrote:
> > > # HG changeset patch
> > > # User Jun Wu <quark at fb.com>
> > > # Date 1470849617 -3600
> > > #      Wed Aug 10 18:20:17 2016 +0100
> > > # Node ID e7c880aa65ef1cdf00ffe0db27d4365294cb6a62
> > > # Parent  7472b38c08ca30af74668f41056afbd065887c04
> > > # Available At https://bitbucket.org/quark-zju/hg-draft 
> > > #              hg pull https://bitbucket.org/quark-zju/hg-draft  -r e7c880aa65ef
> > > chg: change server's process title
> > > 
> > > This patch uses the newly introduced "setprocname" interface to update the
> > > process title server-side, to make it easier to tell what a worker is
> > > actually doing.
> > > 
> > > The title is short, "chg:$PID", to fit in prctl's 15-char limit. The new
> > > title can be observed using "ps -AO comm" under Linux, and is directly
> > > observable using "ps -A" under FreeBSD.
> > 
> > > +static void updateprocname(hgclient_t *hgc)
> > > +{
> > > +    /* prctl(PR_SET_NAME) has a 15-char limit. be as short as possible */
> > > +    size_t n = (size_t)snprintf(hgc->ctx.data, hgc->ctx.maxdatasize,
> > > +            "chg:%d", (int)getpid());
> > > +    hgc->ctx.datasize = n;
> > > +    writeblockrequest(hgc, "setprocname");
> > > +}
> > 
> > If it's displayed as if argv were {"chg:%d"} on FreeBSD, it would be confusing
> > that both client and server are named as "chg".
> 
> ":" can be used to distinguish servers from clients. I'm open to ideas about
> better format string but pid can be as long as 10 chars, or at least 7 chars
> so we have little space left for Linux.
> 
> > I'm not enthusiastic about this series because it requires new C functions
> > and command-server command just for ease of debugging, different platform
> > behaviors (I guess), no OSX support.
> 
> Unfortunately I don't see a better way to do this. Some people from other
> teams want this feature badly and I think it's a worthy one. From time to
> time, the worker fails to write its pid to blackbox and we have to check
> process startup time to find the matching chg process - not a pleasant
> experience.

Maybe we'll need setproctitle() equivalent for Linux which will update argv?
16-char limitation of prctl() would come from pthread API. If we want to
extend the (ab)use of process title to hgweb, PR_SET_NAME won't be useful.
It won't be displayed in normal ps output.

I found some examples in CRuby (MRI) and PostgreSQL code, though I don't
know if OSX is supported.

> If we really want OS X support, it is probably doable like what node.js
> does [1], although the code and comment scares me a bit.
> 
> [1]: https://github.com/openwebos/nodejs/blob/master/src/platform_darwin_proctitle.cc


More information about the Mercurial-devel mailing list