hamon-in / cpslib Goto Github PK
View Code? Open in Web Editor NEWCross platform library to gather process and system information.
License: MIT License
Cross platform library to gather process and system information.
License: MIT License
How are we going to handle cross-platform builds?
I don't think that make is really suited for this task.
So we have to basically chose between CMake and Autotools. I already know CMake and libgit2 is using it as well(they're doing a good job at supporting a lot of platforms and bindings)
Things like DiskPartitionInfo
exist just to hold the count of partitions. cpslib
is a low level library so it should be fine to have two functions get_partition_count
and then get_partition_info
to get the list of paritions and the information. This will allow us to drop one struct.
The structs are named inconsistently. Fix it.
This looks like good advice https://spin.atomicobject.com/2016/08/26/makefile-c-projects/
Ref: nibrahim@bdeafd8
The following APIs currently have get_
prefixed in their names. This is both inconsistent with psutil and with rest of the APIs. Consider renaming.
Process *get_process(unsigned int);
unsigned long int get_boot_time();
UsersInfo *get_users();
The CPU times available change based on the Kernel version. Psutils does this properly. We use a static structure and need some way of changing this when the library is compiled.
We can't prefetch all the properties for the user. We shouldn't be inconsistent if a property is prefetched or up-to-date. Hence we have to return always an up-to-date value.
The Process should be an opaque data type and we should provide the following methods to fetch the relevant property.
Notes:
I will try and fix this.
I noticed a few places where int types are used when standard system typedefs are available which would be more appropriate.
Examples.
Most of these are available in <sys/types.h> and we should use them wherever possible.
Generated Makefile doesn't have these CFLAGS anymore.
It might be a good idea to set up a test infrastructure such that we could verify compatibility of each API's result with corresponding psutil API's.
Unit testing will also, of course, help prevent future breaking changes.
If I add -pedantic
/-Wpedantic
to the Makefile, I receive the following errors:
$ make
cc -fPIC -Wall -Werror -Wunused -Wextra -Wpedantic -O0 -g -std=c11 -fprofile-arcs -ftest-coverage -c -o common.o common.c
In file included from common.c:5:
./common.h:36:14: error: token pasting of ',' and __VA_ARGS__ is a GNU extension [-Werror,-Wgnu-zero-variadic-macro-arguments]
log_err(M, ##__VA_ARGS__); \
^
./common.h:25:55: error: token pasting of ',' and __VA_ARGS__ is a GNU extension [-Werror,-Wgnu-zero-variadic-macro-arguments]
__LINE__, __FUNCTION__, errno, clean_errno(), ##__VA_ARGS__)
^
./common.h:36:14: error: token pasting of ',' and __VA_ARGS__ is a GNU extension [-Werror,-Wgnu-zero-variadic-macro-arguments]
log_err(M, ##__VA_ARGS__); \
^
./common.h:25:55: error: token pasting of ',' and __VA_ARGS__ is a GNU extension [-Werror,-Wgnu-zero-variadic-macro-arguments]
__LINE__, __FUNCTION__, errno, clean_errno(), ##__VA_ARGS__)
^
4 errors generated.
make: *** [common.o] Error 1
No clean solution exists. See: https://stackoverflow.com/questions/5588855/standard-alternative-to-gccs-va-args-trick
OSX port already uses clang-format
style, most of the rest of the code doesn't. See section on Formatting at How to C in 2016
We could perhaps use the following style (allowing short fns on single line and keeping indent width as 2):
clang-format -style="{BasedOnStyle: llvm, IndentWidth: 2, KeepEmptyLinesAtTheStartOfBlocks: false}"
Open for discussion.
Different Linux Kernels provide different CPU times and this should be taken into account when returning the CPU times and other CPU related information (percentages etc.).
=========================== FAILURES ===========================
___________________________ test_process ____________________________
flush = None
def test_process(flush):
cpid = os.getpid()
psu = psutil.Process(cpid)
psl = P.get_process(cpid)
assert psu.pid == psl.pid
assert psu.ppid() == psl.ppid
assert psu.name() == ffi.string(psl.name)
assert psu.exe() == ffi.string(psl.exe)
assert " ".join(psu.cmdline()) == ffi.string(psl.cmdline)
assert psu.create_time() == psl.create_time
uids = psu.uids()
assert uids.real == psl.uid
assert uids.effective == psl.euid
assert uids.saved == psl.suid
gids = psu.gids()
assert gids.real == psl.gid
assert gids.effective == psl.egid
assert gids.saved == psl.sgid
assert psu.username() == ffi.string(psl.username)
> assert psu.terminal() == ffi.string(psl.terminal)
E assert '/dev/pts/2' == '/dev/null'
E - /dev/pts/2
E + /dev/null
test_process.py:26: AssertionError
==================== 1 failed, 16 passed in 4.08 seconds ===================
It would be nice to be able to build a .so
with a single make shared
or something similar.
Currently, pslib_linux.c is being used for OS X as well.
Currently we need to execute something like the following to obtain coverage information:
$ gcov pslib_osx.c
File 'pslib_osx.c'
Lines executed:73.56% of 696
pslib_osx.c:creating 'pslib_osx.c.gcov'
It will be good to have this automatically printed at the end of make test
.
See Types section in How to C in 2016
See also: #13
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.