How can I access to linux file system read/write speed in c program?
<p>I need to access to linux kernel metrics, one of them is the file system read and write speed.</p>

<p>I know there are commands such as 'dd', 'hdparm' and 'iotop' that give information about the file system's data transfer speed, but I don't know how can I read this information in my C program and then, for example, I print the speed in console.  </p>

<p>If there is a file which it has speed information it can be read file in C program and access to speed.
How can this be done? 
Thank you. <img src="https://i.stack.imgur.com/QNKoX.png" alt="enter image description here"></p>

<hr>

<p>I read <a href="https://www.kernel.org/doc/Documentation/iostats.txt" rel="nofollow noreferrer">iostats.txt</a> documentation.The file <strong><em>/proc/diskstats</em></strong> has 11 parameter for each row. According to iostats.txt, for each row 3rd parameter is total number of reading sectors and 4th parameter is the total number of reading time in milliseconds. 
If <a href="https://en.wikipedia.org/wiki/Disk_sector" rel="nofollow noreferrer">every sector is 4096 bytes</a>, so the reading speed formula must be:
<a href="http://latex.codecogs.com/gif.latex?speed%20%3D%20%28%28%243%29%20*%204096%20%29/%20%244%20*%201000%20MB%20per%20Seconds%20%28MB/Sec%29" rel="nofollow noreferrer">speed = (($3) * 4096 )/ $4</a>      ($x means parameter x)</p>

<p><a href="https://i.stack.imgur.com/4Ja7F.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4Ja7F.gif" alt="enter image description here"></a></p>

<p>but when I calculated reading speed of my flash memory, it was 0.2 MB/sec although it must be about 7 Mb/sec according to the command  <strong><em>iostat -k 2</em></strong>  or gnu disk utility (graphical app).
How can I evaluate speed from these parameters, what is correct formula for evaluating speed in MB/Sec ? </p>