How to get Disk I/O stat by devctl(DCMD_FSYS_STATISTICS)

Why does devctl(DCMD_FSYS_STATISTICS) always return 0 for Disk I/O statistics?

I’m trying to make an utility for disk filesystem’s statistics like
QNX’s fsysinfo utility. But, I’m in trouble to get disk I/O write and
read information because devctl(DCMD_FSYS_STATISTICS) always returns 0
for the following disk I/O statistics.

// s_buf_rphys and s_buf_wphys become always 0 unexptedly
struct fs_stats {
   /* Buffer/DiskIO statistics */
   uint64_t    s_buf_rphys; /* 
   uint64_t    s_buf_wphys; 

According to fsysinfo’s manual page, it is a front end of devctl(DCMD_FSYS_STATISTICS).



By using fsysinfo, you can get disk filesystem’s statistics as

$ fsysinfo /mnt/data
FILESYS     /mnt/data/ [qnx6]
MOUNT       mounted  Sat Jan  1 00:00:00 2000     elapsed 1032 secs
DISK I/O    write       4007   read          56   r/a            0
            direct         0   bad            0
CACHE       write    5578729   read     8799168   rate         99%
            mfu       23732k   mru        9036k   ratio        72%
SYSCALL     open        8032   stat       16038   namei      28540
            write     281212   read        2733   devctl        29
            create      4000   delete      4000
NAMES       exist     148742   enoent     12507   misses      8000
            unsuit         0   stale        276   rate         95%
BMAP        hit       309693   miss         203   rate         99%
VNODES      create      4000   hit       181282   rate         97%
            lock     1302952   recycl      4373
SLAB        map          608   unmap        285   active       323
THREADS     create        60   destro        54   pool           6

The above’s DISK I/O write and read correspond to the following
devctl(DCMD_FSYS_STATISTICS)'s struct fs_stats.

struct fs_stats {
   /* Buffer/DiskIO statistics */
   uint64_t    s_buf_rphys; /* 
   uint64_t    s_buf_wphys; 

So, I wrote a code as follows to get the DiskIO write and read information.

int fd = 0;
if((fd = open("/mnt/data", O_RDONLY)) == -1) {

struct fs_stats data;
if (devctl(fd, DCMD_FSYS_STATISTICS, &data, sizeof(struct fs_stats), NULL) != EOK) {

printf("DISK I/O write %llu read %llu\n", data.s_buf_wphys, data.s_buf_rphys);

But, data.s_buf_wphys(DISK IO write) and data.s_buf_rphys(DISK IO read) are always set as 0 even
when fsysinfo utility reports non-zero values for the DISK IO.

I found the following interesting description about fsysinfo’s ‘-m’ option in its manual.

So, it seems devctl(DCMD_FSYS_STATISTICS)'s default behavior is the
same as fsysinfo’s ‘-m’ option.

Is it possible to make devctl(DCMD_FSYS_STATISTICS) behave like
fsysinfo without -m option?

You should try with io_devctl() function. Search for “DCMD_FSYS_STATISTICS” in QNX help.
Beware that QNX documentation states that : “There is no supported utility which obtains this, the fs_stats is completely undocumented, and may/will change in the future, and certainly has changed in the past.”

Hi, nico

Thank you.

Now, I’m trying to understand the io_devctl()'s usage with
DCMD_FSYS_STATISTICS by reffering the following pages.

The io_devctl() function:


The io_devctl()'s usage seems not so straightforward. Anyway, I’ll try
to find how to do that.

Best regards,

Just realised that io_devctl() is not what you need. I’ve been too fast analysing the search result.
io_devctl() function is for managing devctl() calls to a resource manager you write. Definitively not what you need.
Sorry for this mistake.

Hi, nico

OK, understood. Anyway, thank you :slight_smile:

A relationship between fsysinfo’s -m option and devctl(DCMD_FSYS_STATISTICS) is very mysterious.

I tried the following code on my system :

    int fd = -1;
    struct fs_stats data;
    int err;

    fd = open("/mnt/sdhc-user-up/", O_RDONLY);
    if(fd == -1)

    err = devctl(fd, DCMD_FSYS_STATISTICS, &data, sizeof(struct fs_stats), NULL);
    if (err != EOK)
        printf("devctl() -> %d", err);

    printf("DISK I/O write %llu read %llu\n", data.s_buf_wphys, data.s_buf_rphys);

Each time a file is written, s_buf_wphys is incremented by one and each time a file is read, s_buf_rphys is incremented by one.

It does not work with /tmp.

Umm, I’ll check my code and system again tomorrow. Maybe, I overlooked sth.

In your code, you want to get stats for /mnt/data. What is /mnt/data ? USB drive ? SD card ? …

Sorry for too late reply.

/mnt/data is a hard disk drive partition formatted with QNX6’s Power-Safe filesystem. Still, I’m in the title’s trouble. I assume I overlook a something trivial. I’m totally stuck.