From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] Make getrusage04 be able to loop more times
Date: Wed, 7 Jun 2017 17:13:15 +0200 [thread overview]
Message-ID: <20170607151315.GA30168@rei.suse.de> (raw)
In-Reply-To: <1496388495-30584-1-git-send-email-chuhu@redhat.com>
Hi!
> int main(int argc, char *argv[])
> {
> struct rusage usage;
> - unsigned long ulast, udelta, slast, sdelta;
> + unsigned long ulast, slast, ulasts, slasts;
> + long udelta, sdelta, udeltas, sdeltas;
> int i, lc;
> char msg_string[BUFSIZ];
>
> @@ -104,28 +105,33 @@ int main(int argc, char *argv[])
> tst_count = 0;
> i = 0;
> SAFE_GETRUSAGE(cleanup, RUSAGE_THREAD, &usage);
> - tst_resm(TINFO, "utime:%12luus; stime:%12luus",
> - usage.ru_utime.tv_usec, usage.ru_stime.tv_usec);
> + tst_resm(TINFO, "utime:%lus %12luus; stime:%lus %12luus",
> + usage.ru_utime.tv_sec, usage.ru_utime.tv_usec,
> + usage.ru_stime.tv_sec, usage.ru_stime.tv_usec);
> ulast = usage.ru_utime.tv_usec;
> slast = usage.ru_stime.tv_usec;
> + ulasts = usage.ru_utime.tv_sec;
> + slasts = usage.ru_stime.tv_sec;
This is getting ugly. Why not just:
struct timeval ulast = usage.ru_utime;
struct timeval slast = usage.ru_stime;
> while (i < RECORD_MAX) {
> SAFE_GETRUSAGE(cleanup, RUSAGE_THREAD, &usage);
> udelta = usage.ru_utime.tv_usec - ulast;
> sdelta = usage.ru_stime.tv_usec - slast;
> + udeltas = usage.ru_utime.tv_sec - ulasts;
> + sdeltas = usage.ru_stime.tv_sec - slasts;
> if (udelta > 0 || sdelta > 0) {
> i++;
> - tst_resm(TINFO, "utime:%12luus; stime:%12luus",
> - usage.ru_utime.tv_usec,
> - usage.ru_stime.tv_usec);
> - if (udelta > 1000 + (BIAS_MAX * factor_nr)) {
> + tst_resm(TINFO, "utime:%lus %12luus; stime:%lus %12luus",
> + usage.ru_utime.tv_sec, usage.ru_utime.tv_usec,
> + usage.ru_stime.tv_sec, usage.ru_stime.tv_usec);
> + if (udelta > 1000 + (BIAS_MAX * factor_nr) && !udeltas) {
> sprintf(msg_string,
> "utime increased > %ldus:",
> 1000 + BIAS_MAX * factor_nr);
> tst_brkm(TFAIL, cleanup, msg_string,
> " delta = %luus", udelta);
> }
> - if (sdelta > 1000 + (BIAS_MAX * factor_nr)) {
> + if (sdelta > 1000 + (BIAS_MAX * factor_nr) && !sdeltas) {
Also why do we skipp the comparsion if seconds has changed?
Computing difference for twom timeval structures is not that
complicated. I can add a helper into include/tst_timer.h if you want.
> sprintf(msg_string,
> "stime increased > %ldus:",
> 1000 + BIAS_MAX * factor_nr);
> @@ -135,6 +141,8 @@ int main(int argc, char *argv[])
> }
> ulast = usage.ru_utime.tv_usec;
> slast = usage.ru_stime.tv_usec;
> + ulasts = usage.ru_utime.tv_sec;
> + slasts = usage.ru_stime.tv_sec;
> busyloop(100000);
> }
> }
> --
> 1.8.3.1
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2017-06-07 15:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-02 7:28 [LTP] [PATCH] Make getrusage04 be able to loop more times Chunyu Hu
2017-06-07 15:13 ` Cyril Hrubis [this message]
2017-06-09 7:42 ` Chunyu Hu
2017-06-12 15:04 ` Cyril Hrubis
2017-06-13 11:47 ` Chunyu Hu
2017-06-13 12:58 ` Cyril Hrubis
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=20170607151315.GA30168@rei.suse.de \
--to=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/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