[PATCH] Decode RUSAGE_THREAD
Eugene Syromyatnikov
evgsyr at gmail.com
Wed Mar 15 16:02:07 UTC 2017
Please do not answer in an existing thread and start a new thread for
a new separate patch.
On Wed, Mar 15, 2017 at 3:25 PM, Victor Krapivensky
<krapivenskiy.va at phystech.edu> wrote:
> * xlat/usagewho.in: Add RUSAGE_THREAD.
> * tests/getrusage.c: Test decoding of RUSAGE_THREAD.
> ---
> tests/getrusage.c | 21 +++++++++++++++------
> xlat/usagewho.in | 1 +
> 2 files changed, 16 insertions(+), 6 deletions(-)
>
> diff --git a/tests/getrusage.c b/tests/getrusage.c
> index 8b76eff..ba1a7ef 100644
> --- a/tests/getrusage.c
> +++ b/tests/getrusage.c
> @@ -25,7 +25,6 @@
> * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
> * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
> */
> -
Is this intentional?
> #include "tests.h"
> #include <asm/unistd.h>
>
> @@ -36,17 +35,16 @@
> # include <sys/resource.h>
> # include <unistd.h>
>
> -int
> -main(void)
> +int invoke_print(int who, const char *who_str, struct rusage *usage)
Please follow the same coding style (function return type on the separate line).
> {
> - struct rusage *const usage = tail_alloc(sizeof(struct rusage));
> - int rc = syscall(__NR_getrusage, RUSAGE_SELF, usage);
> - printf("getrusage(RUSAGE_SELF, {ru_utime={tv_sec=%jd, tv_usec=%jd}"
> + int rc = syscall(__NR_getrusage, who, usage);
> + printf("getrusage(%s, {ru_utime={tv_sec=%jd, tv_usec=%jd}"
> ", ru_stime={tv_sec=%jd, tv_usec=%jd}, ru_maxrss=%lu"
> ", ru_ixrss=%lu, ru_idrss=%lu, ru_isrss=%lu, ru_minflt=%lu"
> ", ru_majflt=%lu, ru_nswap=%lu, ru_inblock=%lu"
> ", ru_oublock=%lu, ru_msgsnd=%lu, ru_msgrcv=%lu"
> ", ru_nsignals=%lu, ru_nvcsw=%lu, ru_nivcsw=%lu}) = %d\n",
> + who_str,
> (intmax_t) usage->ru_utime.tv_sec,
> (intmax_t) usage->ru_utime.tv_usec,
> (intmax_t) usage->ru_stime.tv_sec,
> @@ -56,6 +54,17 @@ main(void)
> usage->ru_nswap, usage->ru_inblock, usage->ru_oublock,
> usage->ru_msgsnd, usage->ru_msgrcv, usage->ru_nsignals,
> usage->ru_nvcsw, usage->ru_nivcsw, rc);
> + return rc;
> +}
> +
> +int
> +main(void)
> +{
> + struct rusage *const usage = tail_alloc(sizeof(struct rusage));
> + (void) invoke_print(RUSAGE_SELF, "RUSAGE_SELF", usage);
> +# ifdef RUSAGE_THREAD
> + (void) invoke_print(RUSAGE_THREAD, "RUSAGE_THREAD", usage);
You can try to use ARG_STR() macro here in order to avoid duplication
of the symbolic name, but it's a bit obscure.
> +# endif
>
> puts("+++ exited with 0 +++");
> return 0;
> diff --git a/xlat/usagewho.in b/xlat/usagewho.in
> index e2153b3..62e7352 100644
> --- a/xlat/usagewho.in
> +++ b/xlat/usagewho.in
> @@ -1,3 +1,4 @@
> RUSAGE_SELF
> RUSAGE_CHILDREN
> RUSAGE_BOTH
> +RUSAGE_THREAD
It may be a good idea to add values for these xlat values (as long as
they are arch-independent) in order to depend less on kernel headers
(there is some effort to do so, but it's inconsistent and is enforced
case-by-case basis). In this case RUSAGE_THREAD can also be tested
regardless of kernel version, but it should be considered then that
kernel could return -EINVAL in case it doesn't support it.
Otherwise, patch looks good overall.
> --
> 2.10.2
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Strace-devel mailing list
> Strace-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/strace-devel
--
Eugene Syromyatnikov
mailto:evgsyr at gmail.com
xmpp:esyr at jabber.{ru|org}
More information about the Strace-devel
mailing list