Giter Club home page Giter Club logo

cpslib's People

Contributors

anmolsarma avatar glossarytingtun avatar k4rtik avatar nibrahim avatar powerinside avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpslib's Issues

Switch to CMake for cross-platform builds

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)

Remove `*Info` structures

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.

get_ prefix unnecessary in exposed APIs

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();

CPU times change based on Kernel version

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.

Refactor Process struct

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.

  • process_pid
  • process_ppid
  • process_name
  • process_exe
  • process_cmdline
  • process_create_time
  • process_parent
  • process_cwd
  • process_username
  • process_uids
  • process_gids
  • process_terminal
  • process_nice
  • process_ionice
  • process_rlimit
  • process_io_counters
  • process_num_ctx_switches
  • process_num_fds
  • process_num_handles
  • process_num_threads
  • process_threads
  • process_cpu_times
  • process_cpu_percent
  • process_cpu_affinity
  • process_memory_info
  • process_memory_info_ex
  • process_memory_percent
  • process_memory_maps
  • process_children
  • process_open_files
  • process_connections
  • process_is_running
  • process_send_signal
  • process_suspend
  • process_resume
  • process_terminate
  • process_kill
  • process_wait

Add OS X support

Notes:

  • Cut a "mac" branch for the actual work.
  • Also need to clean up the headers and build scripts so that it works properly on both platforms.

I will try and fix this.

Use proper types from <sys/types.h> in struct definition

I noticed a few places where int types are used when standard system typedefs are available which would be more appropriate.

Examples.

  1. fields pid, ppid in struct Process. Should be pid_t instead of "unsigned int".
  2. field uid etc - Should be uid_t.
  3. field create_time - Should be time_t (I think).

Most of these are available in <sys/types.h> and we should use them wherever possible.

Unit test each API

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.

[osx] -Wpedantic can not be enabled as we use a GNU extension

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

Standardize on code style

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.

CPU fields change based on Linux version

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.).

Test for process.terminal fails

=========================== 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 ===================

Print coverage information after `make test`

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.