免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2352 | 回复: 2
打印 上一主题 下一主题

io accounting 的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-12-17 09:31 |只看该作者 |倒序浏览
和内核沾点边,来这里求助了,

我想在用户层分别得到使用磁盘,cpu最高的几个进程(或者进程组), 不知道该如何实现,
linux下有个iotop能以类似top(1)的形式显示进程的I/O利用情况,但是那个软件是python写的,我读起来很(非常)吃力,
他大致是先在从proc读到进程列表,然后又读了 /proc/xxpid/status, 然后用netlink获得某些进程的taskstats

不清楚从proc pid status下他想读什么,貌似是读进程的uid,gid之类的东东



  1. // /usr/include/linux/taskstats.h

  2. struct taskstats {

  3. ...
  4.         __u8        ac_flag;                /* Record flags */
  5.         __u8        ac_nice;                /* task_nice */

  6.         __u64        cpu_count __attribute__((aligned(8)));
  7.         __u64        cpu_delay_total;

  8.         /* Following four fields atomically updated using task->delays->lock */

  9.         /* Delay waiting for synchronous block I/O to complete
  10.          * does not account for delays in I/O submission
  11.          */
  12.         __u64        blkio_count;
  13.         __u64        blkio_delay_total;

  14.         /* Delay waiting for page fault I/O (swap in only) */
  15.         __u64        swapin_count;
  16.         __u64        swapin_delay_total;

  17.         /* cpu "wall-clock" running time
  18.          * On some architectures, value will adjust for cpu time stolen
  19.          * from the kernel in involuntary waits due to virtualization.
  20.          * Value is cumulative, in nanoseconds, without a corresponding count
  21.          * and wraps around to zero silently on overflow
  22.          */
  23.         __u64        cpu_run_real_total;

  24.         /* cpu "virtual" running time
  25.          * Uses time intervals seen by the kernel i.e. no adjustment
  26.          * for kernel's involuntary waits due to virtualization.
  27.          * Value is cumulative, in nanoseconds, without a corresponding count
  28.          * and wraps around to zero silently on overflow
  29.          */
  30.         __u64        cpu_run_virtual_total;
  31.         /* Delay accounting fields end */
  32.         /* version 1 ends here */

  33.         /* Basic Accounting Fields start */
  34.         char        ac_comm[TS_COMM_LEN];        /* Command name */
  35.         __u8        ac_sched __attribute__((aligned(8)));
  36.                                         /* Scheduling discipline */
  37.         __u8        ac_pad[3];
  38.         __u32        ac_uid __attribute__((aligned(8)));
  39.                                         /* User ID */
  40.         __u32        ac_gid;                        /* Group ID */
  41.         __u32        ac_pid;                        /* Process ID */
  42.         __u32        ac_ppid;                /* Parent process ID */
  43.         __u32        ac_btime;                /* Begin time [sec since 1970] */
  44.         __u64        ac_etime __attribute__((aligned(8)));
  45.                                         /* Elapsed time [usec] */
  46.         __u64        ac_utime;                /* User CPU time [usec] */
  47.         __u64        ac_stime;                /* SYstem CPU time [usec] */
  48.         __u64        ac_minflt;                /* Minor Page Fault Count */
  49.         __u64        ac_majflt;                /* Major Page Fault Count */
  50. ...

  51.         /* The following four fields are I/O statistics of a task. */
  52.         __u64        read_char;                /* bytes read */
  53.         __u64        write_char;                /* bytes written */
  54.         __u64        read_syscalls;                /* read syscalls */
  55.         __u64        write_syscalls;                /* write syscalls */
  56.         /* Extended accounting fields end */

  57. #define TASKSTATS_HAS_IO_ACCOUNTING
  58.         /* Per-task storage I/O accounting starts */
  59.         __u64        read_bytes;                /* bytes of read I/O */
  60.         __u64        write_bytes;                /* bytes of write I/O */
  61.         __u64        cancelled_write_bytes;        /* bytes of cancelled write I/O */

  62.         __u64  nvcsw;                        /* voluntary_ctxt_switches */
  63.         __u64  nivcsw;                        /* nonvoluntary_ctxt_switches */

  64.         /* time accounting for SMT machines */
  65.         __u64        ac_utimescaled;                /* utime scaled on frequency etc */
  66.         __u64        ac_stimescaled;                /* stime scaled on frequency etc */
  67.         __u64        cpu_scaled_run_real_total; /* scaled cpu_run_real_total */
  68. };

复制代码


貌似和磁盘io有关的是


  1. #define TASKSTATS_HAS_IO_ACCOUNTING
  2.         /* Per-task storage I/O accounting starts */
  3.         __u64        read_bytes;                /* bytes of read I/O */
  4.         __u64        write_bytes;                /* bytes of write I/O */
  5.         __u64        cancelled_write_bytes;        /* bytes of cancelled write I/O */           这个如何理解呢???
复制代码


cancelled_write_bytes是怎么一回事?
另外和cpu利用率有关的是哪些成员? 最后说的SMT又是什么意思呢?


要是想得到利用率的话是不是需要读取两次相减再除以时间间隔?还是有什么别的直接的办法?
这里面讲的task和process的区别是什么呢? task带表进程组 process带表进程?
另外再请问有没有除proc外的其他接口直接获得所有进程号的呢?


问了好多问题,希望大家不吝赐教
谢谢!


http://kernelnewbies.org/Linux_2 ... ed22c281ca9ab54bb12

IO Accounting

The present per-task IO accounting isn't very useful. It simply counts the number of bytes passed into read() and write(). So if a process reads 1MB from an already-cached file, it is accused of having performed 1MB of I/O, which is 'wrong'. So this IO accounting implements per-process statistics of "storage I/O" (i.e.: I/O that _really_ does I/O on the storage device - Linux already had I/O storage statistics but it's not per-task). The data is reported through taskstats and procfs (/proc/$PID/io) (commit 1, 2, 3, 4, 5, 6, 7, 8, 10, 11)

最后一句话说的proc/$id/io是说的新的io accountting还是前面说的present per-task IO accounting ?
如果是新的的话就可以直接读proc下的pid下的io了,比netlink更方便, 不知道效率上是不是会比netlink差

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
2 [报告]
发表于 2008-12-17 09:49 |只看该作者
如果单说读出进程CPU的利用率,应该ps就可以实现吧。

论坛徽章:
0
3 [报告]
发表于 2008-12-17 09:53 |只看该作者
还有磁盘io,不想用shell实现
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP