All of lore.kernel.org
 help / color / mirror / Atom feed
From: gnurou@gmail.com (Alexandre Courbot)
To: kernelnewbies@lists.kernelnewbies.org
Subject: can we measure the traffic between user and kernel mode
Date: Mon, 31 Jan 2011 10:38:23 +0900	[thread overview]
Message-ID: <AANLkTin72YXvEMqvM7V+K8OaKZUhCN9ncJK2t9pfLUTC@mail.gmail.com> (raw)
In-Reply-To: <AANLkTinrr=OqCW+ssw93_D5Tunjo3cPoAFeHD95kRNkR@mail.gmail.com>

> I have tried both ways you mentioned.
> in case 1:
> it did interleave the output of standard output with standard error.
> in case 2:
> the standard output seems will be collect for flush at later,
> combine.strace.txt.
> (I attach the testing result for your reference.)
> theoretically, file re-direction should not be effect the content of
> output, right?

That's what I thought too, but it turns out the libc is smarter than
we expected. File redirection *does* affect the order of output, as
testified by your logs. See the non-redirected behavior:

15:55:35.205409 write(1, "\n", 1)       = 1
15:55:35.205517 write(1, "open fail\n", 10) = 10
15:55:35.205628 open("/home/miloody", O_RDONLY) = -1 ENOENT (No such
file or directory)
15:55:35.205745 write(1, "\n", 1)       = 1
15:55:35.205847 write(1, "open fail\n", 10) = 10
15:55:35.205957 open("/home/miloody", O_RDONLY) = -1 ENOENT (No such
file or directory)
15:55:35.206073 write(1, "\n", 1)       = 1
15:55:35.206174 write(1, "open fail\n", 10) = 10
15:55:35.206284 open("/home/miloody", O_RDONLY) = -1 ENOENT (No such
file or directory)
...

and compare it to what happens when we use redirection:

...
15:56:21.105236 open("/home/miloody", O_RDONLY) = -1 ENOENT (No such
file or directory)
15:56:21.105294 open("/home/miloody", O_RDONLY) = -1 ENOENT (No such
file or directory)
15:56:21.105353 open("/home/miloody", O_RDONLY) = -1 ENOENT (No such
file or directory)
15:56:21.105417 write(1, "\nopen fail\n\nopen fail\n\nopen fail"..., 110

Here the libc has grouped all your printfs into one single system call
because of user-space buffering. Fortunately you can prevent this
behavior using unbuffer:

http://linuxcommand.org/man_pages/unbuffer1.html

So your strace invokation would be like:

$ strace -tt stdbuf -o0 -e0 ./foo &>output

Which produces the expected output on my system.

Alex.

  reply	other threads:[~2011-01-31  1:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-27  3:42 can we measure the traffic between user and kernel mode loody
2011-01-27  4:41 ` Alexandre Courbot
2011-01-27  5:02 ` Mulyadi Santosa
2011-01-27  5:56   ` loody
2011-01-27  6:20     ` Mulyadi Santosa
2011-01-27 11:56       ` Pravin Shedage
2011-01-27 13:48       ` loody
2011-01-27 17:45         ` Mulyadi Santosa
2011-01-30  7:50           ` loody
2011-01-28  1:07         ` Alexandre Courbot
2011-01-30  8:07           ` loody
2011-01-31  1:38             ` Alexandre Courbot [this message]
2011-01-31  1:40               ` Alexandre Courbot
2011-01-27  5:56 ` Michael Blizek

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=AANLkTin72YXvEMqvM7V+K8OaKZUhCN9ncJK2t9pfLUTC@mail.gmail.com \
    --to=gnurou@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.