mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: ptxdist@pengutronix.de, post@lespocky.de
Subject: Re: [ptxdist] [PATCH] htop: version bump 2.0.2 -> 2.1.0
Date: Thu, 8 Feb 2018 11:33:33 +0100	[thread overview]
Message-ID: <dbf7fc96-ae62-9051-4688-dfddc70b60f7@pengutronix.de> (raw)
In-Reply-To: <20180208101903.h6fgxgtidnqqwxou@falbala.home.lespocky.de>


[-- Attachment #1.1.1: Type: text/plain, Size: 5605 bytes --]

On 02/08/2018 11:19 AM, Alexander Dahl wrote:
> On Thu, Feb 08, 2018 at 10:17:31AM +0100, Marc Kleine-Budde wrote:
>> Have you enabled CONFIG_TASK_XACCT and CONFIG_TASK_IO_ACCOUNTING?
> 
> Didn't have that before. I get some values now, although I'm not sure
> how to interpret those. I should probably look in the htop
> documentation again. But thanks for the hint, I guess htop can show
> even more interesting things, I did not know it can, yet. :-)

Luckily I've recently collected all needed information:

> RCHAR - Number of bytes the process has read
> WCHAR - Number of bytes the process has written
> SYSCR - Number of read(2) syscalls for the process
> SYSCW - Number of write(2) syscalls for the process
> RBYTES - Bytes of read(2) I/O for the process
> WBYTES - Bytes of write(2) I/O for the process
> CNCLWB - Bytes of cancelled write(2) I/O
> 
> IO_READ_RATE - The I/O rate of read(2) in bytes per second for the
>                process
> IO_WRITE_RATE - The I/O rate of write(2) in bytes per second for the
>                 process
> IO_RATE - Total I/O rate in bytes per second
> 
> However if you want machine readable output, you have two options:
> 
> 1)
> Parse /proc/$PID/io directly, which correspond to the absolute numbers
> from htop. The *_RATE values are calculated by htop from the absolute
> numbers.
> 
> See man-page of proc(5) for more information about /proc/$PID/io:
> 
>> >               rchar: characters read
>> >                      The  number of bytes which this task has caused to
>> >                      be read from storage.  This is simply the  sum  of
>> >                      bytes  which  this  process  passed to read(2) and
>> >                      similar system calls.  It includes things such  as
>> >                      terminal  I/O  and is unaffected by whether or not
>> >                      actual physical disk I/O was  required  (the  read
>> >                      might have been satisfied from pagecache).
>> > 
>> >               wchar: characters written
>> >                      The number of bytes which this task has caused, or
>> >                      shall  cause  to  be  written  to  disk.   Similar
>> >                      caveats apply here as with rchar.
> 
> Counts all read/write done through files (_including_ pseudo files like
> /dev/zero, /dev/null, named pipes).
> 
>> >               syscr: read syscalls
>> >                      Attempt  to  count  the  number of read I/O opera‐
>> >                      tions—that is, system calls such  as  read(2)  and
>> >                      pread(2).
>> > 
>> >               syscw: write syscalls
>> >                      Attempt  to  count  the number of write I/O opera‐
>> >                      tions—that is, system calls such as  write(2)  and
>> >                      pwrite(2).
>> > 
>> >               read_bytes: bytes read
>> >                      Attempt  to  count  the number of bytes which this
>> >                      process really did cause to be  fetched  from  the
>> >                      storage  layer.  This is accurate for block-backed
>> >                      filesystems.
>> > 
>> >               write_bytes: bytes written
>> >                      Attempt to count the number of  bytes  which  this
>> >                      process caused to be sent to the storage layer.
> 
> Accounting on MTD devices is not accurate for these two.
> 
>> >               cancelled_write_bytes:
>> >                      The big inaccuracy here is truncate.  If a process
>> >                      writes 1MB to a file and then deletes the file, it
>> >                      will  in  fact  perform  no writeout.  But it will
>> >                      have been accounted as having caused 1MB of write.
>> >                      In  other  words: this field represents the number
>> >                      of bytes which this process caused to not  happen,
>> >                      by  truncating pagecache.  A task can cause "nega‐
>> >                      tive" I/O too.  If this task truncates some  dirty
>> >                      pagecache,  some  I/O  which another task has been
>> >                      accounted for (in its  write_bytes)  will  not  be
>> >                      happening.
>> > 
>> >               Note:  In  the  current  implementation, things are a bit
>> >               racy on 32-bit systems: if process A  reads  process  B's
>> >               /proc/[pid]/io  while  process B is updating one of these
>> >               64-bit counters, process  A  could  see  an  intermediate
>> >               result.
>> > 
>> >               Permission  to  access  this file is governed by a ptrace
>> >               access   mode   PTRACE_MODE_READ_FSCREDS    check;    see
>> >               ptrace(2).
> 
> 2)
> Use the netlink bases taststats interface, which gives you the same
> information, but uses far less system resources.
> 
> See:
> http://lxr.bootlin.com/linux/latest/source/Documentation/accounting/taskstats.txt
> http://lxr.bootlin.com/linux/latest/source/Documentation/accounting/taskstats-struct.txt
> https://stackoverflow.com/questions/30617368/sending-netlink-taskstats-message-using-libnl-3

Marc

-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 91 bytes --]

_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

      reply	other threads:[~2018-02-08 10:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-08  8:24 Marc Kleine-Budde
2018-02-08  9:03 ` Alexander Dahl
2018-02-08  9:17   ` Marc Kleine-Budde
2018-02-08 10:19     ` Alexander Dahl
2018-02-08 10:33       ` Marc Kleine-Budde [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=dbf7fc96-ae62-9051-4688-dfddc70b60f7@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=post@lespocky.de \
    --cc=ptxdist@pengutronix.de \
    /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