Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Merge branch 'master' into osx
Merge Notes: - skipped merging gcov related changes, didn't work on osx. - skipped merging tests for unimplemented APIs - test infra exposed some Linux-specific in cpu_times(), need to get rid of them. Tests skip them (TODO: tests should be aware of platform in the future)
- Loading branch information
Showing
13 changed files
with
509 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
# pycpslib.py | ||
|
||
import os | ||
|
||
from cffi import FFI | ||
|
||
ffi = FFI() | ||
project_root = os.path.abspath("../../") | ||
|
||
ffi.set_source("pycpslib", | ||
"""#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/types.h> | ||
#include <unistd.h> | ||
#include "pslib.h" | ||
""", | ||
libraries = ["pslib"], | ||
library_dirs = [project_root], | ||
include_dirs = [project_root]) | ||
|
||
|
||
ffi.cdef(""" | ||
typedef struct { | ||
char *device; | ||
char *mountpoint; | ||
char *fstype; | ||
char *opts; | ||
} DiskPartition; /* TBD: Pluralise */ | ||
typedef struct { | ||
int nitems; | ||
DiskPartition *partitions; | ||
} DiskPartitionInfo; | ||
typedef struct { | ||
unsigned long total; | ||
unsigned long used; | ||
unsigned long free; | ||
float percent; | ||
} DiskUsage; | ||
typedef struct { | ||
char *name; | ||
unsigned long readbytes; | ||
unsigned long writebytes; | ||
unsigned long reads; | ||
unsigned long writes; | ||
unsigned long readtime; | ||
unsigned long writetime; | ||
} DiskIOCounters; | ||
typedef struct { | ||
int nitems; | ||
DiskIOCounters *iocounters; | ||
} DiskIOCounterInfo; | ||
typedef struct { | ||
char * name; | ||
unsigned long bytes_sent; | ||
unsigned long bytes_recv; | ||
unsigned long packets_sent; | ||
unsigned long packets_recv; | ||
unsigned long errin; | ||
unsigned long errout; | ||
unsigned long dropin; | ||
unsigned long dropout; | ||
} NetIOCounters; | ||
typedef struct { | ||
int nitems; | ||
NetIOCounters *iocounters; | ||
} NetIOCounterInfo; | ||
typedef struct { | ||
char *username; | ||
char *tty; | ||
char *hostname; | ||
float tstamp; | ||
} Users; | ||
typedef struct { | ||
int nitems; | ||
Users *users; | ||
} UsersInfo; | ||
UsersInfo *get_users(void); | ||
long int get_boot_time(void); | ||
typedef struct { | ||
unsigned long total; | ||
unsigned long available; | ||
float percent; | ||
unsigned long used; | ||
unsigned long free; | ||
unsigned long active; | ||
unsigned long inactive; | ||
unsigned long buffers; | ||
unsigned long cached; | ||
} VmemInfo; | ||
typedef struct { | ||
unsigned long total; | ||
unsigned long used; | ||
unsigned long free; | ||
float percent; | ||
unsigned long sin; | ||
unsigned long sout; | ||
} SwapMemInfo; | ||
typedef struct { | ||
double user; | ||
double system; | ||
double idle; | ||
double nice; | ||
double iowait; | ||
double irq; | ||
double softirq; | ||
double steal; | ||
double guest; | ||
double guest_nice; | ||
} CpuTimes; | ||
CpuTimes *cpu_times(int); | ||
int cpu_count(int); | ||
CpuTimes *cpu_times_percent(int, CpuTimes *); | ||
double *cpu_util_percent(int percpu, CpuTimes *prev_times); | ||
typedef struct { | ||
int pid; | ||
int ppid; | ||
char *name; | ||
char *exe; | ||
char *cmdline; | ||
double create_time; | ||
unsigned int uid; | ||
unsigned int euid; | ||
unsigned int suid; | ||
unsigned int gid; | ||
unsigned int egid; | ||
unsigned int sgid; | ||
char *username; | ||
char *terminal; | ||
} Process; | ||
""") | ||
|
||
if __name__ == '__main__': | ||
ffi.compile() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup(name = "pycpslib", | ||
version = "0.1", | ||
packages = find_packages(), | ||
setup_requires=["cffi>=1.0.0"], | ||
cffi_modules=["pycpslib_build.py:ffi"], | ||
install_requires = ["cffi>=1.0.0"], | ||
author = "Noufal Ibrahim", | ||
author_email = "noufal@nibrahim.net.in", | ||
description = "Python bindings for the cpslib library", | ||
license = "MIT", | ||
keywords = "tests", | ||
url = "http://github.com/nibrahim/cpslib", | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.