From: "Jiří Paleček" <jpalecek@web.de>
To: Garrett Cooper <yanegomi@gmail.com>
Cc: ltp-list <ltp-list@lists.sourceforge.net>
Subject: Re: [LTP] [PATCH] cpuctl_fj: replace ps by top to fix cpu usage's computation error
Date: Sun, 24 Jan 2010 01:22:01 +0100 [thread overview]
Message-ID: <op.u60gmvbpu2flwt@debian> (raw)
In-Reply-To: <364299f41001231438u2422c16n2c8b0838812e3237@mail.gmail.com>
On Sat, 23 Jan 2010 23:38:08 +0100, Garrett Cooper <yanegomi@gmail.com>
wrote:
> 2010/1/22 Jiří Paleček <jpalecek@web.de>:
>> On Wed, 20 Jan 2010 03:52:48 +0100, Garrett Cooper <yanegomi@gmail.com>
>> wrote:
>>
>>> On Tue, Jan 19, 2010 at 4:30 PM, Jiri Palecek <jpalecek@web.de> wrote:
>>>>
>>>> On Wednesday 06 January 2010 10:47:34 Shi Weihua wrote:
>>>>>
>>>>> at 2010-1-6 13:24, Garrett Cooper wrote:
>>>>> > On Tue, Jan 5, 2010 at 8:58 PM, Shi Weihua <shiwh@cn.fujitsu.com>
>>>>> > wrote:
>>>>> >> Some abnormal messages outputted in my x86_64.
>>>>> >> -------------------
>>>>> >> pid 4622 cpu_usage 0
>>>>> >> cpuctl_test_fj 1 TFAIL : case19 FAIL
>>>>> >> pid 4646 cpu_usage 0
>>>>> >> cpuctl_test_fj 1 TFAIL : case20 FAIL
>>>>> >> pid 4670 cpu_usage 63
>>>>> >> cpuctl_test_fj 1 TFAIL : case21 FAIL
>>>>> >> -------------------
>>>>> >> I think cpu usage's computation error occured.
>>>>> >> So I tried to use the oldest arithmetic of cpu usage, fortunately
>>>>> it
>>>>> >> works.
>>>>> >> Maybe we should replace 'ps' by 'top' in get_cpu_usage().
>>>>> >> By the way, I increased the admissible range of cpu usage in
>>>>> case21()
>>>>> >> because it jumps out range of 44-56 sometimes.
>>>>> >>
>>>>> >> My patch works now:
>>>>> >> -------------------
>>>>> >> pid 20277 cpu_usage 97
>>>>> >> cpuctl_test_fj 1 TPASS : case19 PASS
>>>>> >> pid 20307 cpu_usage 99
>>>>> >> cpuctl_test_fj 1 TPASS : case20 PASS
>>>>> >> pid 20336 cpu_usage 55
>>>>> >> pid 20336 cpu_usage 53
>>>>> >> pid 20336 cpu_usage 55
>>>>> >> pid 20336 cpu_usage 57
>>>>> >> pid 20336 cpu_usage 55
>>>>> >> pid 20336 cpu_usage 55
>>>>> >> pid 20336 cpu_usage 55
>>>>> >> pid 20336 cpu_usage 55
>>>>> >> pid 20336 cpu_usage 57
>>>>> >> pid 20336 cpu_usage 53
>>>>> >> cpuctl_test_fj 1 TPASS : case21 PASS
>>>>> >> -------------------
>>>>> >>
>>>>> >> Signed-off-by: Shi Weihua <shiwh@cn.fujitsu.com>
>>>>> >> ---
>>>>> >> ---
>>>>> >>
>>>>> ltp-full-20091231/testcases/kernel/controllers/cpuctl_fj/run_cpuctl_test_fj.sh
>>>>> >> 2009-11-16 15:40:40.000000000 +0800
>>>>> >> +++
>>>>> >>
>>>>> ltp-full-20091231.new/testcases/kernel/controllers/cpuctl_fj/run_cpuctl_test_fj.sh
>>>>> >> 2010-01-06 12:36:32.000000000 +0800
>>>>> >> @@ -85,7 +85,10 @@ creat_process()
>>>>> >>
>>>>> >> get_cpu_usage()
>>>>> >> {
>>>>> >> - ps -eo 'pid,pcpu' | awk '$1 == "'$1'" {
>>>>> >> sub(/(\.[[:digit:]])*$/, "", $2); print $2 }'
>>>>> >> + top=($(top -b -n 1 -p $1 | tail -2 | head -1))
>>>>> >> + top=${top[8]}
>>>>> >> + top=`echo $top | awk -F "." '{print $1}'`
>>>>> >> + echo "$top"
>>>>> >> }
>>>>> >>
>>>>> >> kill_all_pid()
>>>>> >> @@ -627,7 +630,7 @@ case21()
>>>>> >> do
>>>>> >> cpu_usage=$(get_cpu_usage $pid)
>>>>> >> echo "pid $pid cpu_usage $cpu_usage"
>>>>> >> - expr 44 \< "$cpu_usage" \& "$cpu_usage" \< 56 >
>>>>> >> /dev/null 2>&1
>>>>> >> + expr 40 \< "$cpu_usage" \& "$cpu_usage" \< 60 >
>>>>> >> /dev/null 2>&1
>>>>> >> ret=$?
>>>>> >> : $(( top_times+=1 ))
>>>>> >> done
>>>>> >
>>>>> > Could you add a set -x to the top of the script so we can see
>>>>> the
>>>>> > output please? ps --version would be helpful too..
>>>>>
>>>>> I wish it can help you.
>>>>> --------------------- sh -x -----------------------------
>>>>> + for i in '$(seq 1 $TST_TOTAL)'
>>>>> + setup
>>>>
>>>> [ ... snip ... ]
>>>>
>>>> I believe Garrett Cooper meant to send the trace output of the
>>>> original
>>>> script (the one with ps).
>>>>
>>>> However, I'm not sure about the awk program there - particularly:
>>>>
>>>> sub(/(\.[[:digit:]])*$/, "", $2)
>>>>
>>>> should probably be
>>>>
>>>> sub(/\.[[:digit:]]*$/, "", $2)
>>>>
>>>> (without the group). Not sure if this can actually cause what you see.
>>>>
>>>> Also, I think we could simplify it a bit further, to something like
>>>> this:
>>>>
>>>> get_cpu_usage()
>>>> {
>>>> ps -p $1 -o pcpu= | awk -F "." '{print $1}'
>>>> }
>>>>
>>>> Please, tell me what do you think about it.
>>>
>>> Actually he gave me what I needed (forgot to reply because I
>>
>> Yes, but it doesn't cast much light on the problem that it didn't work
>> for
>> Shi Weihua in the first place.
>>
>>> didn't star the email); I'm pretty sure that your observation is
>>> correct: we shouldn't be extracting \. unless we're actually going to
>>> use it, so the ellipses [\(\)] can be removed.
>>> Are we using just the `major' number, or are we using the `minor'
>>> number in the cpu usage?
>>
>> You mean integral and fractional part? I guess the integral part only.
>
> Does expr(1) do float point comparisons (this is where the issue was
> coming from I think...)?
>
> gcooper@optimus ~ $ expr 0 \< 42.0 \& 42.0 \< 100
> 0
> gcooper@optimus ~ $ expr 0.0 \< 42.0 \& 42.0 \< 100.0
> 0
>
> I checked in a copy based on your suggestion Jiri so folks would hit
> this issue, but I'm curious as to why integers are the only things
> supported by expr(1) when comparing ranges.
Obviously, only integers are supported by expr. That's the way it is.
Not that I think we (or this test) actually need floating point numbers -
we can happily use integral approximations when testing against interval
40-60. But Shi Weihua's mail indicated that he gets 0 (zero) from that
function, so I guess it's because top gives different data from ps (which
is actually true - ps gives average cpu % over the whole lifetime of the
process, top over the last five seconds). Maybe this needs changing?
Regards
Jiri Palecek
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
prev parent reply other threads:[~2010-01-23 23:22 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-06 4:58 [LTP] [PATCH] cpuctl_fj: replace ps by top to fix cpu usage's computation error Shi Weihua
2010-01-06 5:24 ` Garrett Cooper
2010-01-06 9:47 ` Shi Weihua
2010-01-20 0:30 ` Jiri Palecek
2010-01-20 2:52 ` Garrett Cooper
2010-01-22 11:25 ` Jiří Paleček
2010-01-23 22:38 ` Garrett Cooper
2010-01-23 22:38 ` Garrett Cooper
2010-01-24 0:22 ` Jiří Paleček [this message]
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=op.u60gmvbpu2flwt@debian \
--to=jpalecek@web.de \
--cc=ltp-list@lists.sourceforge.net \
--cc=yanegomi@gmail.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