The principle of sar in linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. It was originally intended to find out the exception of the System load Status, which could not be checked by conventional means, so it was not necessary to study the moving average calculation method of load. Looking at the source code of sar, we found that sar only reads a series of memory files under linux/proc and obtains data through sampling.
Since I have never read the source code related to linux, I don't know much about many styles and variable definitions, and it is very difficult. After finding the root cause in a bunch of files and header definitions, I found the root cause from the main function for a long time. I didn't think it was read from the file, I thought that I could directly use some OS functions to get my own calculations.
Sar uses these files in fscanf to obtain output data.