procfs: fix parseStat comment and reuse line variable (#855)
parseStat reads /proc/stat, not /proc/[pid]/stat. Also use the existing line variable with strings.Fields instead of calling scanner.Text twice.
Signed-off-by: zanarelli zanarelli.dev@gmail.com
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
procfs
This package provides functions to retrieve system, kernel, and process metrics from the pseudo-filesystems /proc and /sys.
WARNING: This package is a work in progress. Its API may still break in backwards-incompatible ways without warnings. Use it at your own risk.
Usage
The procfs library is organized by packages based on whether the gathered data is coming from /proc, /sys, or both. Each package contains an
FStype which represents the path to either /proc, /sys, or both. For example, cpu statistics are gathered from/proc/statand are available via the root procfs package. First, the proc filesystem mount point is initialized, and then the stat information is read.Some sub-packages such as
blockdevice, require access to both the proc and sys filesystems.Package Organization
The packages in this project are organized according to (1) whether the data comes from the
/procor/sysfilesystem and (2) the type of information being retrieved. For example, most process information can be gathered from the functions in the rootprocfspackage. Information about block devices such as disk drives is available in theblockdevicessub-package.Building and Testing
The procfs library is intended to be built as part of another application, so there are no distributable binaries.
However, most of the API includes unit tests which can be run with
make test.Updating Test Fixtures
The procfs library includes a set of test fixtures which include many example files from the
/procand/sysfilesystems. These fixtures are included as a ttar file which is extracted automatically during testing. To add/update the test fixtures, first ensure thetestdata/fixturesdirectory is up to date by removing the existing directory and then extracting the ttar file usingmake testdata/fixtures/.unpackedor justmake test.Next, make the required changes to the extracted files in the
testdata/fixturesdirectory. When the changes are complete, runmake update_fixturesto create a newfixtures.ttarfile based on the updatedfixturesdirectory. And finally, verify the changes usinggit diff testdata/fixtures.ttar.