Under HHVM, measure resources for the thread, not calling process
authorOri Livneh <ori@wikimedia.org>
Thu, 4 Sep 2014 23:56:20 +0000 (16:56 -0700)
committerOri Livneh <ori@wikimedia.org>
Wed, 10 Sep 2014 19:03:32 +0000 (12:03 -0700)
commit4ee9063956ba1a3e7fcc1195b5034f128267ab35
tree0e96e73aea852ea54d131ecac5d2c0290adac62c
parentc209105a3fc4c37d7d68a406bba78b078f1ee1b2
Under HHVM, measure resources for the thread, not calling process

As of <https://github.com/facebook/hhvm/commit/0f98cab>, it is possible to
call getrusage( [ int $who = 0 ] ) with $who = 2 to request resource usage
info for the current thread (RUSAGE_THERAD), rather than the calling process
(RUSAGE_SELF). (Earlier versions of HHVM return RUSAGE_SELF data unless $who
is 1.)

PHP5 code can assume that each request is handled in a dedicated subprocess,
but the same is not true of HHVM, which is multi-threaded. Therefore, to get
resource usage data for the current request context, it is necessary to ask
for RUSAGE_THREAD rather than RUSAGE_SELF.

To do this, introduce a new global function in Profiler.php: wfGetRusage().
It is defined there and not in GlobalFunctions.php so that it can be used early
in WebStart.php.

Bug: 70227
Change-Id: Ibe9598ecdfc0f6c434f8b3c7a94f06a7b2fcca23
includes/WebStart.php
includes/parser/ParserOutput.php
includes/profiler/Profiler.php