diff options
author | Benoît Dejean <bdejean@src.gnome.org> | 2004-07-03 13:28:59 +0000 |
---|---|---|
committer | Benoît Dejean <bdejean@src.gnome.org> | 2004-07-03 13:28:59 +0000 |
commit | 50f086cb684355a25f22a92c4cee76365ac4945f (patch) | |
tree | 3b62b6f893a6ba8dc6c6cd60192004d3ec747766 /sysdeps/linux/glibtop_server.h | |
parent | 8eae848c3fa5258b926d9a4e2c3f4a643b9c7a7c (diff) | |
download | libgtop-50f086cb684355a25f22a92c4cee76365ac4945f.tar.gz |
Added. These functions are commonly used. Misc cleanups.
* glibtop_server.h:
* glibtop_server.c: (try_file_to_buffer), (file_to_buffer): Added. These
functions are commonly used. Misc cleanups.
* cpu.c: (glibtop_get_cpu_s):
* loadavg.c: (glibtop_get_loadavg_s):
* mem.c: (glibtop_get_mem_s):
* open.c: (glibtop_open_s):
* swap.c: (glibtop_get_swap_s):
* sysinfo.c: (init_sysinfo):
* uptime.c: (glibtop_get_uptime_s): Replaced open/read/close by file_to_buffer().
Diffstat (limited to 'sysdeps/linux/glibtop_server.h')
-rw-r--r-- | sysdeps/linux/glibtop_server.h | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/sysdeps/linux/glibtop_server.h b/sysdeps/linux/glibtop_server.h index a522cefb..ab1d32aa 100644 --- a/sysdeps/linux/glibtop_server.h +++ b/sysdeps/linux/glibtop_server.h @@ -21,8 +21,10 @@ Boston, MA 02111-1307, USA. */ -#ifndef __GLIBTOP_SERVER_H__ -#define __GLIBTOP_SERVER_H__ +#ifndef __LINUX__GLIBTOP_SERVER_H__ +#define __LINUX__GLIBTOP_SERVER_H__ + +#include <glibtop.h> #include <glib.h> @@ -36,8 +38,10 @@ G_BEGIN_DECLS #define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z) + unsigned get_pageshift(); + static inline char * skip_token (const char *p) { @@ -55,6 +59,7 @@ skip_multiple_token (const char *p, size_t count) return (char *)p; } + static inline char * skip_line (const char *p) { @@ -62,12 +67,29 @@ skip_line (const char *p) return (char *) (*p ? p+1 : p); } + unsigned long long get_scaled(const char *buffer, const char *key); +/* aborts on error */ +void +file_to_buffer(glibtop *server, char *buffer, const char *filename); + +/* return < 0 on error, otherwise 0 on success */ int -proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid); +try_file_to_buffer(char *buffer, const char *format, ...); + + +/* some inline functions that wrap proc path + * as fast as macros :) + */ + +static inline int +proc_file_to_buffer (char *buffer, const char *fmt, pid_t pid) +{ + return try_file_to_buffer(buffer, fmt, pid); +} static inline int proc_stat_to_buffer (char *buffer, pid_t pid) @@ -87,6 +109,7 @@ proc_statm_to_buffer (char *buffer, pid_t pid) return proc_file_to_buffer (buffer, "/proc/%d/statm", pid); } + static inline char * proc_stat_after_cmd (char *p) { @@ -121,4 +144,4 @@ proc_stat_after_cmd (char *p) G_END_DECLS -#endif +#endif /* __LINUX__GLIBTOP_SERVER_H__ */ |