New upstream version 2.38.0
This commit is contained in:
784
sysdeps/linux/ChangeLog
Normal file
784
sysdeps/linux/ChangeLog
Normal file
@@ -0,0 +1,784 @@
|
||||
2007-05-20 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* *.c:
|
||||
|
||||
Got rid of glibtop_init_s calls.
|
||||
If i'm right, these are only no-op and the legacy stub/ don't
|
||||
have any calls to them, so it's should harmless.
|
||||
So let's try it.
|
||||
|
||||
2007-05-19 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* proclist.c: (glibtop_get_proclist_s):
|
||||
|
||||
Fixed warnings.
|
||||
|
||||
2007-05-17 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* procopenfiles.c: (glibtop_get_proc_open_files_s):
|
||||
|
||||
Added missing sizeof.
|
||||
|
||||
2007-05-07 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* procwd.c:
|
||||
|
||||
Always set buf->number.
|
||||
|
||||
2007-05-07 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* glibtop_private.c (safe_readlink):
|
||||
|
||||
Simplified.
|
||||
|
||||
* procopenfiles.c:
|
||||
|
||||
Use safe_readlink.
|
||||
|
||||
2007-05-07 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* procwd.c:
|
||||
|
||||
Implemented.
|
||||
|
||||
* glibtop_private.c (safe_readlink):
|
||||
|
||||
New function.
|
||||
|
||||
2007-03-13 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* fsusage.c: (get_sys_path), (linux_2_6_0):
|
||||
|
||||
Fixed stat parsing for md devices.
|
||||
Patch by Martin Bailey <martin@pcalpha.com>.
|
||||
|
||||
2007-02-15 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* procmap.c: (add_smaps):
|
||||
|
||||
Some more const.
|
||||
|
||||
2007-01-14 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* procmap.c: (glibtop_get_proc_map_s):
|
||||
* procopenfiles.c: (parse_file):
|
||||
|
||||
Fixed stack overflow in proc_map.
|
||||
Switched to Glibc getline because fgets gets fooled by long
|
||||
lines.
|
||||
Closes #396477.
|
||||
|
||||
2007-01-11 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* glibtop_private.c: (get_scaled):
|
||||
|
||||
Replaced two strstr by a hand-written loop in this critical code.
|
||||
|
||||
2006-09-11 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* procmap.c: (glibtop_get_proc_map_s):
|
||||
|
||||
Fixed parsing s?maps on 64bit kernel.
|
||||
Closes #355290.
|
||||
Removed useless casts.
|
||||
|
||||
2006-08-10 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* open.c: (glibtop_open_s):
|
||||
|
||||
Only print the warning if
|
||||
(number of real cpu's) != (number of cpu's monitored).
|
||||
Patch by Wouter Bolsterlee (uws) <uws+gnome@xs4all.nl>.
|
||||
Closes #350705.
|
||||
|
||||
2006-07-27 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* netload.c: (glibtop_get_netload_s):
|
||||
|
||||
Updated implementation.
|
||||
|
||||
2006-07-27 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* glibtop_private.c: (has_sysfs):
|
||||
* glibtop_private.h:
|
||||
* netload.c: (glibtop_get_netload_s):
|
||||
* open.c: (set_linux_version):
|
||||
|
||||
New has_sysfs function to avoid stating
|
||||
over and over '/sys' on each netload call.
|
||||
|
||||
2006-04-02 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* msg_limits.c: (glibtop_get_msg_limits_s):
|
||||
* sem_limits.c: (glibtop_get_sem_limits_s):
|
||||
* shm_limits.c: (glibtop_get_shm_limits_s):
|
||||
|
||||
Fixed a bunch of warnings.
|
||||
|
||||
2006-01-23 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* procmap.c: (glibtop_get_proc_map_s):
|
||||
|
||||
I can't believe i've been so stupid :)
|
||||
Uses smaps if linux > 2.6.14.
|
||||
|
||||
2005-12-15 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* proclist.c: (glibtop_get_proclist_s):
|
||||
|
||||
Fixed when which == GLIBTOP_KERN_PROC_UID.
|
||||
Closes #324055.
|
||||
|
||||
2005-12-14 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* open.c: (glibtop_open_s):
|
||||
|
||||
Implemented server->real_ncpu.
|
||||
Add a warning to display ncpu and real_ncpu on open.
|
||||
|
||||
2005-12-13 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* cpu.c: (glibtop_get_cpu_s):
|
||||
* glibtop_private.c: (get_scaled), (check_cpu_line):
|
||||
* glibtop_private.h:
|
||||
* open.c: (glibtop_open_s):
|
||||
* proctime.c: (glibtop_get_proc_time_s):
|
||||
|
||||
Fixed server->ncpu usage (SMP handling). Need more testing.
|
||||
|
||||
2005-12-12 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* procmap.c: (add_smaps), (glibtop_get_proc_map_s):
|
||||
|
||||
Implemented smap support.
|
||||
Closes #320710.
|
||||
|
||||
2005-12-12 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* proclist.c: (glibtop_get_proclist_s):
|
||||
|
||||
Improved so that it doesn't stat(2) every /proc/<PID>/.
|
||||
|
||||
2005-12-07 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* procmap.c: (glibtop_get_proc_map_s):
|
||||
|
||||
Small improvements.
|
||||
Use g_array_sized_new instead of g_array_new with
|
||||
reserved_size = 100.
|
||||
Don't use g_array_append_val to avoid copying
|
||||
glibtop_map_entries. Use g_array_set_size(size + 1) instead.
|
||||
|
||||
I've run a little python benchmark and this shows a little
|
||||
speedup. I hope this would be more sensible in
|
||||
gnome-system-monitor (glibtop_get_procmap is intensively used for
|
||||
the 'Writable Memory' column).
|
||||
|
||||
2005-10-29 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* glibtop_private.c: (read_boot_time):
|
||||
|
||||
Removed 1 g_return_*.
|
||||
|
||||
2005-08-15 Benoît Dejean <benoit@placenet.org>
|
||||
|
||||
* cpu.c: (glibtop_get_cpu_s):
|
||||
|
||||
Do not add irq, softirq and iowait to idle.
|
||||
|
||||
2005-08-04 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* open.c: (set_linux_version), (glibtop_open_s):
|
||||
|
||||
Reworked a bit.
|
||||
Warn on 2.6 without /sys.
|
||||
|
||||
2005-08-03 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* netload.c: (glibtop_get_netload_s):
|
||||
|
||||
Fixed for people running 2.6 without /sys.
|
||||
|
||||
2005-08-02 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* glibtop_server.h:
|
||||
|
||||
Added GLIBTOP_SUID_NETLIST.
|
||||
|
||||
2005-07-23 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* uptime.c:
|
||||
|
||||
Fixed .flags.
|
||||
|
||||
2005-07-22 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* glibtop_private.c: (get_page_size):
|
||||
* glibtop_private.h:
|
||||
* procmem.c: (glibtop_get_proc_mem_s):
|
||||
* procsegment.c: (glibtop_get_proc_segment_s):
|
||||
|
||||
Cached getpagesize().
|
||||
|
||||
2005-07-09 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* netload.c: (read_value), (linux_2_6_stats), (linux_2_0_stats),
|
||||
(linux_2_4_stats), (glibtop_get_netload_s): Split implementations.
|
||||
New (simpler) implementation for 2.6 (/sys is so nice ;)
|
||||
|
||||
2005-07-07 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* glibtop_private.c: (read_boot_time), (get_boot_time): Cached boot_time.
|
||||
|
||||
2005-07-06 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
Et m***e ... CVS got me. I wanted to commit a single change on the
|
||||
toplevel configure.in but commited the whole tree. Sorry.
|
||||
|
||||
* glibtop_private.c:
|
||||
* glibtop_private.h:
|
||||
* proctime.c:
|
||||
* uptime.c:
|
||||
|
||||
Added new function get_boot_time.
|
||||
|
||||
Retrieve boot_time from /proc/stat.
|
||||
|
||||
2005-06-13 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* glibtop_private.c: (try_file_to_buffer): Ensures buffer is 0-terminated.
|
||||
|
||||
2005-06-13 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* swap.c: (glibtop_get_swap_s): Added pagein/pageout for linux 2.6.
|
||||
|
||||
2005-05-26 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* siglist.c: Fixed compilation on mips. Closes #304570.
|
||||
|
||||
2005-04-01 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* glibtop_private.h: Fixed gcc-4.0 warnings.
|
||||
|
||||
2005-03-29 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* fsusage.c: (get_partition): Removed a g_return_if_fail.
|
||||
|
||||
2005-03-27 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* loadavg.c: (glibtop_get_loadavg_s):
|
||||
* uptime.c: (glibtop_get_uptime_s): Fixed behaviour when locale is not C
|
||||
s/strtod/g_ascii_strod/. (strtod behaviour is locale specific, which is bad
|
||||
because linux /proc is always C.)
|
||||
|
||||
2005-03-25 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* netload.c: (get_ipv6): s/strerror/g_strerror/
|
||||
|
||||
2005-03-25 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* siglist.c: Updated.
|
||||
|
||||
2005-02-15 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* fsusage.c: Fixed G_GNUC attribute usage.
|
||||
|
||||
2005-01-22 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* procopenfiles.c: (parse_file), (get_all), (inet_socket_parser),
|
||||
(get_all_inet_sockets), (local_socket_parser),
|
||||
(get_all_local_sockets), (glibtop_get_proc_open_files_s): Total rewrite.
|
||||
socket/localsocket should be much faster.
|
||||
|
||||
2005-01-16 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* glibtop_private.c: (skip_token):
|
||||
* glibtop_private.h: Uninlined.
|
||||
|
||||
2005-01-13 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* fsusage.c: (get_partition), (get_sys_path), (linux_2_6_0): Reworked.
|
||||
Should works with IDE, SCSI. DM support is ready, but i don't know why
|
||||
their /stat is empty ...
|
||||
|
||||
2005-01-12 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* procopenfiles.c: (get_all_sockets),
|
||||
(glibtop_get_proc_open_files_s): Parses /proc/net/tcp only once.
|
||||
|
||||
2005-01-10 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* procopenfiles.c: (get_socket_endpoint): Fixed.
|
||||
|
||||
2005-01-10 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* glibtop_server.h:
|
||||
* procopenfiles.c: (get_socket_endpoint): Disabled.
|
||||
|
||||
(glibtop_get_proc_open_files_s): Secured -> g_snprintf.
|
||||
|
||||
2004-12-23 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* fsusage.c: (_glibtop_linux_get_fsusage_read_write):
|
||||
* glibtop_private.h: Marked private functions G_GNUC_INTERNAL.
|
||||
|
||||
2004-11-30 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* proclist.c: (glibtop_get_proclist_s): Glibified. g_array_free which
|
||||
returns a char* ! If you want to change this, please tell them
|
||||
http://bugzilla.gnome.org/show_bug.cgi?id=145767 .
|
||||
|
||||
2004-11-28 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* Makefile.am:
|
||||
* cpu.c:
|
||||
* fsusage.c:
|
||||
* glibtop_private.c: (get_scaled), (try_file_to_buffer),
|
||||
(file_to_buffer): Added
|
||||
* glibtop_private.h: Added
|
||||
* glibtop_server.c: Removed
|
||||
* glibtop_server.h:
|
||||
* loadavg.c:
|
||||
* mem.c:
|
||||
* netload.c:
|
||||
* open.c:
|
||||
* prockernel.c:
|
||||
* procmem.c:
|
||||
* procsegment.c:
|
||||
* procsignal.c:
|
||||
* procstate.c:
|
||||
* proctime.c:
|
||||
* procuid.c:
|
||||
* swap.c:
|
||||
* sysinfo.c:
|
||||
* uptime.c: Moved linux impl utils function from glibtop_server.* to
|
||||
glibtob_private.* because glibtop_server.h is a public header.
|
||||
|
||||
2004-11-15 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* netload.c: (get_ipv6), (glibtop_get_netload_s): Added a check for NULL
|
||||
pointer when wlaking though interfaces (though i don't understand why some
|
||||
interface don't have an ifa_addr).
|
||||
Move all ipv6 code into a separate function. Added a paranoid check on
|
||||
getifaddrs.
|
||||
|
||||
2004-11-13 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* netlist.c: (glibtop_get_netlist_s): Killed warning.
|
||||
|
||||
2004-10-26 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* proctime.c: (glibtop_get_proc_time_s): Set .rtime. At last !
|
||||
|
||||
2004-09-24 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* loadavg.c: (glibtop_get_loadavg_s):
|
||||
* msg_limits.c: (glibtop_get_msg_limits_s):
|
||||
* shm_limits.c: (glibtop_get_shm_limits_s): Small cleanup.
|
||||
|
||||
2004-09-23 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* glibtop_server.c:
|
||||
* glibtop_server.h:
|
||||
* procmem.c: (glibtop_get_proc_mem_s):
|
||||
* procsegment.c: (glibtop_get_proc_segment_s): Removed get_pageshift().
|
||||
Every one can affort a * instead of a >>, no need for this kind of
|
||||
non-reentrant optimization. Saved 144B (obviously perfect cleanup ;)
|
||||
|
||||
2004-09-22 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* glibtop_server.c: Removed #warning, my gcc is not buggy anymore.
|
||||
|
||||
2004-09-21 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* fsusage.c: (linux_2_6_0), (linux_2_4_0),
|
||||
(_glibtop_linux_get_fsusage_read_write): Back to previous version.
|
||||
Now set .flags correctly.
|
||||
|
||||
2004-09-19 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* fsusage.c: (linux_2_6_0), (linux_2_4_0),
|
||||
(_glibtop_linux_get_fsusage_read_write): Updated to match new prototype.
|
||||
|
||||
2004-09-19 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* mem.c: (glibtop_get_mem_s): Added missing memset( , 0, ).
|
||||
|
||||
2004-08-03 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* glibtop_server.h: Added next_token(). Changed skip_token(),
|
||||
i hope it won't break any bad code.
|
||||
* procstate.c: (glibtop_get_proc_state_s): Used next_token.
|
||||
* proctime.c: (glibtop_get_proc_time_s): Implemented .start_time
|
||||
the way it ought to be. Clean ups
|
||||
|
||||
2004-07-22 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* netload.c: (glibtop_get_netload_s): Fixed leak.
|
||||
* proctime.c: (glibtop_get_proc_time_s): Don't set .timeout anymore.
|
||||
|
||||
2004-07-17 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* Makefile.am:
|
||||
* fsusage.c: (linux_2_6_0), (linux_2_4_0),
|
||||
(_glibtop_linux_get_fsusage_read_write): Added to repository. WIP.
|
||||
|
||||
|
||||
* glibtop_server.h: LINUX_VERSION -> LINUX_VERSION_CODE
|
||||
|
||||
* netload.c: (glibtop_get_netload_s): Cleanups. Added support for
|
||||
hardware address. s/LINUX_VERSION/LINUX_VERSION_CODE/
|
||||
|
||||
* open.c: (get_linux_version): s/LINUX_VERSION/LINUX_VERSION_CODE/
|
||||
|
||||
* procmap.c: (glibtop_get_proc_map_s): glibify: used GArray
|
||||
|
||||
* procuid.c: (glibtop_get_proc_uid_s): s/LINUX_VERSION/LINUX_VERSION_CODE/.
|
||||
Used Linux MKDEV.
|
||||
|
||||
2004-07-15 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* procstate.c: (glibtop_get_proc_state_s): Wake, we're libgtop2.7.x,
|
||||
lets get rid of old buf->state format. Now using bitfield instead
|
||||
letters.
|
||||
|
||||
2004-07-07 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* procargs.c: (glibtop_get_proc_args_s): Fixed. error is now correctly
|
||||
set to NULL before is's used. Fixed max_len behaviour.
|
||||
|
||||
2004-07-03 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* sysinfo.c: (init_sysinfo): Removed useless memset.
|
||||
|
||||
2004-07-03 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* 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().
|
||||
|
||||
2004-06-18 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* loadavg.c: (glibtop_get_loadavg_s): Whitespace cleanup.
|
||||
|
||||
* ppp.c: (get_ISDN_stats), (is_ISDN_on): Replace g_malloc by an
|
||||
array.
|
||||
|
||||
* glibtop_server.c: (get_pageshift):
|
||||
* glibtop_server.h:
|
||||
* procmem.c: (glibtop_init_proc_mem_s), (glibtop_get_proc_mem_s):
|
||||
* procsegment.c: (glibtop_init_proc_segment_s),
|
||||
(glibtop_get_proc_segment_s): Moved the pageshift calculation to
|
||||
glibtop_server.[ch]
|
||||
|
||||
* procstate.c: (glibtop_get_proc_state_s):
|
||||
* procuid.c: (glibtop_get_proc_uid_s):
|
||||
* sysinfo.c: (init_sysinfo): Minor cleanups.
|
||||
|
||||
2004-06-18 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* netload.c: (glibtop_get_netload_s): Implemented new IPv6 feature.
|
||||
|
||||
2004-06-13 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* procargs.c: (glibtop_get_proc_args_s): Replaced by g_file_get_contents.
|
||||
|
||||
2004-06-13 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* glibtop_server.h:
|
||||
* glibtop_server.c: (get_scaled): Cleaned.
|
||||
(proc_file_to_buffer): Uninlined.
|
||||
|
||||
* sysinfo.c: (init_sysinfo): Re-implemented.
|
||||
Fixed segfault on SMP.
|
||||
Stores keys in cpuinfo->labels.
|
||||
|
||||
2004-06-12 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* Makefile.am:
|
||||
* glibtop_server.c: Added to repository.
|
||||
|
||||
* glibtop_server.h: (get_scaled): Uninlined and moved it to glibtop_server.c.
|
||||
(skip_token) : Fixed indentation.
|
||||
|
||||
* procmap.c: (glibtop_get_proc_map_s): Big cleanup. Better allocation
|
||||
algorithm.
|
||||
|
||||
* procmem.c:
|
||||
* procsegment.c: Added missing initializations.
|
||||
|
||||
* sem_limits.c:
|
||||
* shm_limits.c: (glibtop_get_shm_limits_s):
|
||||
* swap.c:
|
||||
* uptime.c: Added missing const qualifiers.
|
||||
|
||||
* sysinfo.c: (init_sysinfo): Added missing 0 initialization.
|
||||
Saved 1 gboolean :D.
|
||||
|
||||
2004-06-08 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* procuid.c: (glibtop_get_proc_uid_s): Whitespace clean up.
|
||||
|
||||
2004-06-08 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* glibtop_server.h: Small clean up.
|
||||
|
||||
2004-06-07 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* glibtop_machine.h (skip_token): Removed.
|
||||
* glibtop_server.h (skip_multiple_token): Cleaned.
|
||||
* netload.c: (glibtop_get_netload_s): Replaced unsafe strcpy by g_strlcpy.
|
||||
* procmap.c: (glibtop_get_proc_map_s): s/strncpy/g_strlcpy/.
|
||||
* procstate.c: (glibtop_get_proc_state_s): Likewise.
|
||||
* sysinfo.c: (init_sysinfo): Cleaned.
|
||||
|
||||
2004-05-26 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* cpu.c: (glibtop_get_cpu_s): Cleaned whitespaces.
|
||||
|
||||
* open.c: (get_linux_version), (glibtop_open_s): Removed get_linux_version()
|
||||
Cleaned. Remove static struct utsname.
|
||||
|
||||
2004-05-26 Benoît Dejean <tazforever@dlfp.org>
|
||||
|
||||
* glibtop_server.h:
|
||||
* open.c:
|
||||
* procuid.c: Moved LINUX_VERSION macro to glibtop_server.h.
|
||||
|
||||
* Changelog: Converted to UTF-8.
|
||||
|
||||
2004-05-19 Benoît Dejean <TazForEver@dlfp.org>
|
||||
|
||||
* glibtop_server.h (skip_line): Added test for end of string.
|
||||
(get_scaled): Cleaned.
|
||||
|
||||
* cpu.c (glibtop_get_cpu_s):
|
||||
* open.c (glibtop_open_s): Fixed SMP detection. Closes #142597.
|
||||
|
||||
* uptime.c (glibtop_get_uptime_s): Added boot_time.
|
||||
|
||||
2004-03-09 Bastien Nocera <hadess@hadess.net>
|
||||
|
||||
* cpu.c: (glibtop_get_cpu_s): fixup CPU usage calculation on 2.6
|
||||
kernels (patch by Benoît Dejean <bnet@ifrance.com>) (Closes: #134252)
|
||||
|
||||
2004-03-04 Bastien Nocera <hadess@hadess.net>
|
||||
|
||||
* ppp.c: use a config.h define instead of copying the values in
|
||||
the file (Closes: #126504)
|
||||
|
||||
2004-02-02 Sebastien Bacher <seb128@debian.org>
|
||||
|
||||
* sysdeps/linux/mem.c: (glibtop_get_mem_s): patch from
|
||||
Benoît Dejean <bnet@ifrance.com> to fix libtop_mem.used
|
||||
and glibtop_mem.shared values (Closes: #129863).
|
||||
|
||||
2003-12-23 Bastien Nocera <hadess@hadess.net>
|
||||
|
||||
* cpu.c: (glibtop_get_cpu_s):
|
||||
* glibtop_server.h:
|
||||
* loadavg.c: (glibtop_get_loadavg_s):
|
||||
* mem.c: (glibtop_get_mem_s):
|
||||
* netload.c: (glibtop_get_netload_s):
|
||||
* prockernel.c: (glibtop_get_proc_kernel_s):
|
||||
* procmem.c: (glibtop_get_proc_mem_s):
|
||||
* procsegment.c: (glibtop_get_proc_segment_s):
|
||||
* procsignal.c: (glibtop_get_proc_signal_s):
|
||||
* proctime.c: (glibtop_get_proc_time_s):
|
||||
* procuid.c: (glibtop_get_proc_uid_s):
|
||||
* swap.c: (glibtop_get_swap_s): Apply patch from Benoît Dejean
|
||||
<bnet@ifrance.com> to fix overflow issues using strtol
|
||||
(Closes: #129881)
|
||||
|
||||
2003-12-23 Bastien Nocera <hadess@hadess.net>
|
||||
|
||||
* mem.c: (glibtop_get_mem_s): Fix calculation of used memory,
|
||||
patch by Benoît Dejean, <bnet@ifrance.com> (Closes: #129863)
|
||||
|
||||
2003-12-07 Jon K Hellan <hellan@acm.org>
|
||||
|
||||
* ppp.c: Copy needed defines from linux/isdn.h instead of
|
||||
including it, unbreaking build with linux 2.6 kernel headers.
|
||||
|
||||
2003-10-21 Bastien Nocera <hadess@hadess.net>
|
||||
|
||||
* Makefile.am: install only one library, libgtop-2.0
|
||||
Fix build-time warnings due to the redefinition of guint64
|
||||
|
||||
2003-10-20 Bastien Nocera <hadess@hadess.net>
|
||||
|
||||
* glibtop_server.h:
|
||||
* mem.c: (glibtop_get_mem_s):
|
||||
* swap.c: (glibtop_get_swap_s): committing patch from Sebastien
|
||||
Bacher <seb128@debian.org> for Linux 2.6 support (Closes: #104747)
|
||||
|
||||
2003-10-20 Bastien Nocera <hadess@hadess.net>
|
||||
|
||||
* cpu.c: (glibtop_get_cpu_s):
|
||||
* procmap.c: (glibtop_get_proc_map_s): s/u_int64_t/guint64/
|
||||
|
||||
2003-10-20 Bastien Nocera <hadess@hadess.net>
|
||||
|
||||
* glibtop_machine.h:
|
||||
* glibtop_server.h:
|
||||
* ppp.c:
|
||||
* procargs.c: (glibtop_get_proc_args_s):
|
||||
* proclist.c:
|
||||
* procmap.c: fixed compilation
|
||||
|
||||
2003-10-20 Bastien Nocera <hadess@hadess.net>
|
||||
|
||||
* ppp.c: (get_ISDN_stats):
|
||||
* procargs.c: (glibtop_get_proc_args_s):
|
||||
* proclist.c: (glibtop_get_proclist_s):
|
||||
* procmap.c: (glibtop_get_proc_map_s):
|
||||
replace all the xmalloc crap by glib memory management functions
|
||||
|
||||
2001-10-17 Abel Cheung <maddog@linux.org.hk>
|
||||
|
||||
* Makefile.am: move header to $(includedir)/libgtop-1.0/glibtop.
|
||||
|
||||
2001-02-13 Martin Baulig <baulig@suse.de>
|
||||
|
||||
Fix bug #14076.
|
||||
|
||||
* open.c (glibtop_open_s): Check whether /proc/1/cpu exists to
|
||||
detect SMP support rather than reading /proc/stat; on Linux 2.4.x,
|
||||
/proc/stat has "cpu" and "cpu0" entries even for non-SMP systems.
|
||||
|
||||
2000-01-22 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procargs.c (glibtop_get_proc_args_s): Set correct `buf->size' and
|
||||
`buf->flags' fields when `max_length' was given. Fixes #5183.
|
||||
|
||||
1999-11-28 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procstate.c (glibtop_get_procstate_s): Stat "/proc/<pid>" instead
|
||||
of "/proc/<pid>/state" to get `uid' and `gid'. Thanks to Jason Becker
|
||||
for pointing out that GTop reported wrong uid's.
|
||||
|
||||
1999-10-19 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* uptime.c (glibtop_get_uptime_s): Don't cast uptime and idletime
|
||||
to float as suggested by John Kodis.
|
||||
|
||||
1999-07-29 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* proctime.c (glibtop_get_proctime_s): Don't provide `rtime'
|
||||
any longer since we must not use `rtime = utime + stime'.
|
||||
|
||||
1999-02-20 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netload.c: Don't include <linux/ip_fw.h> for libc5 systems
|
||||
since it is no longer required and makes trouble on Slakware.
|
||||
|
||||
1999-01-06 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netload.c (glibtop_get_netload_s): Use `server->os_version_code'
|
||||
instead of GLIBTOP_LINUX_VERSION_CODE.
|
||||
|
||||
1999-01-06 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
Unconditionally enable SMP support for linux.
|
||||
|
||||
* open.c (_glibtop_open_s): Always determine the number of CPUs
|
||||
we have here, not only when SMP support was enabled.
|
||||
|
||||
* cpu.c, proctime.c: Use `server->ncpu' to determine whether to
|
||||
enable SMP support.
|
||||
|
||||
1998-12-28 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netload.c: When using glibc, don't include <netinet/ip_fw.h>
|
||||
any longer but all headers that were included there; we only
|
||||
needed this file to get those headers.
|
||||
|
||||
1998-12-09 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procargs.c (glibtop_get_proc_args_s): Added implementation
|
||||
for this function.
|
||||
|
||||
1998-12-03 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netload.c: No longer include <linux/version.h>, but use
|
||||
GLIBTOP_LINUX_VERSION_CODE which is set by configure instead.
|
||||
Define _GLIBTOP_IP_FW_ACCTIN and _GLIBTOP_IP_FW_ACCTOUT here
|
||||
and use them instead of IP_FW_F_ACCTIN and IP_FW_F_ACCTOUT.
|
||||
|
||||
1998-11-30 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netload.c: Use correct header files both for libc5 and glibc.
|
||||
With Linux >= 2.1.114 we no longer use IP accounting since it
|
||||
already has byte counts in /proc/net/dev.
|
||||
|
||||
1998-11-22 Martin Baulig <baulig@merkur.uni-trier.de>
|
||||
|
||||
* netload.c (glibtop_get_netload_s): Added implementation
|
||||
for this function.
|
||||
|
||||
The code here is smart enough to use /proc/net/ip_acct if
|
||||
IP accounting is enabled in the kernel and activated on the
|
||||
requested device and /proc/net/dev if not.
|
||||
|
||||
To get separate statistics for received and transmitted
|
||||
packets you need to use two accounting rules:
|
||||
|
||||
ipfwadm -A in -a -P all -W eth0
|
||||
ipfwadm -A out -a -P all -W eth0
|
||||
|
||||
But before you activate IP accounting, please have a look
|
||||
at /proc/net/dev - if if already contains byte counters,
|
||||
then don't use IP accounting.
|
||||
|
||||
1998-10-28 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* ppp.c: Added code for ISDN here.
|
||||
|
||||
1998-10-26 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* netload.c: New file. Currently empty.
|
||||
|
||||
1998-10-26 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procargs.c: New file. Currently empty.
|
||||
|
||||
1998-10-25 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* ppp.c: New file. Currently empty.
|
||||
|
||||
1998-10-11 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* procdata.c: Removed this obsolete file.
|
||||
|
||||
1998-10-02 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* proclist.c (glibtop_init_proclist_s): You can now also use the
|
||||
`GLIBTOP_EXCLUDE_*' flags for the `which' parameter.
|
||||
|
||||
1998-10-01 Martin Baulig <baulig@Stud.Informatik.uni-trier.de>
|
||||
|
||||
* proclist.c (glibtop_init_proclist_s): Honor the `which' parameter
|
||||
to select which processes to fetch.
|
||||
|
||||
1998-09-12 Martin Baulig <martin@home-of-linux.org>
|
||||
|
||||
* sysinfo.c: New file.
|
||||
|
||||
1998-09-09 Martin Baulig <baulig@Stud.Informatik.uni-trier.de>
|
||||
|
||||
* proctime.c (glibtop_get_proc_time_s): Added SMP support.
|
||||
|
||||
* open.c (glibtop_init_s): Initialize `ncpu' on SMP systems.
|
||||
|
||||
* cpu.c (glibtop_get_cpu_s): Added SMP support.
|
||||
|
||||
* ChangeLog: New file.
|
||||
|
||||
23
sysdeps/linux/Makefile.am
Normal file
23
sysdeps/linux/Makefile.am
Normal file
@@ -0,0 +1,23 @@
|
||||
AM_CPPFLAGS = @AM_CPPFLAGS@
|
||||
|
||||
noinst_LTLIBRARIES = libgtop_sysdeps-2.0.la
|
||||
|
||||
EXTRA_DIST = procmap_smaps.gperf procmap_smaps.c
|
||||
|
||||
libgtop_sysdeps_2_0_la_SOURCES = open.c close.c cpu.c mem.c swap.c \
|
||||
uptime.c loadavg.c shm_limits.c msg_limits.c \
|
||||
sem_limits.c proclist.c procstate.c procuid.c \
|
||||
proctime.c procmem.c procsignal.c prockernel.c \
|
||||
procsegment.c procargs.c procmap.c siglist.c \
|
||||
sysinfo.c netload.c ppp.c glibtop_private.c \
|
||||
mountlist.c procaffinity.c procio.c \
|
||||
fsusage.c netlist.c procopenfiles.c procwd.c
|
||||
|
||||
libgtop_sysdeps_2_0_la_LIBADD = @GLIB_LIBS@
|
||||
|
||||
# libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
|
||||
libgtopinclude_HEADERS = glibtop_server.h glibtop_machine.h
|
||||
libgtopincludedir = $(includedir)/libgtop-2.0
|
||||
|
||||
noinst_HEADERS = glibtop_private.h
|
||||
769
sysdeps/linux/Makefile.in
Normal file
769
sysdeps/linux/Makefile.in
Normal file
@@ -0,0 +1,769 @@
|
||||
# Makefile.in generated by automake 1.15 from Makefile.am.
|
||||
# @configure_input@
|
||||
|
||||
# Copyright (C) 1994-2014 Free Software Foundation, Inc.
|
||||
|
||||
# This Makefile.in is free software; the Free Software Foundation
|
||||
# gives unlimited permission to copy and/or distribute it,
|
||||
# with or without modifications, as long as this notice is preserved.
|
||||
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
|
||||
# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
# PARTICULAR PURPOSE.
|
||||
|
||||
@SET_MAKE@
|
||||
|
||||
|
||||
VPATH = @srcdir@
|
||||
am__is_gnu_make = { \
|
||||
if test -z '$(MAKELEVEL)'; then \
|
||||
false; \
|
||||
elif test -n '$(MAKE_HOST)'; then \
|
||||
true; \
|
||||
elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \
|
||||
true; \
|
||||
else \
|
||||
false; \
|
||||
fi; \
|
||||
}
|
||||
am__make_running_with_option = \
|
||||
case $${target_option-} in \
|
||||
?) ;; \
|
||||
*) echo "am__make_running_with_option: internal error: invalid" \
|
||||
"target option '$${target_option-}' specified" >&2; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
has_opt=no; \
|
||||
sane_makeflags=$$MAKEFLAGS; \
|
||||
if $(am__is_gnu_make); then \
|
||||
sane_makeflags=$$MFLAGS; \
|
||||
else \
|
||||
case $$MAKEFLAGS in \
|
||||
*\\[\ \ ]*) \
|
||||
bs=\\; \
|
||||
sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
|
||||
| sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \
|
||||
esac; \
|
||||
fi; \
|
||||
skip_next=no; \
|
||||
strip_trailopt () \
|
||||
{ \
|
||||
flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
|
||||
}; \
|
||||
for flg in $$sane_makeflags; do \
|
||||
test $$skip_next = yes && { skip_next=no; continue; }; \
|
||||
case $$flg in \
|
||||
*=*|--*) continue;; \
|
||||
-*I) strip_trailopt 'I'; skip_next=yes;; \
|
||||
-*I?*) strip_trailopt 'I';; \
|
||||
-*O) strip_trailopt 'O'; skip_next=yes;; \
|
||||
-*O?*) strip_trailopt 'O';; \
|
||||
-*l) strip_trailopt 'l'; skip_next=yes;; \
|
||||
-*l?*) strip_trailopt 'l';; \
|
||||
-[dEDm]) skip_next=yes;; \
|
||||
-[JT]) skip_next=yes;; \
|
||||
esac; \
|
||||
case $$flg in \
|
||||
*$$target_option*) has_opt=yes; break;; \
|
||||
esac; \
|
||||
done; \
|
||||
test $$has_opt = yes
|
||||
am__make_dryrun = (target_option=n; $(am__make_running_with_option))
|
||||
am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
|
||||
pkgdatadir = $(datadir)/@PACKAGE@
|
||||
pkgincludedir = $(includedir)/@PACKAGE@
|
||||
pkglibdir = $(libdir)/@PACKAGE@
|
||||
pkglibexecdir = $(libexecdir)/@PACKAGE@
|
||||
am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
|
||||
install_sh_DATA = $(install_sh) -c -m 644
|
||||
install_sh_PROGRAM = $(install_sh) -c
|
||||
install_sh_SCRIPT = $(install_sh) -c
|
||||
INSTALL_HEADER = $(INSTALL_DATA)
|
||||
transform = $(program_transform_name)
|
||||
NORMAL_INSTALL = :
|
||||
PRE_INSTALL = :
|
||||
POST_INSTALL = :
|
||||
NORMAL_UNINSTALL = :
|
||||
PRE_UNINSTALL = :
|
||||
POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
subdir = sysdeps/linux
|
||||
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
|
||||
am__aclocal_m4_deps = $(top_srcdir)/m4/gettext.m4 \
|
||||
$(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/iconv.m4 \
|
||||
$(top_srcdir)/m4/intlmacosx.m4 \
|
||||
$(top_srcdir)/m4/introspection.m4 $(top_srcdir)/m4/lib-ld.m4 \
|
||||
$(top_srcdir)/m4/lib-link.m4 $(top_srcdir)/m4/lib-prefix.m4 \
|
||||
$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
|
||||
$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
|
||||
$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/nls.m4 \
|
||||
$(top_srcdir)/m4/po.m4 $(top_srcdir)/m4/progtest.m4 \
|
||||
$(top_srcdir)/acinclude.m4 $(top_srcdir)/libgtop-sysdeps.m4 \
|
||||
$(top_srcdir)/configure.ac
|
||||
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
|
||||
$(ACLOCAL_M4)
|
||||
DIST_COMMON = $(srcdir)/Makefile.am $(libgtopinclude_HEADERS) \
|
||||
$(noinst_HEADERS) $(am__DIST_COMMON)
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_HEADER = $(top_builddir)/config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
CONFIG_CLEAN_VPATH_FILES =
|
||||
LTLIBRARIES = $(noinst_LTLIBRARIES)
|
||||
libgtop_sysdeps_2_0_la_DEPENDENCIES =
|
||||
am_libgtop_sysdeps_2_0_la_OBJECTS = open.lo close.lo cpu.lo mem.lo \
|
||||
swap.lo uptime.lo loadavg.lo shm_limits.lo msg_limits.lo \
|
||||
sem_limits.lo proclist.lo procstate.lo procuid.lo proctime.lo \
|
||||
procmem.lo procsignal.lo prockernel.lo procsegment.lo \
|
||||
procargs.lo procmap.lo siglist.lo sysinfo.lo netload.lo ppp.lo \
|
||||
glibtop_private.lo mountlist.lo procaffinity.lo procio.lo \
|
||||
fsusage.lo netlist.lo procopenfiles.lo procwd.lo
|
||||
libgtop_sysdeps_2_0_la_OBJECTS = $(am_libgtop_sysdeps_2_0_la_OBJECTS)
|
||||
AM_V_lt = $(am__v_lt_@AM_V@)
|
||||
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
|
||||
am__v_lt_0 = --silent
|
||||
am__v_lt_1 =
|
||||
AM_V_P = $(am__v_P_@AM_V@)
|
||||
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
|
||||
am__v_P_0 = false
|
||||
am__v_P_1 = :
|
||||
AM_V_GEN = $(am__v_GEN_@AM_V@)
|
||||
am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@)
|
||||
am__v_GEN_0 = @echo " GEN " $@;
|
||||
am__v_GEN_1 =
|
||||
AM_V_at = $(am__v_at_@AM_V@)
|
||||
am__v_at_ = $(am__v_at_@AM_DEFAULT_V@)
|
||||
am__v_at_0 = @
|
||||
am__v_at_1 =
|
||||
DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
|
||||
depcomp = $(SHELL) $(top_srcdir)/depcomp
|
||||
am__depfiles_maybe = depfiles
|
||||
am__mv = mv -f
|
||||
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
|
||||
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \
|
||||
$(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
|
||||
$(AM_CFLAGS) $(CFLAGS)
|
||||
AM_V_CC = $(am__v_CC_@AM_V@)
|
||||
am__v_CC_ = $(am__v_CC_@AM_DEFAULT_V@)
|
||||
am__v_CC_0 = @echo " CC " $@;
|
||||
am__v_CC_1 =
|
||||
CCLD = $(CC)
|
||||
LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
$(AM_LDFLAGS) $(LDFLAGS) -o $@
|
||||
AM_V_CCLD = $(am__v_CCLD_@AM_V@)
|
||||
am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@)
|
||||
am__v_CCLD_0 = @echo " CCLD " $@;
|
||||
am__v_CCLD_1 =
|
||||
SOURCES = $(libgtop_sysdeps_2_0_la_SOURCES)
|
||||
DIST_SOURCES = $(libgtop_sysdeps_2_0_la_SOURCES)
|
||||
am__can_run_installinfo = \
|
||||
case $$AM_UPDATE_INFO_DIR in \
|
||||
n|no|NO) false;; \
|
||||
*) (install-info --version) >/dev/null 2>&1;; \
|
||||
esac
|
||||
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
|
||||
am__vpath_adj = case $$p in \
|
||||
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
|
||||
*) f=$$p;; \
|
||||
esac;
|
||||
am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`;
|
||||
am__install_max = 40
|
||||
am__nobase_strip_setup = \
|
||||
srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'`
|
||||
am__nobase_strip = \
|
||||
for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||"
|
||||
am__nobase_list = $(am__nobase_strip_setup); \
|
||||
for p in $$list; do echo "$$p $$p"; done | \
|
||||
sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \
|
||||
$(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \
|
||||
if (++n[$$2] == $(am__install_max)) \
|
||||
{ print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \
|
||||
END { for (dir in files) print dir, files[dir] }'
|
||||
am__base_list = \
|
||||
sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \
|
||||
sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g'
|
||||
am__uninstall_files_from_dir = { \
|
||||
test -z "$$files" \
|
||||
|| { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \
|
||||
|| { echo " ( cd '$$dir' && rm -f" $$files ")"; \
|
||||
$(am__cd) "$$dir" && rm -f $$files; }; \
|
||||
}
|
||||
am__installdirs = "$(DESTDIR)$(libgtopincludedir)"
|
||||
HEADERS = $(libgtopinclude_HEADERS) $(noinst_HEADERS)
|
||||
am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)
|
||||
# Read a list of newline-separated strings from the standard input,
|
||||
# and print each of them once, without duplicates. Input order is
|
||||
# *not* preserved.
|
||||
am__uniquify_input = $(AWK) '\
|
||||
BEGIN { nonempty = 0; } \
|
||||
{ items[$$0] = 1; nonempty = 1; } \
|
||||
END { if (nonempty) { for (i in items) print i; }; } \
|
||||
'
|
||||
# Make sure the list of sources is unique. This is necessary because,
|
||||
# e.g., the same source file might be shared among _SOURCES variables
|
||||
# for different programs/libraries.
|
||||
am__define_uniq_tagged_files = \
|
||||
list='$(am__tagged_files)'; \
|
||||
unique=`for i in $$list; do \
|
||||
if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
|
||||
done | $(am__uniquify_input)`
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp \
|
||||
ChangeLog
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
ACLOCAL = @ACLOCAL@
|
||||
ACLOCAL_AMFLAGS = @ACLOCAL_AMFLAGS@
|
||||
ALLOCA = @ALLOCA@
|
||||
AMTAR = @AMTAR@
|
||||
AM_CPPFLAGS = @AM_CPPFLAGS@
|
||||
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
|
||||
AR = @AR@
|
||||
AS = @AS@
|
||||
AUTOCONF = @AUTOCONF@
|
||||
AUTOHEADER = @AUTOHEADER@
|
||||
AUTOMAKE = @AUTOMAKE@
|
||||
AWK = @AWK@
|
||||
CC = @CC@
|
||||
CCDEPMODE = @CCDEPMODE@
|
||||
CFLAGS = @CFLAGS@
|
||||
CPP = @CPP@
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CYGPATH_W = @CYGPATH_W@
|
||||
DEFS = @DEFS@
|
||||
DEPDIR = @DEPDIR@
|
||||
DLLTOOL = @DLLTOOL@
|
||||
DL_LIB = @DL_LIB@
|
||||
DSYMUTIL = @DSYMUTIL@
|
||||
DUMPBIN = @DUMPBIN@
|
||||
ECHO_C = @ECHO_C@
|
||||
ECHO_N = @ECHO_N@
|
||||
ECHO_T = @ECHO_T@
|
||||
EGREP = @EGREP@
|
||||
EXEEXT = @EXEEXT@
|
||||
FGREP = @FGREP@
|
||||
GETTEXT_MACRO_VERSION = @GETTEXT_MACRO_VERSION@
|
||||
GETTEXT_PACKAGE = @GETTEXT_PACKAGE@
|
||||
GLIB_CFLAGS = @GLIB_CFLAGS@
|
||||
GLIB_LIBS = @GLIB_LIBS@
|
||||
GMSGFMT = @GMSGFMT@
|
||||
GMSGFMT_015 = @GMSGFMT_015@
|
||||
GREP = @GREP@
|
||||
GTKDOC_CHECK = @GTKDOC_CHECK@
|
||||
GTKDOC_CHECK_PATH = @GTKDOC_CHECK_PATH@
|
||||
GTKDOC_DEPS_CFLAGS = @GTKDOC_DEPS_CFLAGS@
|
||||
GTKDOC_DEPS_LIBS = @GTKDOC_DEPS_LIBS@
|
||||
GTKDOC_MKPDF = @GTKDOC_MKPDF@
|
||||
GTKDOC_REBASE = @GTKDOC_REBASE@
|
||||
HTML_DIR = @HTML_DIR@
|
||||
INSTALL = @INSTALL@
|
||||
INSTALL_DATA = @INSTALL_DATA@
|
||||
INSTALL_PROGRAM = @INSTALL_PROGRAM@
|
||||
INSTALL_SCRIPT = @INSTALL_SCRIPT@
|
||||
INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
|
||||
INTLLIBS = @INTLLIBS@
|
||||
INTL_MACOSX_LIBS = @INTL_MACOSX_LIBS@
|
||||
INTROSPECTION_CFLAGS = @INTROSPECTION_CFLAGS@
|
||||
INTROSPECTION_COMPILER = @INTROSPECTION_COMPILER@
|
||||
INTROSPECTION_GENERATE = @INTROSPECTION_GENERATE@
|
||||
INTROSPECTION_GIRDIR = @INTROSPECTION_GIRDIR@
|
||||
INTROSPECTION_LIBS = @INTROSPECTION_LIBS@
|
||||
INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@
|
||||
INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@
|
||||
INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@
|
||||
KVM_LIBS = @KVM_LIBS@
|
||||
LD = @LD@
|
||||
LDFLAGS = @LDFLAGS@
|
||||
LIBGTOP_BINDIR = @LIBGTOP_BINDIR@
|
||||
LIBGTOP_EXTRA_LIBS = @LIBGTOP_EXTRA_LIBS@
|
||||
LIBGTOP_INCS = @LIBGTOP_INCS@
|
||||
LIBGTOP_LIBS = @LIBGTOP_LIBS@
|
||||
LIBGTOP_MAJOR_VERSION = @LIBGTOP_MAJOR_VERSION@
|
||||
LIBGTOP_MICRO_VERSION = @LIBGTOP_MICRO_VERSION@
|
||||
LIBGTOP_MINOR_VERSION = @LIBGTOP_MINOR_VERSION@
|
||||
LIBGTOP_SERVER = @LIBGTOP_SERVER@
|
||||
LIBGTOP_SERVER_VERSION = @LIBGTOP_SERVER_VERSION@
|
||||
LIBGTOP_VERSION = @LIBGTOP_VERSION@
|
||||
LIBGTOP_VERSION_CODE = @LIBGTOP_VERSION_CODE@
|
||||
LIBICONV = @LIBICONV@
|
||||
LIBINTL = @LIBINTL@
|
||||
LIBOBJS = @LIBOBJS@
|
||||
LIBS = @LIBS@
|
||||
LIBTOOL = @LIBTOOL@
|
||||
LIPO = @LIPO@
|
||||
LN_S = @LN_S@
|
||||
LTLIBICONV = @LTLIBICONV@
|
||||
LTLIBINTL = @LTLIBINTL@
|
||||
LTLIBOBJS = @LTLIBOBJS@
|
||||
LT_SYS_LIBRARY_PATH = @LT_SYS_LIBRARY_PATH@
|
||||
LT_VERSION_INFO = @LT_VERSION_INFO@
|
||||
MAKEINFO = @MAKEINFO@
|
||||
MANIFEST_TOOL = @MANIFEST_TOOL@
|
||||
MKDIR_P = @MKDIR_P@
|
||||
MSGFMT = @MSGFMT@
|
||||
MSGFMT_015 = @MSGFMT_015@
|
||||
MSGMERGE = @MSGMERGE@
|
||||
NM = @NM@
|
||||
NMEDIT = @NMEDIT@
|
||||
OBJDUMP = @OBJDUMP@
|
||||
OBJEXT = @OBJEXT@
|
||||
OTOOL = @OTOOL@
|
||||
OTOOL64 = @OTOOL64@
|
||||
PACKAGE = @PACKAGE@
|
||||
PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
|
||||
PACKAGE_NAME = @PACKAGE_NAME@
|
||||
PACKAGE_STRING = @PACKAGE_STRING@
|
||||
PACKAGE_TARNAME = @PACKAGE_TARNAME@
|
||||
PACKAGE_URL = @PACKAGE_URL@
|
||||
PACKAGE_VERSION = @PACKAGE_VERSION@
|
||||
PATH_SEPARATOR = @PATH_SEPARATOR@
|
||||
PERL = @PERL@
|
||||
PKG_CONFIG = @PKG_CONFIG@
|
||||
PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
|
||||
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
|
||||
POSUB = @POSUB@
|
||||
RANLIB = @RANLIB@
|
||||
SED = @SED@
|
||||
SET_MAKE = @SET_MAKE@
|
||||
SHELL = @SHELL@
|
||||
STRIP = @STRIP@
|
||||
USE_NLS = @USE_NLS@
|
||||
VERSION = @VERSION@
|
||||
XGETTEXT = @XGETTEXT@
|
||||
XGETTEXT_015 = @XGETTEXT_015@
|
||||
XGETTEXT_EXTRA_OPTIONS = @XGETTEXT_EXTRA_OPTIONS@
|
||||
XMKMF = @XMKMF@
|
||||
X_CFLAGS = @X_CFLAGS@
|
||||
X_EXTRA_LIBS = @X_EXTRA_LIBS@
|
||||
X_LIBS = @X_LIBS@
|
||||
X_PRE_LIBS = @X_PRE_LIBS@
|
||||
abs_builddir = @abs_builddir@
|
||||
abs_srcdir = @abs_srcdir@
|
||||
abs_top_builddir = @abs_top_builddir@
|
||||
abs_top_srcdir = @abs_top_srcdir@
|
||||
ac_ct_AR = @ac_ct_AR@
|
||||
ac_ct_CC = @ac_ct_CC@
|
||||
ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
|
||||
am__include = @am__include@
|
||||
am__leading_dot = @am__leading_dot@
|
||||
am__quote = @am__quote@
|
||||
am__tar = @am__tar@
|
||||
am__untar = @am__untar@
|
||||
bindir = @bindir@
|
||||
build = @build@
|
||||
build_alias = @build_alias@
|
||||
build_cpu = @build_cpu@
|
||||
build_os = @build_os@
|
||||
build_vendor = @build_vendor@
|
||||
builddir = @builddir@
|
||||
datadir = @datadir@
|
||||
datarootdir = @datarootdir@
|
||||
docdir = @docdir@
|
||||
dvidir = @dvidir@
|
||||
exec_prefix = @exec_prefix@
|
||||
host = @host@
|
||||
host_alias = @host_alias@
|
||||
host_cpu = @host_cpu@
|
||||
host_os = @host_os@
|
||||
host_vendor = @host_vendor@
|
||||
htmldir = @htmldir@
|
||||
includedir = @includedir@
|
||||
infodir = @infodir@
|
||||
install_sh = @install_sh@
|
||||
libdir = @libdir@
|
||||
libexecdir = @libexecdir@
|
||||
libgtop_have_sysinfo = @libgtop_have_sysinfo@
|
||||
libgtop_need_server = @libgtop_need_server@
|
||||
libgtop_postinstall = @libgtop_postinstall@
|
||||
libgtop_sysdeps_dir = @libgtop_sysdeps_dir@
|
||||
libgtop_top_builddir = @libgtop_top_builddir@
|
||||
libs_xauth = @libs_xauth@
|
||||
localedir = @localedir@
|
||||
localstatedir = @localstatedir@
|
||||
mandir = @mandir@
|
||||
mkdir_p = @mkdir_p@
|
||||
oldincludedir = @oldincludedir@
|
||||
pdfdir = @pdfdir@
|
||||
prefix = @prefix@
|
||||
program_transform_name = @program_transform_name@
|
||||
psdir = @psdir@
|
||||
sbindir = @sbindir@
|
||||
server_programs = @server_programs@
|
||||
sharedstatedir = @sharedstatedir@
|
||||
srcdir = @srcdir@
|
||||
sysconfdir = @sysconfdir@
|
||||
sysdeps_dir = @sysdeps_dir@
|
||||
sysdeps_suid_lib = @sysdeps_suid_lib@
|
||||
target_alias = @target_alias@
|
||||
top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
noinst_LTLIBRARIES = libgtop_sysdeps-2.0.la
|
||||
EXTRA_DIST = procmap_smaps.gperf procmap_smaps.c
|
||||
libgtop_sysdeps_2_0_la_SOURCES = open.c close.c cpu.c mem.c swap.c \
|
||||
uptime.c loadavg.c shm_limits.c msg_limits.c \
|
||||
sem_limits.c proclist.c procstate.c procuid.c \
|
||||
proctime.c procmem.c procsignal.c prockernel.c \
|
||||
procsegment.c procargs.c procmap.c siglist.c \
|
||||
sysinfo.c netload.c ppp.c glibtop_private.c \
|
||||
mountlist.c procaffinity.c procio.c \
|
||||
fsusage.c netlist.c procopenfiles.c procwd.c
|
||||
|
||||
libgtop_sysdeps_2_0_la_LIBADD = @GLIB_LIBS@
|
||||
|
||||
# libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
|
||||
libgtopinclude_HEADERS = glibtop_server.h glibtop_machine.h
|
||||
libgtopincludedir = $(includedir)/libgtop-2.0
|
||||
noinst_HEADERS = glibtop_private.h
|
||||
all: all-am
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .lo .o .obj
|
||||
$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
|
||||
@for dep in $?; do \
|
||||
case '$(am__configure_deps)' in \
|
||||
*$$dep*) \
|
||||
( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
|
||||
&& { if test -f $@; then exit 0; else break; fi; }; \
|
||||
exit 1;; \
|
||||
esac; \
|
||||
done; \
|
||||
echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu sysdeps/linux/Makefile'; \
|
||||
$(am__cd) $(top_srcdir) && \
|
||||
$(AUTOMAKE) --gnu sysdeps/linux/Makefile
|
||||
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
|
||||
@case '$?' in \
|
||||
*config.status*) \
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
|
||||
*) \
|
||||
echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
|
||||
esac;
|
||||
|
||||
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
|
||||
$(top_srcdir)/configure: $(am__configure_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
||||
cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
|
||||
$(am__aclocal_m4_deps):
|
||||
|
||||
clean-noinstLTLIBRARIES:
|
||||
-test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES)
|
||||
@list='$(noinst_LTLIBRARIES)'; \
|
||||
locs=`for p in $$list; do echo $$p; done | \
|
||||
sed 's|^[^/]*$$|.|; s|/[^/]*$$||; s|$$|/so_locations|' | \
|
||||
sort -u`; \
|
||||
test -z "$$locs" || { \
|
||||
echo rm -f $${locs}; \
|
||||
rm -f $${locs}; \
|
||||
}
|
||||
|
||||
libgtop_sysdeps-2.0.la: $(libgtop_sysdeps_2_0_la_OBJECTS) $(libgtop_sysdeps_2_0_la_DEPENDENCIES) $(EXTRA_libgtop_sysdeps_2_0_la_DEPENDENCIES)
|
||||
$(AM_V_CCLD)$(LINK) $(libgtop_sysdeps_2_0_la_OBJECTS) $(libgtop_sysdeps_2_0_la_LIBADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
|
||||
distclean-compile:
|
||||
-rm -f *.tab.c
|
||||
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/close.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cpu.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fsusage.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/glibtop_private.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/loadavg.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mem.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mountlist.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msg_limits.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netlist.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/netload.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/open.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ppp.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procaffinity.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procargs.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procio.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/prockernel.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proclist.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procmap.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procmem.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procopenfiles.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procsegment.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procsignal.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procstate.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proctime.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procuid.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/procwd.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sem_limits.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/shm_limits.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/siglist.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/swap.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sysinfo.Plo@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uptime.Plo@am__quote@
|
||||
|
||||
.c.o:
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ $<
|
||||
|
||||
.c.obj:
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
|
||||
|
||||
.c.lo:
|
||||
@am__fastdepCC_TRUE@ $(AM_V_CC)$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
|
||||
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
|
||||
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
|
||||
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LTCOMPILE) -c -o $@ $<
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
clean-libtool:
|
||||
-rm -rf .libs _libs
|
||||
install-libgtopincludeHEADERS: $(libgtopinclude_HEADERS)
|
||||
@$(NORMAL_INSTALL)
|
||||
@list='$(libgtopinclude_HEADERS)'; test -n "$(libgtopincludedir)" || list=; \
|
||||
if test -n "$$list"; then \
|
||||
echo " $(MKDIR_P) '$(DESTDIR)$(libgtopincludedir)'"; \
|
||||
$(MKDIR_P) "$(DESTDIR)$(libgtopincludedir)" || exit 1; \
|
||||
fi; \
|
||||
for p in $$list; do \
|
||||
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
|
||||
echo "$$d$$p"; \
|
||||
done | $(am__base_list) | \
|
||||
while read files; do \
|
||||
echo " $(INSTALL_HEADER) $$files '$(DESTDIR)$(libgtopincludedir)'"; \
|
||||
$(INSTALL_HEADER) $$files "$(DESTDIR)$(libgtopincludedir)" || exit $$?; \
|
||||
done
|
||||
|
||||
uninstall-libgtopincludeHEADERS:
|
||||
@$(NORMAL_UNINSTALL)
|
||||
@list='$(libgtopinclude_HEADERS)'; test -n "$(libgtopincludedir)" || list=; \
|
||||
files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
|
||||
dir='$(DESTDIR)$(libgtopincludedir)'; $(am__uninstall_files_from_dir)
|
||||
|
||||
ID: $(am__tagged_files)
|
||||
$(am__define_uniq_tagged_files); mkid -fID $$unique
|
||||
tags: tags-am
|
||||
TAGS: tags
|
||||
|
||||
tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
|
||||
set x; \
|
||||
here=`pwd`; \
|
||||
$(am__define_uniq_tagged_files); \
|
||||
shift; \
|
||||
if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
|
||||
test -n "$$unique" || unique=$$empty_fix; \
|
||||
if test $$# -gt 0; then \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
"$$@" $$unique; \
|
||||
else \
|
||||
$(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
|
||||
$$unique; \
|
||||
fi; \
|
||||
fi
|
||||
ctags: ctags-am
|
||||
|
||||
CTAGS: ctags
|
||||
ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files)
|
||||
$(am__define_uniq_tagged_files); \
|
||||
test -z "$(CTAGS_ARGS)$$unique" \
|
||||
|| $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
|
||||
$$unique
|
||||
|
||||
GTAGS:
|
||||
here=`$(am__cd) $(top_builddir) && pwd` \
|
||||
&& $(am__cd) $(top_srcdir) \
|
||||
&& gtags -i $(GTAGS_ARGS) "$$here"
|
||||
cscopelist: cscopelist-am
|
||||
|
||||
cscopelist-am: $(am__tagged_files)
|
||||
list='$(am__tagged_files)'; \
|
||||
case "$(srcdir)" in \
|
||||
[\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \
|
||||
*) sdir=$(subdir)/$(srcdir) ;; \
|
||||
esac; \
|
||||
for i in $$list; do \
|
||||
if test -f "$$i"; then \
|
||||
echo "$(subdir)/$$i"; \
|
||||
else \
|
||||
echo "$$sdir/$$i"; \
|
||||
fi; \
|
||||
done >> $(top_builddir)/cscope.files
|
||||
|
||||
distclean-tags:
|
||||
-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
|
||||
|
||||
distdir: $(DISTFILES)
|
||||
@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
|
||||
list='$(DISTFILES)'; \
|
||||
dist_files=`for file in $$list; do echo $$file; done | \
|
||||
sed -e "s|^$$srcdirstrip/||;t" \
|
||||
-e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
|
||||
case $$dist_files in \
|
||||
*/*) $(MKDIR_P) `echo "$$dist_files" | \
|
||||
sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
|
||||
sort -u` ;; \
|
||||
esac; \
|
||||
for file in $$dist_files; do \
|
||||
if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
|
||||
if test -d $$d/$$file; then \
|
||||
dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
|
||||
if test -d "$(distdir)/$$file"; then \
|
||||
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
|
||||
fi; \
|
||||
if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
|
||||
cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
|
||||
find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
|
||||
fi; \
|
||||
cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
|
||||
else \
|
||||
test -f "$(distdir)/$$file" \
|
||||
|| cp -p $$d/$$file "$(distdir)/$$file" \
|
||||
|| exit 1; \
|
||||
fi; \
|
||||
done
|
||||
check-am: all-am
|
||||
check: check-am
|
||||
all-am: Makefile $(LTLIBRARIES) $(HEADERS)
|
||||
installdirs:
|
||||
for dir in "$(DESTDIR)$(libgtopincludedir)"; do \
|
||||
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
|
||||
done
|
||||
install: install-am
|
||||
install-exec: install-exec-am
|
||||
install-data: install-data-am
|
||||
uninstall: uninstall-am
|
||||
|
||||
install-am: all-am
|
||||
@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
|
||||
|
||||
installcheck: installcheck-am
|
||||
install-strip:
|
||||
if test -z '$(STRIP)'; then \
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
install; \
|
||||
else \
|
||||
$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
|
||||
install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
|
||||
"INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \
|
||||
fi
|
||||
mostlyclean-generic:
|
||||
|
||||
clean-generic:
|
||||
|
||||
distclean-generic:
|
||||
-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
|
||||
-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
|
||||
|
||||
maintainer-clean-generic:
|
||||
@echo "This command is intended for maintainers to use"
|
||||
@echo "it deletes files that may require special tools to rebuild."
|
||||
clean: clean-am
|
||||
|
||||
clean-am: clean-generic clean-libtool clean-noinstLTLIBRARIES \
|
||||
mostlyclean-am
|
||||
|
||||
distclean: distclean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
distclean-am: clean-am distclean-compile distclean-generic \
|
||||
distclean-tags
|
||||
|
||||
dvi: dvi-am
|
||||
|
||||
dvi-am:
|
||||
|
||||
html: html-am
|
||||
|
||||
html-am:
|
||||
|
||||
info: info-am
|
||||
|
||||
info-am:
|
||||
|
||||
install-data-am: install-libgtopincludeHEADERS
|
||||
|
||||
install-dvi: install-dvi-am
|
||||
|
||||
install-dvi-am:
|
||||
|
||||
install-exec-am:
|
||||
|
||||
install-html: install-html-am
|
||||
|
||||
install-html-am:
|
||||
|
||||
install-info: install-info-am
|
||||
|
||||
install-info-am:
|
||||
|
||||
install-man:
|
||||
|
||||
install-pdf: install-pdf-am
|
||||
|
||||
install-pdf-am:
|
||||
|
||||
install-ps: install-ps-am
|
||||
|
||||
install-ps-am:
|
||||
|
||||
installcheck-am:
|
||||
|
||||
maintainer-clean: maintainer-clean-am
|
||||
-rm -rf ./$(DEPDIR)
|
||||
-rm -f Makefile
|
||||
maintainer-clean-am: distclean-am maintainer-clean-generic
|
||||
|
||||
mostlyclean: mostlyclean-am
|
||||
|
||||
mostlyclean-am: mostlyclean-compile mostlyclean-generic \
|
||||
mostlyclean-libtool
|
||||
|
||||
pdf: pdf-am
|
||||
|
||||
pdf-am:
|
||||
|
||||
ps: ps-am
|
||||
|
||||
ps-am:
|
||||
|
||||
uninstall-am: uninstall-libgtopincludeHEADERS
|
||||
|
||||
.MAKE: install-am install-strip
|
||||
|
||||
.PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \
|
||||
clean-libtool clean-noinstLTLIBRARIES cscopelist-am ctags \
|
||||
ctags-am distclean distclean-compile distclean-generic \
|
||||
distclean-libtool distclean-tags distdir dvi dvi-am html \
|
||||
html-am info info-am install install-am install-data \
|
||||
install-data-am install-dvi install-dvi-am install-exec \
|
||||
install-exec-am install-html install-html-am install-info \
|
||||
install-info-am install-libgtopincludeHEADERS install-man \
|
||||
install-pdf install-pdf-am install-ps install-ps-am \
|
||||
install-strip installcheck installcheck-am installdirs \
|
||||
maintainer-clean maintainer-clean-generic mostlyclean \
|
||||
mostlyclean-compile mostlyclean-generic mostlyclean-libtool \
|
||||
pdf pdf-am ps ps-am tags tags-am uninstall uninstall-am \
|
||||
uninstall-libgtopincludeHEADERS
|
||||
|
||||
.PRECIOUS: Makefile
|
||||
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
29
sysdeps/linux/close.c
Normal file
29
sysdeps/linux/close.c
Normal file
@@ -0,0 +1,29 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/close.h>
|
||||
|
||||
/* Closes pipe to gtop server. */
|
||||
|
||||
void
|
||||
glibtop_close_s (glibtop *server)
|
||||
{ }
|
||||
151
sysdeps/linux/cpu.c
Normal file
151
sysdeps/linux/cpu.c
Normal file
@@ -0,0 +1,151 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/cpu.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_cpu =
|
||||
(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_USER) +
|
||||
(1L << GLIBTOP_CPU_NICE) + (1L << GLIBTOP_CPU_SYS) +
|
||||
(1L << GLIBTOP_CPU_IDLE) + (1L << GLIBTOP_CPU_FREQUENCY);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_cpu_smp =
|
||||
(1L << GLIBTOP_XCPU_TOTAL) + (1L << GLIBTOP_XCPU_USER) +
|
||||
(1L << GLIBTOP_XCPU_NICE) + (1L << GLIBTOP_XCPU_SYS) +
|
||||
(1L << GLIBTOP_XCPU_IDLE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_cpu_2_6 =
|
||||
(1L << GLIBTOP_CPU_IOWAIT) + (1L << GLIBTOP_CPU_IRQ) +
|
||||
(1L << GLIBTOP_CPU_SOFTIRQ);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_cpu_smp_2_6 =
|
||||
(1L << GLIBTOP_XCPU_IOWAIT) + (1L << GLIBTOP_XCPU_IRQ) +
|
||||
(1L << GLIBTOP_XCPU_SOFTIRQ);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_cpu_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
|
||||
|
||||
if (server->ncpu)
|
||||
server->sysdeps.cpu |= _glibtop_sysdeps_cpu_smp;
|
||||
|
||||
|
||||
if(server->os_version_code >= LINUX_VERSION_CODE(2, 6, 0))
|
||||
{
|
||||
server->sysdeps.cpu |= _glibtop_sysdeps_cpu_2_6;
|
||||
|
||||
if (server->ncpu)
|
||||
server->sysdeps.cpu |= _glibtop_sysdeps_cpu_smp_2_6;
|
||||
}
|
||||
}
|
||||
|
||||
/* Provides information about cpu usage. */
|
||||
|
||||
#define FILENAME "/proc/stat"
|
||||
#define STAT_BUFSIZ 81920
|
||||
|
||||
void
|
||||
glibtop_get_cpu_s (glibtop *server, glibtop_cpu *buf)
|
||||
{
|
||||
char buffer [STAT_BUFSIZ], *p;
|
||||
int i;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_cpu));
|
||||
|
||||
file_to_buffer(server, buffer, sizeof buffer, FILENAME);
|
||||
|
||||
/*
|
||||
* GLOBAL
|
||||
*/
|
||||
|
||||
p = skip_token (buffer); /* "cpu" */
|
||||
|
||||
buf->user = strtoull (p, &p, 0);
|
||||
buf->nice = strtoull (p, &p, 0);
|
||||
buf->sys = strtoull (p, &p, 0);
|
||||
buf->idle = strtoull (p, &p, 0);
|
||||
buf->total = buf->user + buf->nice + buf->sys + buf->idle;
|
||||
|
||||
/* 2.6 kernel */
|
||||
if(server->os_version_code >= LINUX_VERSION_CODE(2, 6, 0))
|
||||
{
|
||||
buf->iowait = strtoull(p, &p, 0);
|
||||
buf->irq = strtoull(p, &p, 0);
|
||||
buf->softirq = strtoull(p, &p, 0);
|
||||
|
||||
buf->total += buf->iowait + buf->irq + buf->softirq;
|
||||
}
|
||||
|
||||
buf->frequency = 100;
|
||||
buf->flags = _glibtop_sysdeps_cpu;
|
||||
|
||||
/*
|
||||
* PER CPU
|
||||
*/
|
||||
|
||||
for (i = 0; i <= server->ncpu; i++) {
|
||||
|
||||
p = skip_line(p); /* move to ^ */
|
||||
|
||||
if (!check_cpu_line_warn(server, p, i))
|
||||
break;
|
||||
|
||||
p = skip_token(p); /* "cpuN" */
|
||||
|
||||
buf->xcpu_user [i] = strtoull (p, &p, 0);
|
||||
buf->xcpu_nice [i] = strtoull (p, &p, 0);
|
||||
buf->xcpu_sys [i] = strtoull (p, &p, 0);
|
||||
buf->xcpu_idle [i] = strtoull (p, &p, 0);
|
||||
buf->xcpu_total[i] = buf->xcpu_user [i] \
|
||||
+ buf->xcpu_nice [i] \
|
||||
+ buf->xcpu_sys [i] \
|
||||
+ buf->xcpu_idle [i];
|
||||
|
||||
/* 2.6 kernel */
|
||||
if(server->os_version_code >= LINUX_VERSION_CODE(2, 6, 0))
|
||||
{
|
||||
buf->xcpu_iowait [i] = strtoull(p, &p, 0);
|
||||
buf->xcpu_irq [i] = strtoull(p, &p, 0);
|
||||
buf->xcpu_softirq [i] = strtoull(p, &p, 0);
|
||||
|
||||
buf->xcpu_total [i] += buf->xcpu_iowait [i] \
|
||||
+ buf->xcpu_irq [i] \
|
||||
+ buf->xcpu_softirq [i];
|
||||
}
|
||||
}
|
||||
|
||||
if(server->ncpu) /* ok, that's a real SMP */
|
||||
buf->flags |= _glibtop_sysdeps_cpu_smp;
|
||||
|
||||
if(server->os_version_code >= LINUX_VERSION_CODE(2, 6, 0))
|
||||
{
|
||||
buf->flags |= _glibtop_sysdeps_cpu_2_6;
|
||||
|
||||
if(server->ncpu) /* ok, that's a real SMP */
|
||||
buf->flags |= _glibtop_sysdeps_cpu_smp_2_6;
|
||||
}
|
||||
}
|
||||
214
sysdeps/linux/fsusage.c
Normal file
214
sysdeps/linux/fsusage.c
Normal file
@@ -0,0 +1,214 @@
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/fsusage.h>
|
||||
#include <glibtop/error.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <linux/kdev_t.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <mntent.h>
|
||||
|
||||
|
||||
/*
|
||||
* Linux 2.6.x
|
||||
* linux/Documentation/iostats.txt
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
static gboolean
|
||||
get_device(glibtop* server, const char *mountpoint,
|
||||
char* device, size_t device_size)
|
||||
{
|
||||
const struct mntent *mnt;
|
||||
FILE *fp;
|
||||
gboolean found = FALSE;
|
||||
|
||||
if (!(fp = setmntent(MOUNTED, "r"))) {
|
||||
glibtop_warn_io_r(server, "Could not open %s", MOUNTED);
|
||||
goto out;
|
||||
}
|
||||
|
||||
while ((mnt = getmntent(fp)))
|
||||
{
|
||||
/* There can be multiple root mount entries, skip the unuseful one */
|
||||
if (!strcmp(mnt->mnt_fsname, "rootfs"))
|
||||
continue;
|
||||
|
||||
if (!strcmp(mountpoint, mnt->mnt_dir)) {
|
||||
if (!strncmp(mnt->mnt_fsname, "/dev/", 5)) {
|
||||
g_strlcpy(device, mnt->mnt_fsname + 5, device_size);
|
||||
found = TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
endmntent(fp);
|
||||
out:
|
||||
return found;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
TRUE if device is like "hda3" and then set prefix to "hda".
|
||||
*/
|
||||
static gboolean
|
||||
is_partition(const char* device, char* prefix, size_t prefix_size)
|
||||
{
|
||||
g_strlcpy(prefix, device, prefix_size);
|
||||
|
||||
for ( ; *prefix; prefix++) {
|
||||
if (isdigit(*prefix)) {
|
||||
*prefix = '\0';
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Bug #539360.
|
||||
/sys/.../stat format is partially defined in
|
||||
linux/Documentation/block/stat.txt (looks outdated). Before linux
|
||||
2.5.25, /sys/block/%s/stat and /sys/block/%s/%s/stat were not the
|
||||
same, but the following commit changed the latter to have the same
|
||||
format and broke compatibility.
|
||||
|
||||
Commit 34e8beac92c27d292938065f8375842d2840767c
|
||||
Author: Jerome Marchand <jmarchan@redhat.com>
|
||||
Date: Fri Feb 8 11:04:55 2008 +0100
|
||||
|
||||
Enhanced partition statistics: sysfs
|
||||
|
||||
Reports enhanced partition statistics in sysfs.
|
||||
|
||||
Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
|
||||
|
||||
fs/partitions/check.c | 22 +++++++++++++++++++---
|
||||
1 files changed, 19 insertions(+), 3 deletions(-)
|
||||
|
||||
*/
|
||||
|
||||
static void
|
||||
get_sys_path(glibtop* server, const char *device, char **stat_path, const char **parse_format)
|
||||
{
|
||||
const char* linux_2_6_25_format = "%*llu %*llu %llu %*llu"
|
||||
"%*llu %*llu %llu %*llu";
|
||||
|
||||
char prefix[32];
|
||||
|
||||
if (is_partition(device, prefix, sizeof prefix)) {
|
||||
|
||||
*stat_path = g_strdup_printf("/sys/block/%s/%s/stat",
|
||||
prefix, device);
|
||||
if (server->os_version_code < LINUX_VERSION_CODE(2, 6, 25))
|
||||
*parse_format = "%*llu %llu %*llu %llu";
|
||||
else
|
||||
*parse_format = linux_2_6_25_format;
|
||||
}
|
||||
else
|
||||
{
|
||||
*stat_path = g_strdup_printf("/sys/block/%s/stat", device);
|
||||
if (server->os_version_code < LINUX_VERSION_CODE(2, 6, 25))
|
||||
*parse_format = "%*llu %*llu %llu %*llu %*llu %*llu %llu";
|
||||
else
|
||||
*parse_format = linux_2_6_25_format;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void linux_2_6_0(glibtop *server, glibtop_fsusage *buf, const char *path)
|
||||
{
|
||||
char *filename = NULL;
|
||||
const char *format;
|
||||
int ret;
|
||||
char buffer[BUFSIZ];
|
||||
char device[64];
|
||||
|
||||
if (!get_device(server, path, device, sizeof device))
|
||||
goto out;
|
||||
|
||||
get_sys_path(server, device, &filename, &format);
|
||||
|
||||
ret = try_file_to_buffer(buffer, sizeof buffer, "%s", filename);
|
||||
|
||||
if (ret < 0) goto out;
|
||||
|
||||
if (sscanf(buffer, format, &buf->read, &buf->write) != 2) {
|
||||
glibtop_warn_io_r(server, "Could not parse %s", filename);
|
||||
goto out;
|
||||
}
|
||||
|
||||
buf->flags |= (1 << GLIBTOP_FSUSAGE_READ) | (1 << GLIBTOP_FSUSAGE_WRITE);
|
||||
out:
|
||||
g_free(filename);
|
||||
}
|
||||
|
||||
|
||||
static void linux_2_4_0(glibtop *server, glibtop_fsusage *buf, const char *path)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
get_fsusage_read_write(glibtop *server, glibtop_fsusage *buf, const char *path)
|
||||
{
|
||||
if(server->os_version_code >= LINUX_VERSION_CODE(2, 6, 0))
|
||||
{
|
||||
linux_2_6_0(server, buf, path);
|
||||
}
|
||||
else if(server->os_version_code >= LINUX_VERSION_CODE(2, 4, 0))
|
||||
{
|
||||
linux_2_4_0(server, buf, path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* the following comes from sysdeps/common/mountlist.c if copyright matters...
|
||||
*/
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_fsusage =
|
||||
(1L << GLIBTOP_FSUSAGE_BLOCKS) + (1L << GLIBTOP_FSUSAGE_BFREE)
|
||||
+ (1L << GLIBTOP_FSUSAGE_BAVAIL) + (1L << GLIBTOP_FSUSAGE_FILES)
|
||||
+ (1L << GLIBTOP_FSUSAGE_FFREE) + (1L << GLIBTOP_FSUSAGE_BLOCK_SIZE);
|
||||
|
||||
|
||||
|
||||
void
|
||||
glibtop_get_fsusage_s(glibtop *server, glibtop_fsusage *buf, const char *path)
|
||||
{
|
||||
struct statvfs fsd;
|
||||
|
||||
memset(buf, 0, sizeof(glibtop_fsusage));
|
||||
|
||||
if (statvfs(path, &fsd) < 0) {
|
||||
glibtop_warn_r(server, "statvfs '%s' failed: %s", path, strerror (errno));
|
||||
return;
|
||||
}
|
||||
|
||||
buf->blocks = fsd.f_blocks;
|
||||
buf->bfree = fsd.f_bfree;
|
||||
buf->bavail = (fsd.f_bavail > fsd.f_bfree) ? 0 : fsd.f_bavail;
|
||||
buf->files = fsd.f_files;
|
||||
buf->ffree = fsd.f_ffree;
|
||||
buf->block_size = fsd.f_bsize;
|
||||
buf->flags = _glibtop_sysdeps_fsusage;
|
||||
|
||||
/* setting additional flags is delegated */
|
||||
get_fsusage_read_write(server, buf, path);
|
||||
}
|
||||
35
sysdeps/linux/glibtop_machine.h
Normal file
35
sysdeps/linux/glibtop_machine.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_MACHINE_H__
|
||||
#define __GLIBTOP_MACHINE_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
struct _glibtop_machine
|
||||
{
|
||||
};
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
223
sysdeps/linux/glibtop_private.c
Normal file
223
sysdeps/linux/glibtop_private.c
Normal file
@@ -0,0 +1,223 @@
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
unsigned long long
|
||||
get_scaled(const char *buffer, const char *key)
|
||||
{
|
||||
const char *ptr = buffer;
|
||||
char *next;
|
||||
unsigned long long value;
|
||||
|
||||
if (key) {
|
||||
if (G_LIKELY((ptr = strstr(buffer, key))))
|
||||
ptr += strlen(key);
|
||||
else {
|
||||
g_warning("Could not read key '%s' in buffer '%s'",
|
||||
key, buffer);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
value = strtoull(ptr, &next, 0);
|
||||
|
||||
for ( ; *next; ++next) {
|
||||
if (*next == 'k') {
|
||||
value *= 1024;
|
||||
break;
|
||||
} else if (*next == 'M') {
|
||||
value *= 1024 * 1024;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
skip_token (const char *p)
|
||||
{
|
||||
p = next_token(p);
|
||||
while (*p && !g_ascii_isspace(*p)) p++;
|
||||
p = next_token(p);
|
||||
return (char *)p;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Read functions
|
||||
*/
|
||||
enum TRY_FILE_TO_BUFFER
|
||||
{
|
||||
TRY_FILE_TO_BUFFER_OK = 0,
|
||||
TRY_FILE_TO_BUFFER_OPEN = -1,
|
||||
TRY_FILE_TO_BUFFER_READ = -2
|
||||
};
|
||||
|
||||
/*
|
||||
* Doesn't handle bufsiz == 0
|
||||
*/
|
||||
int try_file_to_buffer(char *buffer, size_t bufsiz, const char *format, ...)
|
||||
{
|
||||
char path[4096];
|
||||
int fd;
|
||||
size_t len = 0;
|
||||
ssize_t nread = 0;
|
||||
va_list pa;
|
||||
|
||||
if (G_UNLIKELY(bufsiz <= sizeof(char*)))
|
||||
g_warning("Huhu, bufsiz of %lu looks bad", (gulong)bufsiz);
|
||||
|
||||
va_start(pa, format);
|
||||
|
||||
/* C99 also provides vsnprintf */
|
||||
g_vsnprintf(path, sizeof path, format, pa);
|
||||
|
||||
va_end(pa);
|
||||
|
||||
bufsiz--; /* reserve 1 for trailing NUL */
|
||||
buffer [0] = '\0';
|
||||
|
||||
if((fd = open (path, O_RDONLY)) < 0)
|
||||
return TRY_FILE_TO_BUFFER_OPEN;
|
||||
|
||||
while (len < bufsiz) {
|
||||
nread = read (fd, buffer + len, bufsiz - len);
|
||||
|
||||
if (G_UNLIKELY(nread < 0)) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
len += nread;
|
||||
|
||||
if (nread == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
|
||||
if (nread < 0)
|
||||
return TRY_FILE_TO_BUFFER_READ;
|
||||
|
||||
buffer [len] = '\0';
|
||||
|
||||
return TRY_FILE_TO_BUFFER_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
file_to_buffer(glibtop *server, char *buffer, size_t bufsiz, const char *filename)
|
||||
{
|
||||
switch(try_file_to_buffer(buffer, bufsiz, "%s", filename))
|
||||
{
|
||||
case TRY_FILE_TO_BUFFER_OPEN:
|
||||
glibtop_error_io_r (server, "open (%s)", filename);
|
||||
case TRY_FILE_TO_BUFFER_READ:
|
||||
glibtop_error_io_r (server, "read (%s)", filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static unsigned long
|
||||
read_boot_time(glibtop *server)
|
||||
{
|
||||
char* line = NULL;
|
||||
size_t size = 0;
|
||||
FILE* stat;
|
||||
unsigned long btime = 0;
|
||||
|
||||
if (!(stat = fopen("/proc/stat", "r"))) {
|
||||
glibtop_error_io_r(server, "fopen(\"/proc/stat\")");
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (getline(&line, &size, stat) != -1) {
|
||||
if (!strncmp(line, "btime", 5)) {
|
||||
btime = strtoul(skip_token(line), NULL, 10);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(line);
|
||||
fclose(stat);
|
||||
out:
|
||||
return btime;
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned long
|
||||
get_boot_time(glibtop *server)
|
||||
{
|
||||
static unsigned long boot_time = 0UL;
|
||||
|
||||
if(G_UNLIKELY(!boot_time))
|
||||
{
|
||||
boot_time = read_boot_time(server);
|
||||
}
|
||||
|
||||
return boot_time;
|
||||
}
|
||||
|
||||
|
||||
|
||||
gboolean
|
||||
check_cpu_line(glibtop *server, const char *line, unsigned i)
|
||||
{
|
||||
char start[10];
|
||||
|
||||
g_snprintf(start, sizeof start, "cpu%u", i);
|
||||
|
||||
return g_str_has_prefix(line, start);
|
||||
}
|
||||
|
||||
|
||||
|
||||
gboolean
|
||||
has_sysfs(void)
|
||||
{
|
||||
static gboolean init;
|
||||
static gboolean sysfs;
|
||||
|
||||
if (G_UNLIKELY(!init)) {
|
||||
sysfs = g_file_test("/sys", G_FILE_TEST_IS_DIR);
|
||||
init = TRUE;
|
||||
}
|
||||
|
||||
return sysfs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
gboolean safe_readlink(const char *path, char *buf, size_t bufsiz)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
ret = readlink(path, buf, bufsiz - 1);
|
||||
|
||||
if (ret == -1) {
|
||||
g_warning("Could not read link %s : %s", path, strerror(errno));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
buf[ret] = '\0';
|
||||
return TRUE;
|
||||
}
|
||||
153
sysdeps/linux/glibtop_private.h
Normal file
153
sysdeps/linux/glibtop_private.h
Normal file
@@ -0,0 +1,153 @@
|
||||
/* Copyright (C) 2004 Benoît Dejean
|
||||
This file is part of LibGTop 2.0.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX__GLIBTOP_PRIVATE_H__
|
||||
#define __LINUX__GLIBTOP_PRIVATE_H__
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define LINUX_VERSION_CODE(x,y,z) (0x10000*(x) + 0x100*(y) + z)
|
||||
|
||||
|
||||
static inline char*
|
||||
next_token(const char *p)
|
||||
{
|
||||
while (g_ascii_isspace(*p)) p++;
|
||||
return (char*) p;
|
||||
}
|
||||
|
||||
char *
|
||||
skip_token (const char *p);
|
||||
|
||||
static inline char *
|
||||
skip_multiple_token (const char *p, size_t count)
|
||||
{
|
||||
while(count--)
|
||||
p = skip_token (p);
|
||||
|
||||
return (char *)p;
|
||||
}
|
||||
|
||||
|
||||
static inline char *
|
||||
skip_line (const char *p)
|
||||
{
|
||||
while (*p && *p != '\n') p++;
|
||||
return (char *) (*p ? p+1 : p);
|
||||
}
|
||||
|
||||
/*
|
||||
* Smart strtoul which handles binary suffixes
|
||||
* e.g: get_scaled("Size: 32 kB", "Size:") == 32768
|
||||
* key can be NULL if there's not prefix to strip (or prefix size is known
|
||||
*/
|
||||
unsigned long long
|
||||
get_scaled(const char *buffer, const char *key);
|
||||
|
||||
|
||||
/* aborts on error */
|
||||
void
|
||||
file_to_buffer(glibtop *server, char *buffer, size_t bufsiz, const char *filename);
|
||||
|
||||
/* return < 0 on error, otherwise 0 on success */
|
||||
int
|
||||
try_file_to_buffer(char *buffer, size_t bufsiz, const char *format, ...) G_GNUC_PRINTF(3, 4);
|
||||
|
||||
|
||||
/* some inline functions that wrap proc path
|
||||
* as fast as macros :)
|
||||
*/
|
||||
|
||||
static inline int
|
||||
proc_file_to_buffer (char *buffer, size_t bufsiz, const char *fmt, pid_t pid)
|
||||
{
|
||||
return try_file_to_buffer(buffer, bufsiz, fmt, pid);
|
||||
}
|
||||
|
||||
static inline int
|
||||
proc_stat_to_buffer (char *buffer, size_t bufsiz, pid_t pid)
|
||||
{
|
||||
return proc_file_to_buffer(buffer, bufsiz, "/proc/%d/stat", pid);
|
||||
}
|
||||
|
||||
static inline int
|
||||
proc_status_to_buffer (char *buffer, size_t bufsiz, pid_t pid)
|
||||
{
|
||||
return proc_file_to_buffer(buffer, bufsiz, "/proc/%d/status", pid);
|
||||
}
|
||||
|
||||
static inline int
|
||||
proc_statm_to_buffer (char *buffer, size_t bufsiz, pid_t pid)
|
||||
{
|
||||
return proc_file_to_buffer(buffer, bufsiz, "/proc/%d/statm", pid);
|
||||
}
|
||||
|
||||
|
||||
static inline char *
|
||||
proc_stat_after_cmd (char *p)
|
||||
{
|
||||
p = strrchr (p, ')');
|
||||
if (G_LIKELY(p))
|
||||
*p++ = '\0';
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
unsigned long
|
||||
get_boot_time(glibtop *server);
|
||||
|
||||
|
||||
gboolean
|
||||
check_cpu_line(glibtop *server, const char *line, unsigned n);
|
||||
|
||||
|
||||
static inline gboolean
|
||||
check_cpu_line_warn(glibtop *server, const char *line, unsigned i)
|
||||
{
|
||||
gboolean ret;
|
||||
|
||||
ret = check_cpu_line(server, line, i);
|
||||
|
||||
if (G_UNLIKELY(!ret))
|
||||
glibtop_warn_io_r(server,
|
||||
"'%s' does not start with 'cpu%u'",
|
||||
line, i);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
has_sysfs(void) G_GNUC_CONST;
|
||||
|
||||
gboolean safe_readlink(const char *path, char *buf, size_t bufsiz);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __LINUX__GLIBTOP_PRIVATE_H__ */
|
||||
51
sysdeps/linux/glibtop_server.h
Normal file
51
sysdeps/linux/glibtop_server.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX__GLIBTOP_SERVER_H__
|
||||
#define __LINUX__GLIBTOP_SERVER_H__
|
||||
|
||||
#define GLIBTOP_SUID_CPU 0
|
||||
#define GLIBTOP_SUID_MEM 0
|
||||
#define GLIBTOP_SUID_SWAP 0
|
||||
#define GLIBTOP_SUID_UPTIME 0
|
||||
#define GLIBTOP_SUID_LOADAVG 0
|
||||
#define GLIBTOP_SUID_SHM_LIMITS 0
|
||||
#define GLIBTOP_SUID_MSG_LIMITS 0
|
||||
#define GLIBTOP_SUID_SEM_LIMITS 0
|
||||
#define GLIBTOP_SUID_PROCLIST 0
|
||||
#define GLIBTOP_SUID_PROC_STATE 0
|
||||
#define GLIBTOP_SUID_PROC_UID 0
|
||||
#define GLIBTOP_SUID_PROC_MEM 0
|
||||
#define GLIBTOP_SUID_PROC_TIME 0
|
||||
#define GLIBTOP_SUID_PROC_SIGNAL 0
|
||||
#define GLIBTOP_SUID_PROC_KERNEL 0
|
||||
#define GLIBTOP_SUID_PROC_SEGMENT 0
|
||||
#define GLIBTOP_SUID_PROC_ARGS 0
|
||||
#define GLIBTOP_SUID_PROC_MAP 0
|
||||
#define GLIBTOP_SUID_NETLOAD 0
|
||||
#define GLIBTOP_SUID_NETLIST 0
|
||||
#define GLIBTOP_SUID_PROC_WD 0
|
||||
#define GLIBTOP_SUID_PROC_AFFINITY 0
|
||||
#define GLIBTOP_SUID_PPP 0
|
||||
#define GLIBTOP_SUID_PROC_FILE 0
|
||||
#define GLIBTOP_SUID_PROC_IO 0
|
||||
|
||||
#endif /* __LINUX__GLIBTOP_SERVER_H__ */
|
||||
81
sysdeps/linux/loadavg.c
Normal file
81
sysdeps/linux/loadavg.c
Normal file
@@ -0,0 +1,81 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/loadavg.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_loadavg =
|
||||
(1L << GLIBTOP_LOADAVG_LOADAVG);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_loadavg_tasks =
|
||||
(1L << GLIBTOP_LOADAVG_NR_RUNNING) +
|
||||
(1L << GLIBTOP_LOADAVG_NR_TASKS) +
|
||||
(1L << GLIBTOP_LOADAVG_LAST_PID);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_loadavg_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
|
||||
}
|
||||
|
||||
/* Provides load load averange. */
|
||||
|
||||
#define FILENAME "/proc/loadavg"
|
||||
|
||||
void
|
||||
glibtop_get_loadavg_s (glibtop *server, glibtop_loadavg *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *p, *old;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_loadavg));
|
||||
|
||||
file_to_buffer(server, buffer, sizeof buffer, FILENAME);
|
||||
|
||||
buf->loadavg [0] = g_ascii_strtod (buffer, &p);
|
||||
buf->loadavg [1] = g_ascii_strtod (p, &p);
|
||||
buf->loadavg [2] = g_ascii_strtod (p, &p);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_loadavg;
|
||||
|
||||
p = next_token(p);
|
||||
|
||||
/* Older Linux versions don't have the nr_running/nr_tasks fields. */
|
||||
|
||||
old = p;
|
||||
while (*p) {
|
||||
if (*p == '/')
|
||||
break;
|
||||
if (!isdigit (*p))
|
||||
return;
|
||||
p++;
|
||||
}
|
||||
|
||||
buf->nr_running = strtoull (old, &p, 0); p++;
|
||||
buf->nr_tasks = strtoull (p, &p, 0);
|
||||
buf->last_pid = strtoull (p, &p, 0);
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_loadavg_tasks;
|
||||
}
|
||||
71
sysdeps/linux/mem.c
Normal file
71
sysdeps/linux/mem.c
Normal file
@@ -0,0 +1,71 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/mem.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_mem =
|
||||
(1L << GLIBTOP_MEM_TOTAL) + (1L << GLIBTOP_MEM_USED) +
|
||||
(1L << GLIBTOP_MEM_FREE) + (1L << GLIBTOP_MEM_SHARED) +
|
||||
(1L << GLIBTOP_MEM_BUFFER) + (1L << GLIBTOP_MEM_CACHED) +
|
||||
(1L << GLIBTOP_MEM_USER);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_mem_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.mem = _glibtop_sysdeps_mem;
|
||||
}
|
||||
|
||||
/* Provides information about memory usage. */
|
||||
|
||||
#define FILENAME "/proc/meminfo"
|
||||
|
||||
void
|
||||
glibtop_get_mem_s (glibtop *server, glibtop_mem *buf)
|
||||
{
|
||||
char buffer [BUFSIZ];
|
||||
|
||||
memset(buf, 0, sizeof *buf);
|
||||
|
||||
file_to_buffer(server, buffer, sizeof buffer, FILENAME);
|
||||
|
||||
/* try to match procps's `free` */
|
||||
buf->total = get_scaled(buffer, "MemTotal:");
|
||||
buf->free = get_scaled(buffer, "MemFree:");
|
||||
buf->used = buf->total - buf->free;
|
||||
buf->shared = get_scaled(buffer, "Shmem:");
|
||||
buf->buffer = get_scaled(buffer, "Buffers:");
|
||||
buf->cached = get_scaled(buffer, "Cached:") + get_scaled(buffer, "Slab:");
|
||||
|
||||
if (server->os_version_code >= LINUX_VERSION_CODE(3, 14, 0)) {
|
||||
buf->user = buf->total - get_scaled(buffer, "MemAvailable:");
|
||||
}
|
||||
else {
|
||||
buf->user = buf->total - buf->free - buf->cached - buf->buffer;
|
||||
}
|
||||
|
||||
buf->flags = _glibtop_sysdeps_mem;
|
||||
}
|
||||
167
sysdeps/linux/mountlist.c
Normal file
167
sysdeps/linux/mountlist.c
Normal file
@@ -0,0 +1,167 @@
|
||||
/* mountlist.c -- return a list of mounted filesystems
|
||||
Copyright (C) 1991, 1992 Free Software Foundation, Inc.
|
||||
|
||||
This file is a fork of sysdeps/common/mountlist.c.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2, or (at your option)
|
||||
any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
||||
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
mode: C
|
||||
c-file-style: "gnu"
|
||||
End:
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <mntent.h>
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/mountlist.h>
|
||||
#include <glibtop/error.h>
|
||||
|
||||
|
||||
/* IgnoreList */
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GHashTable *table;
|
||||
} IgnoreList;
|
||||
|
||||
|
||||
static IgnoreList*
|
||||
ignore_list_new(void)
|
||||
{
|
||||
IgnoreList* ig;
|
||||
ig = g_new(IgnoreList, 1);
|
||||
ig->table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
|
||||
return ig;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ignore_list_delete(IgnoreList* ig)
|
||||
{
|
||||
if (ig) {
|
||||
g_hash_table_destroy(ig->table);
|
||||
g_free(ig);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
ignore_list_add(IgnoreList* ig, const char* fs)
|
||||
{
|
||||
g_hash_table_insert(ig->table, g_strdup(fs), GINT_TO_POINTER(1));
|
||||
}
|
||||
|
||||
|
||||
static gboolean
|
||||
ignore_list_has(IgnoreList* ig, const char* fs)
|
||||
{
|
||||
gpointer data;
|
||||
data = g_hash_table_lookup(ig->table, fs);
|
||||
return data != NULL;
|
||||
}
|
||||
|
||||
|
||||
/* ~IgnoreList */
|
||||
|
||||
|
||||
static gboolean
|
||||
ignore_fs(const char *fstype, IgnoreList** ig)
|
||||
{
|
||||
if (!*ig) {
|
||||
FILE* fs;
|
||||
char line[128];
|
||||
|
||||
*ig = ignore_list_new();
|
||||
|
||||
ignore_list_add(*ig, "none");
|
||||
|
||||
if ((fs = fopen("/proc/filesystems", "r")) != NULL) {
|
||||
while (fgets(line, sizeof line, fs)) {
|
||||
if (!strncmp(line, "nodev", 5)) {
|
||||
char *type;
|
||||
type = g_strstrip(line + 5);
|
||||
ignore_list_add(*ig, type);
|
||||
}
|
||||
}
|
||||
fclose(fs);
|
||||
}
|
||||
}
|
||||
|
||||
return ignore_list_has(*ig, fstype);
|
||||
}
|
||||
|
||||
|
||||
glibtop_mountentry *
|
||||
glibtop_get_mountlist_s(glibtop *server, glibtop_mountlist *buf, int all_fs)
|
||||
{
|
||||
const struct mntent *mnt;
|
||||
FILE *fp;
|
||||
GArray* entries;
|
||||
IgnoreList* ig = NULL;
|
||||
|
||||
memset(buf, 0, sizeof(glibtop_mountlist));
|
||||
|
||||
/* wild guess, preallocate 8 entries
|
||||
on a desktop, almost everyone has / and a tmpfs for udev
|
||||
if all_fs, there are also proc, sys, fuse, binfmt, etc */
|
||||
entries = g_array_sized_new(FALSE, FALSE, sizeof(glibtop_mountentry), 8);
|
||||
|
||||
if (!(fp = setmntent(MOUNTED, "r"))) {
|
||||
glibtop_warn_io_r(server, "Could not open %s", MOUNTED);
|
||||
goto out;
|
||||
}
|
||||
|
||||
while ((mnt = getmntent(fp)))
|
||||
{
|
||||
glibtop_mountentry *me;
|
||||
const char *devopt;
|
||||
gsize len;
|
||||
|
||||
if (!all_fs && ignore_fs(mnt->mnt_type, &ig))
|
||||
continue;
|
||||
|
||||
len = entries->len;
|
||||
g_array_set_size(entries, len + 1);
|
||||
me = &g_array_index(entries, glibtop_mountentry, len);
|
||||
|
||||
g_strlcpy(me->devname, mnt->mnt_fsname, sizeof me->devname);
|
||||
g_strlcpy(me->mountdir, mnt->mnt_dir, sizeof me->mountdir);
|
||||
g_strlcpy(me->type, mnt->mnt_type, sizeof me->type);
|
||||
devopt = strstr(mnt->mnt_opts, "dev=");
|
||||
me->dev = (devopt ? strtoull(devopt + sizeof "dev=", NULL, 0) : (dev_t)-1);
|
||||
}
|
||||
|
||||
endmntent(fp);
|
||||
|
||||
|
||||
out:
|
||||
ignore_list_delete(ig);
|
||||
|
||||
buf->size = sizeof(glibtop_mountentry);
|
||||
buf->number = entries->len;
|
||||
buf->total = buf->number * buf->size;
|
||||
buf->flags = (1 << GLIBTOP_MOUNTLIST_SIZE)
|
||||
| (1 << GLIBTOP_MOUNTLIST_NUMBER)
|
||||
| (1 << GLIBTOP_MOUNTLIST_TOTAL);
|
||||
|
||||
return (glibtop_mountentry*) g_array_free(entries, FALSE);
|
||||
}
|
||||
61
sysdeps/linux/msg_limits.c
Normal file
61
sysdeps/linux/msg_limits.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/msg_limits.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_msg_limits =
|
||||
(1L << GLIBTOP_IPC_MSGPOOL) + (1L << GLIBTOP_IPC_MSGMAP) +
|
||||
(1L << GLIBTOP_IPC_MSGMAX) + (1L << GLIBTOP_IPC_MSGMNB) +
|
||||
(1L << GLIBTOP_IPC_MSGMNI) + (1L << GLIBTOP_IPC_MSGSSZ) +
|
||||
(1L << GLIBTOP_IPC_MSGTQL);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_msg_limits_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
|
||||
}
|
||||
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
void
|
||||
glibtop_get_msg_limits_s (glibtop *server, glibtop_msg_limits *buf)
|
||||
{
|
||||
struct msginfo msginfo;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_msg_limits));
|
||||
|
||||
msgctl (0, IPC_INFO, (void*) &msginfo);
|
||||
|
||||
buf->msgpool = msginfo.msgpool;
|
||||
buf->msgmap = msginfo.msgmap;
|
||||
buf->msgmax = msginfo.msgmax;
|
||||
buf->msgmnb = msginfo.msgmnb;
|
||||
buf->msgmni = msginfo.msgmni;
|
||||
buf->msgssz = msginfo.msgssz;
|
||||
buf->msgtql = msginfo.msgtql;
|
||||
buf->flags = _glibtop_sysdeps_msg_limits;
|
||||
}
|
||||
80
sysdeps/linux/netlist.c
Normal file
80
sysdeps/linux/netlist.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/netlist.h>
|
||||
#include <glibtop/error.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netlist = (1 << GLIBTOP_NETLIST_NUMBER);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_netlist_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.netlist = _glibtop_sysdeps_netlist;
|
||||
}
|
||||
|
||||
|
||||
char**
|
||||
glibtop_get_netlist_s (glibtop *server, glibtop_netlist *buf)
|
||||
{
|
||||
char line[1024];
|
||||
FILE *f;
|
||||
GPtrArray *devices;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_netlist));
|
||||
|
||||
f = fopen("/proc/net/dev", "r");
|
||||
|
||||
if(!f)
|
||||
{
|
||||
glibtop_warn_io_r (server, "cannot open \"/proc/net/dev\"");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
devices = g_ptr_array_new();
|
||||
|
||||
while(fgets(line, sizeof line, f))
|
||||
{
|
||||
char *sep = strchr(line, ':');
|
||||
|
||||
if(!sep) continue;
|
||||
|
||||
*sep = '\0'; /* truncate : we only need the name */
|
||||
|
||||
g_strstrip(line);
|
||||
g_ptr_array_add(devices, g_strdup(line));
|
||||
buf->number++;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_netlist;
|
||||
|
||||
g_ptr_array_add(devices, NULL);
|
||||
|
||||
return (char**) g_ptr_array_free(devices, FALSE);
|
||||
}
|
||||
|
||||
561
sysdeps/linux/netload.c
Normal file
561
sysdeps/linux/netload.c
Normal file
@@ -0,0 +1,561 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/netload.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#if !defined (__GLIBC__) || __GNU_LIBRARY__ > 1
|
||||
/* GNU LibC */
|
||||
#include <net/if.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <net/if.h>
|
||||
#elif defined (__GLIBC__) /* Libc 5 */
|
||||
#include <linux/if.h>
|
||||
#include <linux/in.h>
|
||||
#include <linux/ip.h>
|
||||
#include <linux/icmp.h>
|
||||
#include <linux/tcp.h>
|
||||
#include <linux/udp.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_IFADDRS_H
|
||||
/* needed for IPV6 support */
|
||||
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#ifndef IN6_IS_ADDR_GLOBAL
|
||||
#define IN6_IS_ADDR_GLOBAL(a) \
|
||||
(((((__const uint8_t *) (a))[0] & 0xff) == 0x3f \
|
||||
|| (((__const uint8_t *) (a))[0] & 0xff) == 0x20))
|
||||
#endif
|
||||
#endif /* HAVE_IFADDRS_H */
|
||||
|
||||
|
||||
#define _GLIBTOP_IP_FW_ACCTIN 0x1000 /* Account incoming packets only. */
|
||||
#define _GLIBTOP_IP_FW_ACCTOUT 0x2000 /* Account outgoing packets only. */
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload =
|
||||
(1L << GLIBTOP_NETLOAD_ERRORS_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_ERRORS_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_COLLISIONS);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_data =
|
||||
(1L << GLIBTOP_NETLOAD_ADDRESS) +
|
||||
(1L << GLIBTOP_NETLOAD_SUBNET) +
|
||||
(1L << GLIBTOP_NETLOAD_MTU);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_bytes =
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_packets =
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_total =
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_in =
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_IN) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_IN);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_out =
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL) +
|
||||
(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
|
||||
(1L << GLIBTOP_NETLOAD_BYTES_OUT);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_netload_6 =
|
||||
(1L << GLIBTOP_NETLOAD_ADDRESS6) +
|
||||
(1L << GLIBTOP_NETLOAD_PREFIX6) +
|
||||
(1L << GLIBTOP_NETLOAD_SCOPE6);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_netload_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.netload = _glibtop_sysdeps_netload |
|
||||
_glibtop_sysdeps_netload_data |
|
||||
_glibtop_sysdeps_netload_bytes |
|
||||
_glibtop_sysdeps_netload_packets;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_IFADDRS_H
|
||||
|
||||
static void get_ipv6(glibtop *server, glibtop_netload *buf,
|
||||
const char *interface)
|
||||
{
|
||||
struct ifaddrs *ifa0, *ifr6;
|
||||
|
||||
if(getifaddrs (&ifa0) != 0)
|
||||
{
|
||||
glibtop_warn_r(server, "getifaddrs failed : %s", g_strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
for (ifr6 = ifa0; ifr6; ifr6 = ifr6->ifa_next) {
|
||||
if (strcmp (ifr6->ifa_name, interface) == 0
|
||||
&& ifr6->ifa_addr != NULL
|
||||
&& ifr6->ifa_addr->sa_family == AF_INET6)
|
||||
break;
|
||||
}
|
||||
|
||||
if(!ifr6) goto free_ipv6;
|
||||
|
||||
memcpy(buf->address6,
|
||||
&((struct sockaddr_in6 *) ifr6->ifa_addr)->sin6_addr,
|
||||
16);
|
||||
|
||||
memcpy(buf->prefix6,
|
||||
&((struct sockaddr_in6 *) ifr6->ifa_netmask)->sin6_addr,
|
||||
16);
|
||||
|
||||
|
||||
if (IN6_IS_ADDR_LINKLOCAL (buf->address6))
|
||||
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_LINK;
|
||||
|
||||
else if (IN6_IS_ADDR_SITELOCAL (buf->address6))
|
||||
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_SITE;
|
||||
|
||||
else if (IN6_IS_ADDR_GLOBAL (buf->address6)
|
||||
|| IN6_IS_ADDR_MC_ORGLOCAL (buf->address6)
|
||||
|| IN6_IS_ADDR_V4COMPAT (buf->address6)
|
||||
|| IN6_IS_ADDR_MULTICAST (buf->address6)
|
||||
|| IN6_IS_ADDR_UNSPECIFIED (buf->address6)
|
||||
)
|
||||
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_GLOBAL;
|
||||
|
||||
else if (IN6_IS_ADDR_LOOPBACK (buf->address6))
|
||||
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_HOST;
|
||||
|
||||
else
|
||||
buf->scope6 = GLIBTOP_IF_IN6_SCOPE_UNKNOWN;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_netload_6;
|
||||
|
||||
free_ipv6:
|
||||
freeifaddrs(ifa0);
|
||||
}
|
||||
|
||||
#endif /* HAVE_IFADDRS_H */
|
||||
|
||||
|
||||
|
||||
|
||||
static gboolean
|
||||
read_value(glibtop *server,
|
||||
const char *device,
|
||||
const char *filename,
|
||||
guint64 *value)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
if(try_file_to_buffer(buffer,
|
||||
sizeof buffer,
|
||||
"/sys/class/net/%s/statistics/%s",
|
||||
device,
|
||||
filename))
|
||||
{
|
||||
glibtop_warn_io_r(server,
|
||||
"Failed to open \"/sys/class/net/%s/statistics/%s\"",
|
||||
device,
|
||||
filename);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*value = strtoull(buffer, NULL, 10);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
linux_2_6_stats(glibtop *server,
|
||||
glibtop_netload *buf,
|
||||
const char *dev)
|
||||
{
|
||||
if(read_value(server, dev, "rx_packets", &buf->packets_in))
|
||||
buf->flags |= (1 << GLIBTOP_NETLOAD_PACKETS_IN);
|
||||
|
||||
if(read_value(server, dev, "tx_packets", &buf->packets_out))
|
||||
buf->flags |= (1 << GLIBTOP_NETLOAD_PACKETS_OUT);
|
||||
|
||||
buf->packets_total = buf->packets_in + buf->packets_out;
|
||||
buf->flags |= (1 << GLIBTOP_NETLOAD_PACKETS_TOTAL);
|
||||
|
||||
|
||||
if(read_value(server, dev, "rx_bytes", &buf->bytes_in))
|
||||
buf->flags |= (1 << GLIBTOP_NETLOAD_BYTES_IN);
|
||||
|
||||
if(read_value(server, dev, "tx_bytes", &buf->bytes_out))
|
||||
buf->flags |= (1 << GLIBTOP_NETLOAD_BYTES_OUT);
|
||||
|
||||
buf->bytes_total = buf->bytes_in + buf->bytes_out;
|
||||
buf->flags |= (1 << GLIBTOP_NETLOAD_BYTES_TOTAL);
|
||||
|
||||
|
||||
if(read_value(server, dev, "rx_errors", &buf->errors_in))
|
||||
buf->flags |= (1 << GLIBTOP_NETLOAD_ERRORS_IN);
|
||||
|
||||
if(read_value(server, dev, "tx_errors", &buf->errors_out))
|
||||
buf->flags |= (1 << GLIBTOP_NETLOAD_ERRORS_OUT);
|
||||
|
||||
buf->errors_total = buf->errors_in + buf->errors_out;
|
||||
buf->flags |= (1 << GLIBTOP_NETLOAD_ERRORS_TOTAL);
|
||||
|
||||
|
||||
if(read_value(server, dev, "collisions", &buf->collisions))
|
||||
buf->flags |= (1 << GLIBTOP_NETLOAD_COLLISIONS);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
linux_2_0_stats(glibtop *server,
|
||||
glibtop_netload *buf,
|
||||
const char *interface)
|
||||
{
|
||||
FILE *f;
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
f = fopen ("/proc/net/ip_acct", "r");
|
||||
|
||||
if (!f) {
|
||||
glibtop_warn_io_r (server,
|
||||
"Failed to open \"/proc/net/ip_acct\"");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Skip over the header line. */
|
||||
fgets (buffer, BUFSIZ-1, f);
|
||||
|
||||
while (fgets (buffer, BUFSIZ-1, f)) {
|
||||
unsigned long long flags, packets, bytes;
|
||||
char *p, *dev;
|
||||
|
||||
/* Skip over the network thing. */
|
||||
dev = skip_token (buffer) + 1;
|
||||
p = skip_token (dev);
|
||||
*p++ = 0;
|
||||
|
||||
if (strcmp (dev, interface))
|
||||
continue;
|
||||
|
||||
p = skip_token (p);
|
||||
|
||||
flags = strtoull (p, &p, 16);
|
||||
|
||||
p = skip_multiple_token (p, 2);
|
||||
|
||||
packets = strtoull (p, &p, 0);
|
||||
bytes = strtoull (p, &p, 0);
|
||||
|
||||
if (flags & _GLIBTOP_IP_FW_ACCTIN) {
|
||||
/* Incoming packets only. */
|
||||
|
||||
buf->packets_total += packets;
|
||||
buf->packets_in += packets;
|
||||
|
||||
buf->bytes_total += bytes;
|
||||
buf->bytes_in += bytes;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_netload_in;
|
||||
|
||||
} else if (flags & _GLIBTOP_IP_FW_ACCTOUT) {
|
||||
/* Outgoing packets only. */
|
||||
|
||||
buf->packets_total += packets;
|
||||
buf->packets_out += packets;
|
||||
|
||||
buf->bytes_total += bytes;
|
||||
buf->bytes_out += bytes;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_netload_out;
|
||||
|
||||
} else {
|
||||
/* Only have total values. */
|
||||
|
||||
buf->packets_total += packets;
|
||||
buf->bytes_total += bytes;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_netload_total;
|
||||
}
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
static void
|
||||
linux_2_4_stats(glibtop *server,
|
||||
glibtop_netload *buf,
|
||||
const char *interface)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int have_bytes, fields;
|
||||
FILE *f;
|
||||
|
||||
/* Ok, either IP accounting is not enabled in the kernel or
|
||||
* it was not enabled for the requested interface. */
|
||||
|
||||
f = fopen ("/proc/net/dev", "r");
|
||||
if (!f) {
|
||||
glibtop_warn_io_r(server,
|
||||
"Failed to open \"/proc/net/dev\"");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Skip over the header line. */
|
||||
fgets (buffer, BUFSIZ-1, f);
|
||||
fgets (buffer, BUFSIZ-1, f);
|
||||
|
||||
/* Starting with 2.1.xx (don't know exactly which version)
|
||||
* /proc/net/dev contains both byte and package counters. */
|
||||
|
||||
p = strchr (buffer, '|');
|
||||
if (!p) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Do we already have byte counters ? */
|
||||
have_bytes = strncmp (++p, "bytes", 5) == 0;
|
||||
|
||||
/* Count remaining 'Receive' fields so we know where
|
||||
* the first 'Transmit' field starts. */
|
||||
|
||||
fields = 0;
|
||||
while (*p != '|') {
|
||||
if (!isspace (*p++)) continue;
|
||||
while (isspace (*p++)) ;
|
||||
fields++;
|
||||
}
|
||||
|
||||
/* Should never happen. */
|
||||
if (fields < 2) {
|
||||
fclose (f);
|
||||
return;
|
||||
}
|
||||
fields--;
|
||||
|
||||
while (fgets (buffer, BUFSIZ-1, f)) {
|
||||
char *p, *dev;
|
||||
|
||||
dev = buffer;
|
||||
while (isspace (*dev)) dev++;
|
||||
|
||||
p = strchr (dev, ':');
|
||||
if (!p) continue;
|
||||
*p++ = 0;
|
||||
|
||||
/* If it's not a digit, then it's most likely an error
|
||||
* message like 'No statistics available'. */
|
||||
while (isspace (*p)) p++;
|
||||
if (!isdigit (*p)) continue;
|
||||
|
||||
if (strcmp (dev, interface))
|
||||
continue;
|
||||
|
||||
/* Ok, we've found the interface */
|
||||
|
||||
/* Only read byte counts if we really have them. */
|
||||
|
||||
if (have_bytes) {
|
||||
buf->bytes_in = strtoull (p, &p, 0);
|
||||
fields--;
|
||||
}
|
||||
|
||||
buf->packets_in = strtoull (p, &p, 0);
|
||||
buf->errors_in = strtoull (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, fields);
|
||||
|
||||
if (have_bytes)
|
||||
buf->bytes_out = strtoull (p, &p, 0);
|
||||
|
||||
buf->packets_out = strtoull (p, &p, 0);
|
||||
buf->errors_out = strtoull (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, 2);
|
||||
|
||||
buf->collisions = strtoull (p, &p, 0);
|
||||
|
||||
/* Compute total valules. */
|
||||
|
||||
buf->bytes_total = buf->bytes_in + buf->bytes_out;
|
||||
buf->packets_total = buf->packets_in + buf->packets_out;
|
||||
|
||||
/* And now the flags. */
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_netload;
|
||||
buf->flags |= _glibtop_sysdeps_netload_packets;
|
||||
|
||||
if (have_bytes)
|
||||
buf->flags |= _glibtop_sysdeps_netload_bytes;
|
||||
|
||||
break; /* finished */
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* Provides network statistics. */
|
||||
|
||||
void
|
||||
glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
|
||||
const char *interface)
|
||||
{
|
||||
int skfd;
|
||||
memset (buf, 0, sizeof (glibtop_netload));
|
||||
|
||||
skfd = socket (AF_INET, SOCK_DGRAM, 0);
|
||||
if (skfd) {
|
||||
struct ifreq ifr;
|
||||
|
||||
g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
|
||||
if (!ioctl (skfd, SIOCGIFFLAGS, &ifr)) {
|
||||
const unsigned long long flags = ifr.ifr_flags;
|
||||
|
||||
buf->flags |= (1L << GLIBTOP_NETLOAD_IF_FLAGS);
|
||||
|
||||
if (flags & IFF_UP)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_UP);
|
||||
|
||||
if (flags & IFF_BROADCAST)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_BROADCAST);
|
||||
|
||||
if (flags & IFF_DEBUG)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_DEBUG);
|
||||
|
||||
if (flags & IFF_LOOPBACK)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_LOOPBACK);
|
||||
|
||||
if (flags & IFF_POINTOPOINT)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_POINTOPOINT);
|
||||
|
||||
if (flags & IFF_RUNNING)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_RUNNING);
|
||||
|
||||
if (flags & IFF_NOARP)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_NOARP);
|
||||
|
||||
if (flags & IFF_PROMISC)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_PROMISC);
|
||||
|
||||
if (flags & IFF_ALLMULTI)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_ALLMULTI);
|
||||
|
||||
if (flags & IFF_MULTICAST)
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_MULTICAST);
|
||||
}
|
||||
|
||||
g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
|
||||
if (!ioctl(skfd, /* SIOCGIWNAME */ 0x8B01, &ifr))
|
||||
buf->if_flags |= (1L << GLIBTOP_IF_FLAGS_WIRELESS);
|
||||
|
||||
g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
|
||||
if (!ioctl (skfd, SIOCGIFADDR, &ifr)) {
|
||||
buf->address = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr;
|
||||
buf->flags |= (1L << GLIBTOP_NETLOAD_ADDRESS);
|
||||
}
|
||||
|
||||
g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
|
||||
if (!ioctl (skfd, SIOCGIFNETMASK, &ifr)) {
|
||||
buf->subnet = ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr;
|
||||
buf->flags |= (1L << GLIBTOP_NETLOAD_SUBNET);
|
||||
}
|
||||
|
||||
g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
|
||||
if (!ioctl (skfd, SIOCGIFMTU, &ifr)) {
|
||||
buf->mtu = ifr.ifr_mtu;
|
||||
buf->flags |= (1L << GLIBTOP_NETLOAD_MTU);
|
||||
}
|
||||
|
||||
g_strlcpy (ifr.ifr_name, interface, sizeof ifr.ifr_name);
|
||||
if (!ioctl (skfd, SIOCGIFHWADDR, &ifr)) {
|
||||
memcpy(buf->hwaddress, &ifr.ifr_hwaddr.sa_data, 8);
|
||||
buf->flags |= (1L << GLIBTOP_NETLOAD_HWADDRESS);
|
||||
}
|
||||
|
||||
close (skfd);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Statistics
|
||||
*/
|
||||
|
||||
/* Linux 2.1.114 - don't know where exactly this was added, but
|
||||
* recent kernels have byte count in /proc/net/dev so we don't
|
||||
* need IP accounting.
|
||||
*/
|
||||
|
||||
if (server->os_version_code < LINUX_VERSION_CODE(2, 1, 14)) {
|
||||
linux_2_0_stats(server, buf, interface);
|
||||
}
|
||||
else if (server->os_version_code > LINUX_VERSION_CODE(2, 6, 0)
|
||||
&& has_sysfs()) {
|
||||
linux_2_6_stats(server, buf, interface);
|
||||
}
|
||||
else {
|
||||
/* 2.4 and 2.6 without /sys (?$£Z¥!) */
|
||||
linux_2_4_stats(server, buf, interface);
|
||||
}
|
||||
|
||||
#ifdef HAVE_IFADDRS_H
|
||||
get_ipv6(server, buf, interface);
|
||||
#endif /* HAVE_IFADDRS_H */
|
||||
}
|
||||
|
||||
|
||||
|
||||
104
sysdeps/linux/open.c
Normal file
104
sysdeps/linux/open.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/cpu.h>
|
||||
#include <glibtop/open.h>
|
||||
#include <glibtop/error.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
/* =====================================================
|
||||
* Linux kernel version information for procps utilities
|
||||
* Copyright (c) 1996 Charles Blake <cblake@bbn.com>
|
||||
*/
|
||||
#include <sys/utsname.h>
|
||||
|
||||
static void set_linux_version(glibtop *server)
|
||||
{
|
||||
struct utsname uts;
|
||||
unsigned x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */
|
||||
int version_string_depth;
|
||||
|
||||
if (uname(&uts) == -1) /* failure most likely implies impending death */
|
||||
glibtop_error_r(server, "uname() failed");
|
||||
|
||||
version_string_depth = sscanf(uts.release, "%u.%u.%u", &x, &y, &z);
|
||||
|
||||
if ((version_string_depth < 2) || /* Non-standard for all known kernels */
|
||||
((version_string_depth < 3) && (x < 3))) /* Non-standard for 2.x.x kernels */
|
||||
glibtop_warn_r(server,
|
||||
"Non-standard uts for running kernel:\n"
|
||||
"release %s=%u.%u.%u gives version code %d\n",
|
||||
uts.release, x, y, z, LINUX_VERSION_CODE(x,y,z));
|
||||
|
||||
if (LINUX_VERSION_CODE(x, y, z) >= LINUX_VERSION_CODE(2, 6, 0)
|
||||
&& !has_sysfs())
|
||||
glibtop_warn_r(server,
|
||||
"You're running a 2.6 kernel without /sys."
|
||||
"You should mount it.");
|
||||
|
||||
server->os_version_code = LINUX_VERSION_CODE(x, y, z);
|
||||
}
|
||||
|
||||
/* ======================================================= */
|
||||
|
||||
/* Opens pipe to gtop server. Returns 0 on success and -1 on error. */
|
||||
|
||||
#define FILENAME "/proc/stat"
|
||||
#define STAT_BUFSIZ 81920
|
||||
|
||||
void
|
||||
glibtop_open_s (glibtop *server, const char *program_name,
|
||||
const unsigned long features,
|
||||
const unsigned flags)
|
||||
{
|
||||
char buffer [STAT_BUFSIZ], *p = buffer;
|
||||
|
||||
server->name = program_name;
|
||||
|
||||
set_linux_version(server);
|
||||
|
||||
file_to_buffer(server, buffer, sizeof buffer, FILENAME);
|
||||
|
||||
p = skip_line(p); /* cpu */
|
||||
|
||||
for (server->real_ncpu = 0; /* nop */; server->real_ncpu++) {
|
||||
|
||||
if (!check_cpu_line(server, p, server->real_ncpu)) {
|
||||
server->real_ncpu--;
|
||||
break;
|
||||
}
|
||||
|
||||
p = skip_line(p);
|
||||
}
|
||||
|
||||
server->ncpu = MIN(GLIBTOP_NCPU - 1, server->real_ncpu);
|
||||
|
||||
if (server->real_ncpu != server->ncpu) {
|
||||
glibtop_warn_r(server,
|
||||
"This machine has %d CPUs, "
|
||||
"%d are being monitored.",
|
||||
server->real_ncpu + 1,
|
||||
server->ncpu + 1);
|
||||
}
|
||||
}
|
||||
197
sysdeps/linux/ppp.c
Normal file
197
sysdeps/linux/ppp.c
Normal file
@@ -0,0 +1,197 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, October 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/ppp.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#ifdef HAVE_ISDN_H
|
||||
#include <linux/isdn.h>
|
||||
#else
|
||||
#define ISDN_MAX_CHANNELS 64
|
||||
#define IIOCGETCPS _IO('I',21)
|
||||
#endif /* HAVE_ISDN_H */
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_ppp =
|
||||
(1L << GLIBTOP_PPP_STATE) + (1L << GLIBTOP_PPP_BYTES_IN) +
|
||||
(1L << GLIBTOP_PPP_BYTES_OUT);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_ppp_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_ISDN_stats (glibtop *server, int *in, int *out)
|
||||
{
|
||||
unsigned long isdn_stats[2 * ISDN_MAX_CHANNELS], *ptr;
|
||||
int fd;
|
||||
|
||||
*in = *out = 0;
|
||||
|
||||
fd = open ("/dev/isdninfo", O_RDONLY);
|
||||
if (fd < 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ((ioctl (fd, IIOCGETCPS, isdn_stats) < 0) && (errno != 0)) {
|
||||
close(fd);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (ptr = isdn_stats;
|
||||
ptr != (isdn_stats + G_N_ELEMENTS(isdn_stats));
|
||||
/* NOOP */) {
|
||||
*in += *ptr++; *out += *ptr++;
|
||||
}
|
||||
|
||||
close (fd);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean is_ISDN_on (glibtop *server, int *online)
|
||||
{
|
||||
FILE *f = NULL;
|
||||
char buffer [BUFSIZ], *p;
|
||||
int i;
|
||||
|
||||
/* Perhaps I should try to explain this code a little bit.
|
||||
*
|
||||
* ------------------------------------------------------------
|
||||
* This is from the manpage of isdninfo(4):
|
||||
*
|
||||
* DESCRIPTION
|
||||
* /dev/isdninfo is a character device with major number 45
|
||||
* and minor number 255. It delivers status information from
|
||||
* the Linux ISDN subsystem to user level.
|
||||
*
|
||||
* DATA FORMAT
|
||||
* When reading from this device, the current status of the
|
||||
* Linux ISDN subsystem is delivered in 6 lines of text. Each
|
||||
* line starts with a tag string followed by a colon and
|
||||
* whitespace. After that the status values are appended sep-
|
||||
* arated by whitespace.
|
||||
*
|
||||
* flags is the tag of line 5. In this line for every driver
|
||||
* slot, it's B-Channel status is shown. If no driver
|
||||
* is registered in a slot, a ? is shown. For every
|
||||
* established B-Channel of the driver, a bit is set
|
||||
* in the shown value. The driver's first channel is
|
||||
* mapped to bit 0, the second channel to bit 1 and so
|
||||
* on.
|
||||
* ------------------------------------------------------------
|
||||
*
|
||||
* So we open /dev/isdninfo, discard the first four lines of text
|
||||
* and then check whether we have something that is not `0' or `?'
|
||||
* in one of the flags fields.
|
||||
*
|
||||
* Sounds complicated, but I don't see any other way to check whether
|
||||
* we are connected. Also, this is the method some other ISDN tools
|
||||
* for Linux use.
|
||||
*
|
||||
* Martin
|
||||
*/
|
||||
|
||||
f = fopen ("/dev/isdninfo", "r");
|
||||
|
||||
if (!f) return FALSE;
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
if (fgets (buffer, BUFSIZ, f) == NULL) {
|
||||
fclose (f);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (strncmp (buffer, "flags:", 6)) {
|
||||
fclose (f);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
p = buffer+6;
|
||||
|
||||
while (*p) {
|
||||
char *end = p;
|
||||
|
||||
if (isspace (*p)) {
|
||||
p++;
|
||||
continue;
|
||||
}
|
||||
|
||||
for (end = p; *end && !isspace (*end); end++)
|
||||
;
|
||||
|
||||
if (*end == 0)
|
||||
break;
|
||||
else
|
||||
*end = 0;
|
||||
|
||||
if (!strcmp (p, "?") || !strcmp (p, "0")) {
|
||||
p = end+1;
|
||||
continue;
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
|
||||
*online = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
fclose (f);
|
||||
|
||||
*online = FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* Provides PPP/ISDN information. */
|
||||
|
||||
void
|
||||
glibtop_get_ppp_s (glibtop *server, glibtop_ppp *buf, unsigned short device)
|
||||
{
|
||||
int in, out, online;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_ppp));
|
||||
|
||||
if (is_ISDN_on (server, &online)) {
|
||||
buf->state = online ? GLIBTOP_PPP_STATE_ONLINE :
|
||||
GLIBTOP_PPP_STATE_HANGUP;
|
||||
buf->flags |= (1L << GLIBTOP_PPP_STATE);
|
||||
}
|
||||
|
||||
if (get_ISDN_stats (server, &in, &out)) {
|
||||
buf->bytes_in = in;
|
||||
buf->bytes_out = out;
|
||||
buf->flags |= (1L << GLIBTOP_PPP_BYTES_IN) |
|
||||
(1L << GLIBTOP_PPP_BYTES_OUT);
|
||||
}
|
||||
}
|
||||
69
sysdeps/linux/procaffinity.c
Normal file
69
sysdeps/linux/procaffinity.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/* Copyright (C) 2007 Benoît Dejean
|
||||
This file is part of LibGTop 2.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/procaffinity.h>
|
||||
#include <glibtop/error.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
#include <sched.h>
|
||||
|
||||
|
||||
void
|
||||
_glibtop_init_proc_affinity_s(glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_affinity =
|
||||
(1 << GLIBTOP_PROC_AFFINITY_NUMBER) |
|
||||
(1 << GLIBTOP_PROC_AFFINITY_ALL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
guint16 *
|
||||
glibtop_get_proc_affinity_s(glibtop *server, glibtop_proc_affinity *buf, pid_t pid)
|
||||
{
|
||||
cpu_set_t set;
|
||||
size_t i;
|
||||
GArray* cpus;
|
||||
|
||||
memset(buf, 0, sizeof *buf);
|
||||
|
||||
if (sched_getaffinity(pid, sizeof set, &set) == -1) {
|
||||
glibtop_error_r(server, "sched_getaffinity failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cpus = g_array_new(FALSE, FALSE, sizeof(guint16));
|
||||
|
||||
for (i = 0; i < MIN(CPU_SETSIZE, (size_t)(server->ncpu + 1)); i++) {
|
||||
if (CPU_ISSET(i, &set)) {
|
||||
guint16 n = i;
|
||||
g_array_append_val(cpus, n);
|
||||
}
|
||||
}
|
||||
|
||||
buf->number = cpus->len;
|
||||
buf->all = (cpus->len == (size_t)(server->ncpu + 1));
|
||||
buf->flags = (1 << GLIBTOP_PROC_AFFINITY_NUMBER)
|
||||
| (1 << GLIBTOP_PROC_AFFINITY_ALL);
|
||||
|
||||
return (guint16*) g_array_free(cpus, FALSE);
|
||||
}
|
||||
|
||||
70
sysdeps/linux/procargs.c
Normal file
70
sysdeps/linux/procargs.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procargs.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_args =
|
||||
(1L << GLIBTOP_PROC_ARGS_SIZE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_proc_args_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
char *
|
||||
glibtop_get_proc_args_s (glibtop *server, glibtop_proc_args *buf,
|
||||
pid_t pid, unsigned max_len)
|
||||
{
|
||||
char filename[48]; /* magiv */
|
||||
|
||||
char *args;
|
||||
gsize length;
|
||||
GError *error = NULL;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_args));
|
||||
|
||||
sprintf (filename, "/proc/%d/cmdline", pid);
|
||||
|
||||
if(!g_file_get_contents(filename, &args, &length, &error)) {
|
||||
g_error_free(error);
|
||||
buf->size = 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if(max_len && max_len < length) {
|
||||
args = g_realloc(args, max_len);
|
||||
args[max_len - 1] = '\0';
|
||||
length = max_len;
|
||||
}
|
||||
|
||||
buf->size = length;
|
||||
buf->flags = _glibtop_sysdeps_proc_args;
|
||||
|
||||
return args;
|
||||
}
|
||||
70
sysdeps/linux/procio.c
Normal file
70
sysdeps/linux/procio.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/* Copyright (C) 2017 Robert Roth
|
||||
This file is part of LibGTop.
|
||||
|
||||
Contributed by Robert Roth <robert.roth.off@gmail.com>, February 2017.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procio.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_io =
|
||||
(1L << GLIBTOP_PROC_IO_DISK_RCHAR) + (1L << GLIBTOP_PROC_IO_DISK_WCHAR) +
|
||||
(1L << GLIBTOP_PROC_IO_DISK_RBYTES) + (1L << GLIBTOP_PROC_IO_DISK_WBYTES);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_proc_io_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_io = _glibtop_sysdeps_proc_io;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_io_s (glibtop *server, glibtop_proc_io *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
memset (buf, 0, sizeof (glibtop_proc_io));
|
||||
|
||||
if (server->os_version_code < LINUX_VERSION_CODE(2, 6, 20))
|
||||
return;
|
||||
|
||||
if (proc_file_to_buffer(buffer, sizeof buffer, "/proc/%d/io", pid))
|
||||
return;
|
||||
|
||||
p = skip_token (buffer);
|
||||
buf->disk_rchar = g_ascii_strtoull (p, &p, 10);
|
||||
p = skip_line (p);
|
||||
p = skip_token (p);
|
||||
buf->disk_wchar = g_ascii_strtoull (p, &p, 10);
|
||||
p = skip_line (p);
|
||||
p = skip_line (p);
|
||||
p = skip_line (p);
|
||||
p = skip_token (p);
|
||||
buf->disk_rbytes = g_ascii_strtoull (p, &p, 10);
|
||||
p = skip_line (p);
|
||||
p = skip_token (p);
|
||||
buf->disk_wbytes = g_ascii_strtoull (p, &p, 10);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_io;
|
||||
}
|
||||
79
sysdeps/linux/prockernel.c
Normal file
79
sysdeps/linux/prockernel.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/prockernel.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_kernel =
|
||||
(1L << GLIBTOP_PROC_KERNEL_K_FLAGS) + (1L << GLIBTOP_PROC_KERNEL_MIN_FLT) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_MAJ_FLT) + (1L << GLIBTOP_PROC_KERNEL_CMIN_FLT) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_CMAJ_FLT) + (1L << GLIBTOP_PROC_KERNEL_KSTK_ESP) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_KSTK_EIP) + (1L << GLIBTOP_PROC_KERNEL_NWCHAN) +
|
||||
(1L << GLIBTOP_PROC_KERNEL_WCHAN);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_proc_kernel_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_kernel_s (glibtop *server, glibtop_proc_kernel *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_kernel));
|
||||
|
||||
if (proc_stat_to_buffer(buffer, sizeof buffer, pid))
|
||||
return;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return;
|
||||
|
||||
p = skip_multiple_token (p, 6);
|
||||
|
||||
buf->k_flags = strtoull (p, &p, 0);
|
||||
buf->min_flt = strtoull (p, &p, 0);
|
||||
buf->cmin_flt = strtoull (p, &p, 0);
|
||||
buf->maj_flt = strtoull (p, &p, 0);
|
||||
buf->cmaj_flt = strtoull (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, 15);
|
||||
|
||||
buf->kstk_esp = strtoull (p, &p, 0);
|
||||
buf->kstk_eip = strtoull (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, 4);
|
||||
|
||||
buf->nwchan = strtoull (p, &p, 0);
|
||||
|
||||
proc_file_to_buffer(buf->wchan, sizeof buf->wchan, "/proc/%d/wchan", pid),
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_kernel;
|
||||
}
|
||||
169
sysdeps/linux/proclist.c
Normal file
169
sysdeps/linux/proclist.c
Normal file
@@ -0,0 +1,169 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/proclist.h>
|
||||
|
||||
#include <glibtop/procuid.h>
|
||||
#include <glibtop/procstate.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proclist =
|
||||
(1L << GLIBTOP_PROCLIST_TOTAL) + (1L << GLIBTOP_PROCLIST_NUMBER) +
|
||||
(1L << GLIBTOP_PROCLIST_SIZE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_proclist_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
|
||||
}
|
||||
|
||||
/* Fetch list of currently running processes.
|
||||
*
|
||||
* The interface of this function is a little bit different from the others:
|
||||
* buf->flags is only set if the call succeeded, in this case pids_chain,
|
||||
* a list of the pids of all currently running processes is returned,
|
||||
* buf->number is the number of elements of this list and buf->size is
|
||||
* the size of one single element (sizeof (unsigned)). The total size is
|
||||
* stored in buf->total.
|
||||
*
|
||||
* The calling function has to free the memory to which a pointer is returned.
|
||||
*
|
||||
* On error, NULL is returned and buf->flags is zero. */
|
||||
|
||||
pid_t*
|
||||
glibtop_get_proclist_s (glibtop *server, glibtop_proclist *buf,
|
||||
gint64 which, gint64 arg)
|
||||
{
|
||||
DIR *proc;
|
||||
struct dirent *entry;
|
||||
GArray *pids;
|
||||
glibtop_proc_uid procuid;
|
||||
glibtop_proc_state procstate;
|
||||
struct stat statb;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proclist));
|
||||
|
||||
proc = opendir ("/proc");
|
||||
if (!proc) return NULL;
|
||||
|
||||
if(fstat(dirfd(proc), &statb) != 0) return NULL;
|
||||
|
||||
pids = g_array_sized_new(FALSE, FALSE, sizeof(pid_t), statb.st_nlink);
|
||||
|
||||
/* read every every entry in /proc */
|
||||
|
||||
while((entry = readdir (proc))) {
|
||||
pid_t pid;
|
||||
|
||||
if (entry->d_type != DT_DIR)
|
||||
continue;
|
||||
|
||||
if (!(pid = strtoul(entry->d_name, NULL, 10)))
|
||||
continue;
|
||||
|
||||
switch (which & GLIBTOP_KERN_PROC_MASK) {
|
||||
case GLIBTOP_KERN_PROC_ALL:
|
||||
break;
|
||||
case GLIBTOP_KERN_PROC_PID:
|
||||
if ((pid_t) arg != pid)
|
||||
continue;
|
||||
break;
|
||||
case GLIBTOP_KERN_PROC_UID:
|
||||
{
|
||||
char path[32];
|
||||
struct stat path_stat;
|
||||
|
||||
snprintf(path, sizeof path, "/proc/%u", (unsigned)pid);
|
||||
|
||||
if (stat(path, &path_stat))
|
||||
continue;
|
||||
|
||||
if ((uid_t) arg != path_stat.st_uid)
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case GLIBTOP_KERN_PROC_PGRP:
|
||||
/* Do you really, really need this ? */
|
||||
glibtop_get_proc_uid_s (server, &procuid, pid);
|
||||
if (procuid.flags & (1L << GLIBTOP_PROC_UID_PGRP))
|
||||
if ((int) arg != procuid.pgrp)
|
||||
continue;
|
||||
break;
|
||||
case GLIBTOP_KERN_PROC_SESSION:
|
||||
/* Do you really, really need this ? */
|
||||
glibtop_get_proc_uid_s (server, &procuid, pid);
|
||||
if (procuid.flags & (1L << GLIBTOP_PROC_UID_SESSION))
|
||||
if ((int) arg != procuid.session)
|
||||
continue;
|
||||
break;
|
||||
case GLIBTOP_KERN_PROC_TTY:
|
||||
/* Do you really, really need this ? */
|
||||
glibtop_get_proc_uid_s (server, &procuid, pid);
|
||||
if (procuid.flags & (1L << GLIBTOP_PROC_UID_TTY))
|
||||
if ((int) arg != procuid.tty)
|
||||
continue;
|
||||
break;
|
||||
case GLIBTOP_KERN_PROC_RUID:
|
||||
/* Do you really, really need this ? */
|
||||
glibtop_get_proc_uid_s (server, &procuid, pid);
|
||||
if (procuid.flags & (1L << GLIBTOP_PROC_UID_EUID))
|
||||
if ((int) arg != procuid.euid)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
if (which & GLIBTOP_EXCLUDE_NOTTY) {
|
||||
glibtop_get_proc_uid_s (server, &procuid, pid);
|
||||
if (procuid.flags & (1L << GLIBTOP_PROC_UID_TTY))
|
||||
if (procuid.tty == -1) continue;
|
||||
}
|
||||
|
||||
if (which & GLIBTOP_EXCLUDE_IDLE) {
|
||||
glibtop_get_proc_state_s (server, &procstate, pid);
|
||||
if (procstate.flags & (1L << GLIBTOP_PROC_STATE_STATE))
|
||||
if (procstate.state != GLIBTOP_PROCESS_RUNNING) continue;
|
||||
}
|
||||
|
||||
if (which & GLIBTOP_EXCLUDE_SYSTEM) {
|
||||
glibtop_get_proc_uid_s (server, &procuid, pid);
|
||||
if (procuid.flags & (1L << GLIBTOP_PROC_UID_UID))
|
||||
if (procuid.uid == 0) continue;
|
||||
}
|
||||
|
||||
g_array_append_val(pids, pid);
|
||||
}
|
||||
|
||||
closedir (proc);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proclist;
|
||||
buf->size = sizeof(pid_t);
|
||||
buf->number = pids->len;
|
||||
buf->total = buf->number * buf->size;
|
||||
|
||||
return (pid_t*)g_array_free(pids, FALSE);
|
||||
}
|
||||
318
sysdeps/linux/procmap.c
Normal file
318
sysdeps/linux/procmap.c
Normal file
@@ -0,0 +1,318 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glib.h>
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procmap.h>
|
||||
|
||||
#include <linux/kdev_t.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
#include "procmap_smaps.c"
|
||||
|
||||
#define MAPS_FILE "/proc/%u/maps"
|
||||
#define SMAPS_FILE "/proc/%u/smaps"
|
||||
|
||||
|
||||
#define PROC_MAPS_FORMAT "%16" G_GINT64_MODIFIER "x-%16" G_GINT64_MODIFIER "x %4c %16" G_GINT64_MODIFIER "x %02hx:%02hx %" G_GINT64_MODIFIER "u%*[ ]%n"
|
||||
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_map =
|
||||
(1L << GLIBTOP_PROC_MAP_NUMBER) + (1L << GLIBTOP_PROC_MAP_TOTAL) +
|
||||
(1L << GLIBTOP_PROC_MAP_SIZE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_map_entry =
|
||||
(1L << GLIBTOP_MAP_ENTRY_START) + (1L << GLIBTOP_MAP_ENTRY_END) +
|
||||
(1L << GLIBTOP_MAP_ENTRY_OFFSET) + (1L << GLIBTOP_MAP_ENTRY_PERM) +
|
||||
(1L << GLIBTOP_MAP_ENTRY_INODE) + (1L << GLIBTOP_MAP_ENTRY_DEVICE) +
|
||||
(1L << GLIBTOP_MAP_ENTRY_FILENAME);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_map_entry_smaps =
|
||||
(1UL << GLIBTOP_MAP_ENTRY_SIZE) + (1UL << GLIBTOP_MAP_ENTRY_RSS) +
|
||||
(1UL << GLIBTOP_MAP_ENTRY_PSS) + (1UL << GLIBTOP_MAP_ENTRY_SWAP) +
|
||||
(1UL << GLIBTOP_MAP_ENTRY_SHARED_DIRTY) + (1UL << GLIBTOP_MAP_ENTRY_SHARED_CLEAN) +
|
||||
(1UL << GLIBTOP_MAP_ENTRY_PRIVATE_DIRTY) + (1UL << GLIBTOP_MAP_ENTRY_PRIVATE_CLEAN);
|
||||
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_proc_map_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
|
||||
static const char*
|
||||
is_smap_value(const char* s)
|
||||
{
|
||||
for ( ; *s; ++s) {
|
||||
|
||||
if (isspace(*s))
|
||||
return NULL;
|
||||
|
||||
if (*s == ':')
|
||||
return s;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Returns whether line is a 'value' line
|
||||
and add if we know its meaning
|
||||
*/
|
||||
static gboolean
|
||||
parse_smaps(glibtop_map_entry *entry, const char* line)
|
||||
{
|
||||
|
||||
const struct smap_value* smap;
|
||||
size_t len;
|
||||
const char* colon;
|
||||
|
||||
if ((colon = is_smap_value(line)) == NULL)
|
||||
return FALSE;
|
||||
|
||||
len = colon - line;
|
||||
smap = _glibtop_find_smap(line, len);
|
||||
|
||||
// g_debug("smap %s -> %p", line, smap);
|
||||
|
||||
if (smap) {
|
||||
char *offset;
|
||||
guint64 *value;
|
||||
|
||||
offset = (void*) entry;
|
||||
offset += smap->offset;
|
||||
value = (void*) offset;
|
||||
|
||||
*value = get_scaled(line + len, NULL);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
sscanf is too slow
|
||||
and system-monitor calls procmap for each pid every second
|
||||
|
||||
manual parsing is faster
|
||||
|
||||
error checking is weaker
|
||||
*/
|
||||
|
||||
static gboolean
|
||||
parse_line(char* line,
|
||||
guint64* start, guint64* end, char flags[4], guint64* offset,
|
||||
gushort* dev_major, gushort* dev_minor, guint64* inode,
|
||||
char** filename)
|
||||
{
|
||||
/* %16llx-%16llx %4c %16llx %02hx:%02hx %llu%*[ ]%n */
|
||||
|
||||
char *p, *next;
|
||||
|
||||
p = line;
|
||||
|
||||
*start = strtoull(p, &p, 16);
|
||||
|
||||
if (G_UNLIKELY(*p != '-'))
|
||||
return FALSE;
|
||||
p++;
|
||||
|
||||
*end = strtoull(p, &p, 16);
|
||||
|
||||
p = next_token(p);
|
||||
|
||||
memcpy(flags, p, 4);
|
||||
p += 4;
|
||||
|
||||
*offset = strtoull(p, &p, 16);
|
||||
|
||||
*dev_major = strtoul(p, &p, 16);
|
||||
|
||||
if (G_UNLIKELY(*p != ':'))
|
||||
return FALSE;
|
||||
p++;
|
||||
|
||||
*dev_minor = strtoul(p, &p, 16);
|
||||
|
||||
*inode = strtoull(p, &p, 10);
|
||||
|
||||
p = next_token(p);
|
||||
|
||||
*filename = p;
|
||||
|
||||
for ( ; *p; p++) {
|
||||
if (*p == '\n') {
|
||||
*p = '\0';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
glibtop_map_entry *
|
||||
glibtop_get_proc_map_s (glibtop *server, glibtop_proc_map *buf, pid_t pid)
|
||||
{
|
||||
char procfilename[GLIBTOP_MAP_FILENAME_LEN+1];
|
||||
|
||||
/*
|
||||
default size of 100 maybe inaccurate.
|
||||
It's the average number of entry per process on my laptop
|
||||
*/
|
||||
|
||||
size_t added = 0, entry_list_capacity = 100;
|
||||
GArray *entry_list = g_array_sized_new(FALSE, FALSE,
|
||||
sizeof(glibtop_map_entry),
|
||||
entry_list_capacity);
|
||||
FILE *maps;
|
||||
const char *filename;
|
||||
gboolean has_smaps;
|
||||
char *line = NULL;
|
||||
size_t line_size = 0;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_map));
|
||||
|
||||
has_smaps = server->os_version_code >= LINUX_VERSION_CODE(2, 6, 14);
|
||||
|
||||
if (has_smaps)
|
||||
filename = SMAPS_FILE;
|
||||
else
|
||||
filename = MAPS_FILE;
|
||||
|
||||
snprintf (procfilename, sizeof procfilename, filename, (unsigned)pid);
|
||||
|
||||
if((maps = fopen (procfilename, "r")) == NULL) {
|
||||
return (glibtop_map_entry*) g_array_free(entry_list, TRUE);
|
||||
}
|
||||
|
||||
while(TRUE)
|
||||
{
|
||||
unsigned long perm;
|
||||
/* int line_end; */
|
||||
|
||||
unsigned short dev_major, dev_minor;
|
||||
guint64 start, end, offset, inode;
|
||||
char flags[4];
|
||||
char *filename;
|
||||
|
||||
glibtop_map_entry *entry;
|
||||
|
||||
if (getline(&line, &line_size, maps) == -1)
|
||||
break;
|
||||
|
||||
new_entry_line:
|
||||
|
||||
if (!parse_line(line,
|
||||
&start, &end, flags, &offset,
|
||||
&dev_major, &dev_minor, &inode, &filename))
|
||||
continue;
|
||||
|
||||
/*
|
||||
if (sscanf(line, PROC_MAPS_FORMAT,
|
||||
&start, &end, flags, &offset,
|
||||
&dev_major, &dev_minor, &inode, &line_end) != 7)
|
||||
continue;
|
||||
|
||||
filename = line + line_end;
|
||||
g_strstrip(filename);
|
||||
*/
|
||||
|
||||
/* Compute access permissions. */
|
||||
perm = 0;
|
||||
|
||||
if (flags [0] == 'r')
|
||||
perm |= GLIBTOP_MAP_PERM_READ;
|
||||
|
||||
if (flags [1] == 'w')
|
||||
perm |= GLIBTOP_MAP_PERM_WRITE;
|
||||
|
||||
if (flags [2] == 'x')
|
||||
perm |= GLIBTOP_MAP_PERM_EXECUTE;
|
||||
|
||||
if (flags [3] == 's')
|
||||
perm |= GLIBTOP_MAP_PERM_SHARED;
|
||||
else if (flags [3] == 'p')
|
||||
perm |= GLIBTOP_MAP_PERM_PRIVATE;
|
||||
|
||||
/*
|
||||
avoid copying the entry, grow by 1 and point to the last
|
||||
element.
|
||||
*/
|
||||
|
||||
if (G_UNLIKELY(added >= entry_list_capacity)) {
|
||||
entry_list_capacity *= 2;
|
||||
g_array_set_size(entry_list, entry_list_capacity);
|
||||
}
|
||||
|
||||
entry = &g_array_index(entry_list, glibtop_map_entry, added++);
|
||||
|
||||
entry->flags = _glibtop_sysdeps_map_entry;
|
||||
entry->start = start;
|
||||
entry->end = end;
|
||||
entry->offset = offset;
|
||||
entry->perm = perm;
|
||||
entry->device = MKDEV(dev_major, dev_minor);
|
||||
entry->inode = inode;
|
||||
g_strlcpy(entry->filename, filename, sizeof entry->filename);
|
||||
|
||||
if (has_smaps) {
|
||||
ssize_t ret;
|
||||
entry->flags |= _glibtop_sysdeps_map_entry_smaps;
|
||||
|
||||
while ((ret = getline(&line, &line_size, maps)) != -1) {
|
||||
if (!parse_smaps(entry, line))
|
||||
goto new_entry_line;
|
||||
}
|
||||
|
||||
if (ret == -1)
|
||||
goto eof;
|
||||
}
|
||||
}
|
||||
|
||||
eof:
|
||||
|
||||
g_array_set_size(entry_list, added);
|
||||
free(line);
|
||||
fclose (maps);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_map;
|
||||
|
||||
buf->number = added;
|
||||
buf->size = sizeof (glibtop_map_entry);
|
||||
buf->total = buf->number * buf->size;
|
||||
|
||||
return (glibtop_map_entry*) g_array_free(entry_list, FALSE);
|
||||
}
|
||||
161
sysdeps/linux/procmap_smaps.c
Normal file
161
sysdeps/linux/procmap_smaps.c
Normal file
@@ -0,0 +1,161 @@
|
||||
/* ANSI-C code produced by gperf version 3.1 */
|
||||
/* Command-line: gperf sysdeps/linux/procmap_smaps.gperf */
|
||||
/* Computed positions: -k'1,$' */
|
||||
|
||||
#if !((' ' == 32) && ('!' == 33) && ('"' == 34) && ('#' == 35) \
|
||||
&& ('%' == 37) && ('&' == 38) && ('\'' == 39) && ('(' == 40) \
|
||||
&& (')' == 41) && ('*' == 42) && ('+' == 43) && (',' == 44) \
|
||||
&& ('-' == 45) && ('.' == 46) && ('/' == 47) && ('0' == 48) \
|
||||
&& ('1' == 49) && ('2' == 50) && ('3' == 51) && ('4' == 52) \
|
||||
&& ('5' == 53) && ('6' == 54) && ('7' == 55) && ('8' == 56) \
|
||||
&& ('9' == 57) && (':' == 58) && (';' == 59) && ('<' == 60) \
|
||||
&& ('=' == 61) && ('>' == 62) && ('?' == 63) && ('A' == 65) \
|
||||
&& ('B' == 66) && ('C' == 67) && ('D' == 68) && ('E' == 69) \
|
||||
&& ('F' == 70) && ('G' == 71) && ('H' == 72) && ('I' == 73) \
|
||||
&& ('J' == 74) && ('K' == 75) && ('L' == 76) && ('M' == 77) \
|
||||
&& ('N' == 78) && ('O' == 79) && ('P' == 80) && ('Q' == 81) \
|
||||
&& ('R' == 82) && ('S' == 83) && ('T' == 84) && ('U' == 85) \
|
||||
&& ('V' == 86) && ('W' == 87) && ('X' == 88) && ('Y' == 89) \
|
||||
&& ('Z' == 90) && ('[' == 91) && ('\\' == 92) && (']' == 93) \
|
||||
&& ('^' == 94) && ('_' == 95) && ('a' == 97) && ('b' == 98) \
|
||||
&& ('c' == 99) && ('d' == 100) && ('e' == 101) && ('f' == 102) \
|
||||
&& ('g' == 103) && ('h' == 104) && ('i' == 105) && ('j' == 106) \
|
||||
&& ('k' == 107) && ('l' == 108) && ('m' == 109) && ('n' == 110) \
|
||||
&& ('o' == 111) && ('p' == 112) && ('q' == 113) && ('r' == 114) \
|
||||
&& ('s' == 115) && ('t' == 116) && ('u' == 117) && ('v' == 118) \
|
||||
&& ('w' == 119) && ('x' == 120) && ('y' == 121) && ('z' == 122) \
|
||||
&& ('{' == 123) && ('|' == 124) && ('}' == 125) && ('~' == 126))
|
||||
/* The character set is not based on ISO-646. */
|
||||
#error "gperf generated tables don't work with this execution character set. Please report a bug to <bug-gperf@gnu.org>."
|
||||
#endif
|
||||
|
||||
#line 8 "sysdeps/linux/procmap_smaps.gperf"
|
||||
|
||||
#include "glibtop_private.h"
|
||||
#include <glibtop/procmap.h>
|
||||
#include <stddef.h>
|
||||
#define SMAP_OFFSET(MEMBER) offsetof(glibtop_map_entry, MEMBER)
|
||||
#line 14 "sysdeps/linux/procmap_smaps.gperf"
|
||||
struct smap_value { int name; ptrdiff_t offset; };
|
||||
#include <string.h>
|
||||
|
||||
#define TOTAL_KEYWORDS 8
|
||||
#define MIN_WORD_LENGTH 3
|
||||
#define MAX_WORD_LENGTH 13
|
||||
#define MIN_HASH_VALUE 3
|
||||
#define MAX_HASH_VALUE 18
|
||||
/* maximum key range = 16, duplicates = 0 */
|
||||
|
||||
#ifdef __GNUC__
|
||||
__inline
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
inline
|
||||
#endif
|
||||
#endif
|
||||
static unsigned int
|
||||
hash (register const char *str, register size_t len)
|
||||
{
|
||||
static const unsigned char asso_values[] =
|
||||
{
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
0, 19, 5, 0, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 5, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
5, 19, 0, 19, 19, 0, 19, 19, 19, 19,
|
||||
19, 0, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 19
|
||||
};
|
||||
return len + asso_values[(unsigned char)str[len - 1]] + asso_values[(unsigned char)str[0]];
|
||||
}
|
||||
|
||||
struct stringpool_t
|
||||
{
|
||||
char stringpool_str3[sizeof("Pss")];
|
||||
char stringpool_str4[sizeof("Swap")];
|
||||
char stringpool_str8[sizeof("Rss")];
|
||||
char stringpool_str9[sizeof("Size")];
|
||||
char stringpool_str12[sizeof("Shared_Dirty")];
|
||||
char stringpool_str13[sizeof("Private_Dirty")];
|
||||
char stringpool_str17[sizeof("Shared_Clean")];
|
||||
char stringpool_str18[sizeof("Private_Clean")];
|
||||
};
|
||||
static const struct stringpool_t stringpool_contents =
|
||||
{
|
||||
"Pss",
|
||||
"Swap",
|
||||
"Rss",
|
||||
"Size",
|
||||
"Shared_Dirty",
|
||||
"Private_Dirty",
|
||||
"Shared_Clean",
|
||||
"Private_Clean"
|
||||
};
|
||||
#define stringpool ((const char *) &stringpool_contents)
|
||||
static /* manually added */
|
||||
const struct smap_value *
|
||||
_glibtop_find_smap (register const char *str, register size_t len)
|
||||
{
|
||||
static const unsigned char lengthtable[] =
|
||||
{
|
||||
0, 0, 0, 3, 4, 0, 0, 0, 3, 4, 0, 0, 12, 13,
|
||||
0, 0, 0, 12, 13
|
||||
};
|
||||
static const struct smap_value wordlist[] =
|
||||
{
|
||||
{-1}, {-1}, {-1},
|
||||
#line 18 "sysdeps/linux/procmap_smaps.gperf"
|
||||
{(int)(size_t)&((struct stringpool_t *)0)->stringpool_str3, SMAP_OFFSET(pss)},
|
||||
#line 23 "sysdeps/linux/procmap_smaps.gperf"
|
||||
{(int)(size_t)&((struct stringpool_t *)0)->stringpool_str4, SMAP_OFFSET(swap),},
|
||||
{-1}, {-1}, {-1},
|
||||
#line 19 "sysdeps/linux/procmap_smaps.gperf"
|
||||
{(int)(size_t)&((struct stringpool_t *)0)->stringpool_str8, SMAP_OFFSET(rss)},
|
||||
#line 22 "sysdeps/linux/procmap_smaps.gperf"
|
||||
{(int)(size_t)&((struct stringpool_t *)0)->stringpool_str9, SMAP_OFFSET(size)},
|
||||
{-1}, {-1},
|
||||
#line 21 "sysdeps/linux/procmap_smaps.gperf"
|
||||
{(int)(size_t)&((struct stringpool_t *)0)->stringpool_str12, SMAP_OFFSET(shared_dirty)},
|
||||
#line 17 "sysdeps/linux/procmap_smaps.gperf"
|
||||
{(int)(size_t)&((struct stringpool_t *)0)->stringpool_str13, SMAP_OFFSET(private_dirty)},
|
||||
{-1}, {-1}, {-1},
|
||||
#line 20 "sysdeps/linux/procmap_smaps.gperf"
|
||||
{(int)(size_t)&((struct stringpool_t *)0)->stringpool_str17, SMAP_OFFSET(shared_clean)},
|
||||
#line 16 "sysdeps/linux/procmap_smaps.gperf"
|
||||
{(int)(size_t)&((struct stringpool_t *)0)->stringpool_str18, SMAP_OFFSET(private_clean)}
|
||||
};
|
||||
|
||||
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
|
||||
{
|
||||
register unsigned int key = hash (str, len);
|
||||
|
||||
if (key <= MAX_HASH_VALUE)
|
||||
if (len == lengthtable[key])
|
||||
{
|
||||
register const char *s = wordlist[key].name + stringpool;
|
||||
|
||||
if (*str == *s && !memcmp (str + 1, s + 1, len - 1))
|
||||
return &wordlist[key];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
23
sysdeps/linux/procmap_smaps.gperf
Normal file
23
sysdeps/linux/procmap_smaps.gperf
Normal file
@@ -0,0 +1,23 @@
|
||||
%language=ANSI-C
|
||||
%includes
|
||||
%struct-type
|
||||
%readonly-tables
|
||||
%pic
|
||||
%define lookup-function-name _glibtop_find_smap
|
||||
%compare-lengths
|
||||
%{
|
||||
#include "glibtop_private.h"
|
||||
#include <glibtop/procmap.h>
|
||||
#include <stddef.h>
|
||||
#define SMAP_OFFSET(MEMBER) offsetof(glibtop_map_entry, MEMBER)
|
||||
%}
|
||||
struct smap_value { int name; ptrdiff_t offset; };
|
||||
%%
|
||||
Private_Clean, SMAP_OFFSET(private_clean)
|
||||
Private_Dirty, SMAP_OFFSET(private_dirty)
|
||||
Pss, SMAP_OFFSET(pss)
|
||||
Rss, SMAP_OFFSET(rss)
|
||||
Shared_Clean, SMAP_OFFSET(shared_clean)
|
||||
Shared_Dirty, SMAP_OFFSET(shared_dirty)
|
||||
Size, SMAP_OFFSET(size)
|
||||
Swap, SMAP_OFFSET(swap),
|
||||
144
sysdeps/linux/procmem.c
Normal file
144
sysdeps/linux/procmem.c
Normal file
@@ -0,0 +1,144 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procmem.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_mem =
|
||||
(1L << GLIBTOP_PROC_MEM_SIZE) + (1L << GLIBTOP_PROC_MEM_RESIDENT) +
|
||||
(1L << GLIBTOP_PROC_MEM_SHARE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_mem_pss =
|
||||
(1L << GLIBTOP_PROC_MEM_RSS);
|
||||
|
||||
|
||||
static unsigned long
|
||||
get_pss(glibtop* server, pid_t pid)
|
||||
{
|
||||
char filepath[128];
|
||||
FILE* smaps;
|
||||
char* line = NULL;
|
||||
size_t line_size = 0;
|
||||
unsigned long pss = 0;
|
||||
|
||||
snprintf(filepath, sizeof filepath, "/proc/%u/smaps", (unsigned)pid);
|
||||
|
||||
if (!(smaps = fopen(filepath, "r"))) {
|
||||
glibtop_error_io_r(server, "Cannot open %s", filepath);
|
||||
goto out;
|
||||
}
|
||||
|
||||
while (getline(&line, &line_size, smaps) != -1) {
|
||||
if (strncmp(line, "Pss:", 4))
|
||||
continue;
|
||||
pss += get_scaled(line + 4, NULL);
|
||||
}
|
||||
|
||||
out:
|
||||
if (smaps)
|
||||
fclose(smaps);
|
||||
|
||||
free(line);
|
||||
|
||||
return pss;
|
||||
}
|
||||
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_proc_mem_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
|
||||
if (server->os_version_code >= LINUX_VERSION_CODE(2, 6, 25))
|
||||
server->sysdeps.proc_mem |= _glibtop_sysdeps_proc_mem_pss;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_mem_s (glibtop *server, glibtop_proc_mem *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
const size_t pagesize = getpagesize();
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_mem));
|
||||
|
||||
/* As of 2.6.24 in fs/proc/*.c
|
||||
|
||||
== rss vs. resident ==
|
||||
|
||||
stat/rss:
|
||||
get_mm_rss where
|
||||
#define get_mm_rss(mm) \
|
||||
(get_mm_counter(mm, file_rss) + get_mm_counter(mm, anon_rss))
|
||||
|
||||
statm/resident:
|
||||
*shared = get_mm_counter(mm, file_rss);
|
||||
*resident = *shared + get_mm_counter(mm, anon_rss);
|
||||
|
||||
== vsize vs. size ==
|
||||
|
||||
stat/vsize:
|
||||
task_vsize(mm) ... total_vm * pagesize
|
||||
|
||||
statm/size
|
||||
mm->total_vm
|
||||
|
||||
=================
|
||||
rss == resident
|
||||
vsize == size
|
||||
rss_lim is not implemented in statm, but there's limits which
|
||||
provides all limits
|
||||
share is only implemented in statm
|
||||
*/
|
||||
|
||||
if (proc_statm_to_buffer(buffer, sizeof buffer, pid))
|
||||
return;
|
||||
|
||||
buf->size = strtoull (buffer, &p, 0);
|
||||
buf->resident = strtoull (p, &p, 0);
|
||||
buf->share = strtoull (p, &p, 0);
|
||||
|
||||
buf->size *= pagesize;
|
||||
buf->resident *= pagesize;
|
||||
buf->share *= pagesize;
|
||||
|
||||
/* dummy values */
|
||||
buf->vsize = buf->size;
|
||||
buf->rss_rlim = ~0;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_mem;
|
||||
|
||||
#if 0
|
||||
/* FIXME: see previous comment */
|
||||
if (server->os_version_code >= LINUX_VERSION_CODE(2, 6, 25)) {
|
||||
buf->rss = get_pss(server, pid);
|
||||
buf->flags |= _glibtop_sysdeps_proc_mem_pss;
|
||||
}
|
||||
#else
|
||||
buf->rss = buf->resident;
|
||||
#endif
|
||||
}
|
||||
324
sysdeps/linux/procopenfiles.c
Normal file
324
sysdeps/linux/procopenfiles.c
Normal file
@@ -0,0 +1,324 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
Copyright (C) 2004 Nicolás Lichtmaier
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Modified by Nicolás Lichtmaier to give a process open files.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procopenfiles.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_open_files =
|
||||
(1L << GLIBTOP_PROC_OPEN_FILES_NUMBER)|
|
||||
(1L << GLIBTOP_PROC_OPEN_FILES_TOTAL)|
|
||||
(1L << GLIBTOP_PROC_OPEN_FILES_SIZE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_proc_open_files_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_open_files = _glibtop_sysdeps_proc_open_files;
|
||||
}
|
||||
|
||||
|
||||
|
||||
typedef void (*LineParser)(GHashTable *dict, const char *line);
|
||||
|
||||
|
||||
static void
|
||||
parse_file(const char *filename, LineParser parser, GHashTable *dict)
|
||||
{
|
||||
FILE *f;
|
||||
char *line = NULL;
|
||||
size_t size = 0;
|
||||
|
||||
f = fopen(filename, "r");
|
||||
|
||||
if(!f) {
|
||||
g_warning("Cannot open '%s'", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/* skip the first line */
|
||||
if (getline(&line, &size, f) == -1)
|
||||
goto eof;
|
||||
|
||||
while (getline(&line, &size, f) != -1)
|
||||
parser(dict, line);
|
||||
|
||||
eof:
|
||||
free(line);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
|
||||
static GHashTable*
|
||||
get_all(const char *filename, LineParser parser)
|
||||
{
|
||||
GHashTable *dict;
|
||||
|
||||
dict = g_hash_table_new_full(g_direct_hash, g_direct_equal,
|
||||
NULL, g_free);
|
||||
|
||||
parse_file(filename, parser, dict);
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct Inet6SocketEntry
|
||||
{
|
||||
char host[GLIBTOP_OPEN_DEST_HOST_LEN + 1];
|
||||
int port;
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
inet6_socket_parser(GHashTable *dict, const char* line)
|
||||
{
|
||||
struct Inet6SocketEntry *se;
|
||||
int sock;
|
||||
struct in6_addr addr;
|
||||
|
||||
se = g_malloc0(sizeof *se);
|
||||
|
||||
if(sscanf(line, "%*d: %*s %8x%8x%8x%8x:%4x %*x %*x:%*x %*x:%*x %*d %*d %*d %d",
|
||||
&addr.s6_addr32[0], &addr.s6_addr32[1], &addr.s6_addr32[2],
|
||||
&addr.s6_addr32[3], &se->port, &sock) != 6)
|
||||
goto error;
|
||||
|
||||
if(!inet_ntop(AF_INET6, &addr, se->host, sizeof se->host))
|
||||
goto error;
|
||||
|
||||
g_hash_table_insert(dict, GINT_TO_POINTER(sock), se);
|
||||
return;
|
||||
|
||||
error:
|
||||
g_free(se);
|
||||
}
|
||||
|
||||
|
||||
static inline GHashTable *
|
||||
get_all_inet6_sockets()
|
||||
{
|
||||
return get_all("/proc/net/tcp6", inet6_socket_parser);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct InetSocketEntry
|
||||
{
|
||||
char host[GLIBTOP_OPEN_DEST_HOST_LEN + 1];
|
||||
int port;
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
inet_socket_parser(GHashTable *dict, const char* line)
|
||||
{
|
||||
struct InetSocketEntry *se;
|
||||
int sock;
|
||||
unsigned addr;
|
||||
|
||||
se = g_malloc0(sizeof *se);
|
||||
|
||||
if(sscanf(line, "%*d: %*x:%*x %8x:%4x %*x %*x:%*x %*x:%*x %*d %*d %*d %d",
|
||||
&addr, &se->port, &sock) != 3)
|
||||
goto error;
|
||||
|
||||
if(!inet_ntop(AF_INET, &addr, se->host, sizeof se->host))
|
||||
goto error;
|
||||
|
||||
g_hash_table_insert(dict, GINT_TO_POINTER(sock), se);
|
||||
return;
|
||||
|
||||
error:
|
||||
g_free(se);
|
||||
}
|
||||
|
||||
|
||||
static inline GHashTable *
|
||||
get_all_inet_sockets()
|
||||
{
|
||||
return get_all("/proc/net/tcp", inet_socket_parser);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct LocalSocketEntry
|
||||
{
|
||||
char name[GLIBTOP_OPEN_DEST_HOST_LEN + 1];
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
local_socket_parser(GHashTable *dict, const char *line)
|
||||
{
|
||||
int sock;
|
||||
struct LocalSocketEntry *use;
|
||||
char *p;
|
||||
|
||||
use = g_malloc0(sizeof *use);
|
||||
|
||||
/* dfaf1640: 00000003 00000000 00000000 0001 03 6457 /dev/log */
|
||||
p = skip_multiple_token(line, 6);
|
||||
|
||||
sock = strtoul(p, &p, 10);
|
||||
g_strlcpy(use->name, p, sizeof use->name);
|
||||
g_strstrip(use->name);
|
||||
g_hash_table_insert(dict, GINT_TO_POINTER(sock), use);
|
||||
}
|
||||
|
||||
|
||||
static inline GHashTable *
|
||||
get_all_local_sockets()
|
||||
{
|
||||
return get_all("/proc/net/unix", local_socket_parser);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Provides detailed information about a process' open files */
|
||||
|
||||
glibtop_open_files_entry *
|
||||
glibtop_get_proc_open_files_s (glibtop *server, glibtop_proc_open_files *buf, pid_t pid)
|
||||
{
|
||||
char fn [BUFSIZ];
|
||||
GArray *entries;
|
||||
GHashTable *inet6_sockets = NULL, *inet_sockets = NULL, *local_sockets = NULL;
|
||||
struct dirent *direntry;
|
||||
DIR *dir;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_open_files));
|
||||
|
||||
sprintf (fn, "/proc/%d/fd", pid);
|
||||
|
||||
dir = opendir (fn);
|
||||
if (!dir) return NULL;
|
||||
|
||||
entries = g_array_new(FALSE, FALSE, sizeof(glibtop_open_files_entry));
|
||||
|
||||
while((direntry = readdir(dir))) {
|
||||
char tgt [BUFSIZ];
|
||||
glibtop_open_files_entry entry = {0};
|
||||
|
||||
if(direntry->d_name[0] == '.')
|
||||
continue;
|
||||
|
||||
g_snprintf(fn, sizeof fn, "/proc/%d/fd/%s",
|
||||
pid, direntry->d_name);
|
||||
|
||||
if (!safe_readlink(fn, tgt, sizeof tgt))
|
||||
continue;
|
||||
|
||||
entry.fd = atoi(direntry->d_name);
|
||||
|
||||
if(g_str_has_prefix(tgt, "socket:["))
|
||||
{
|
||||
int sockfd;
|
||||
struct Inet6SocketEntry *i6se;
|
||||
struct InetSocketEntry *ise;
|
||||
struct LocalSocketEntry *lse;
|
||||
|
||||
if(!inet6_sockets) inet6_sockets = get_all_inet6_sockets();
|
||||
if(!inet_sockets) inet_sockets = get_all_inet_sockets();
|
||||
if(!local_sockets) local_sockets = get_all_local_sockets();
|
||||
|
||||
sockfd = atoi(tgt + 8);
|
||||
|
||||
i6se = g_hash_table_lookup(inet6_sockets,
|
||||
GINT_TO_POINTER(sockfd));
|
||||
|
||||
if(i6se) {
|
||||
entry.type = GLIBTOP_FILE_TYPE_INET6SOCKET;
|
||||
entry.info.sock.dest_port = i6se->port;
|
||||
g_strlcpy(entry.info.sock.dest_host, i6se->host,
|
||||
sizeof entry.info.sock.dest_host);
|
||||
goto found;
|
||||
}
|
||||
|
||||
ise = g_hash_table_lookup(inet_sockets,
|
||||
GINT_TO_POINTER(sockfd));
|
||||
|
||||
if(ise) {
|
||||
entry.type = GLIBTOP_FILE_TYPE_INETSOCKET;
|
||||
entry.info.sock.dest_port = ise->port;
|
||||
g_strlcpy(entry.info.sock.dest_host, ise->host,
|
||||
sizeof entry.info.sock.dest_host);
|
||||
goto found;
|
||||
}
|
||||
|
||||
lse = g_hash_table_lookup(local_sockets,
|
||||
GINT_TO_POINTER(sockfd));
|
||||
|
||||
if(lse) {
|
||||
entry.type = GLIBTOP_FILE_TYPE_LOCALSOCKET;
|
||||
g_strlcpy(entry.info.localsock.name, lse->name,
|
||||
sizeof entry.info.localsock.name);
|
||||
goto found;
|
||||
}
|
||||
|
||||
found:
|
||||
(void)0; /* kills warning */
|
||||
}
|
||||
else if(g_str_has_prefix(tgt, "pipe:["))
|
||||
{
|
||||
entry.type = GLIBTOP_FILE_TYPE_PIPE;
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.type = GLIBTOP_FILE_TYPE_FILE;
|
||||
g_strlcpy(entry.info.file.name, tgt, sizeof entry.info.file.name);
|
||||
}
|
||||
|
||||
g_array_append_val(entries, entry);
|
||||
}
|
||||
|
||||
closedir (dir);
|
||||
|
||||
if(inet_sockets) g_hash_table_destroy(inet_sockets);
|
||||
if(inet6_sockets) g_hash_table_destroy(inet6_sockets);
|
||||
if(local_sockets) g_hash_table_destroy(local_sockets);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_open_files;
|
||||
buf->number = entries->len;
|
||||
buf->size = sizeof(glibtop_open_files_entry);
|
||||
buf->total = buf->number * buf->size;
|
||||
|
||||
return (glibtop_open_files_entry*)g_array_free(entries, FALSE);
|
||||
}
|
||||
93
sysdeps/linux/procsegment.c
Normal file
93
sysdeps/linux/procsegment.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procsegment.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_segment =
|
||||
(1L << GLIBTOP_PROC_SEGMENT_START_CODE) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_END_CODE) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_START_STACK);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_segment_statm =
|
||||
(1L << GLIBTOP_PROC_SEGMENT_TEXT_RSS) +
|
||||
/* Disabled due to bug in the Linux Kernel. */
|
||||
/* (1L << GLIBTOP_PROC_SEGMENT_SHLIB_RSS) + */
|
||||
(1L << GLIBTOP_PROC_SEGMENT_DATA_RSS) +
|
||||
(1L << GLIBTOP_PROC_SEGMENT_DIRTY_SIZE);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_proc_segment_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment |
|
||||
_glibtop_sysdeps_proc_segment_statm;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_segment_s (glibtop *server, glibtop_proc_segment *buf,
|
||||
pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
const size_t pagesize = getpagesize();
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_segment));
|
||||
|
||||
if (proc_stat_to_buffer(buffer, sizeof buffer, pid))
|
||||
return;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return;
|
||||
|
||||
p = skip_multiple_token (p, 23);
|
||||
|
||||
buf->start_code = strtoull (p, &p, 0);
|
||||
buf->end_code = strtoull (p, &p, 0);
|
||||
buf->start_stack = strtoull (p, &p, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_segment;
|
||||
|
||||
if (proc_statm_to_buffer(buffer, sizeof buffer, pid))
|
||||
return;
|
||||
|
||||
p = skip_multiple_token (buffer, 3);
|
||||
|
||||
/* This doesn't work very well due to a bug in the Linux kernel.
|
||||
* I'll submit a patch to the kernel mailing list soon. */
|
||||
|
||||
buf->text_rss = strtoull (p, &p, 0);
|
||||
buf->shlib_rss = strtoull (p, &p, 0);
|
||||
buf->data_rss = strtoull (p, &p, 0);
|
||||
buf->dirty_size = strtoull (p, &p, 0);
|
||||
|
||||
buf->text_rss *= pagesize;
|
||||
buf->shlib_rss *= pagesize;
|
||||
buf->data_rss *= pagesize;
|
||||
buf->dirty_size *= pagesize;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_segment_statm;
|
||||
}
|
||||
64
sysdeps/linux/procsignal.c
Normal file
64
sysdeps/linux/procsignal.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procsignal.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_signal =
|
||||
(1L << GLIBTOP_PROC_SIGNAL_SIGNAL) + (1L << GLIBTOP_PROC_SIGNAL_BLOCKED) +
|
||||
(1L << GLIBTOP_PROC_SIGNAL_SIGIGNORE) + (1L << GLIBTOP_PROC_SIGNAL_SIGCATCH);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_proc_signal_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_signal_s (glibtop *server, glibtop_proc_signal *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_signal));
|
||||
|
||||
if (proc_stat_to_buffer(buffer, sizeof buffer, pid))
|
||||
return;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return;
|
||||
|
||||
p = skip_multiple_token (p, 28);
|
||||
|
||||
buf->signal [0] = strtoull (p, &p, 0);
|
||||
buf->blocked [0] = strtoull (p, &p, 0);
|
||||
buf->sigignore [0] = strtoull (p, &p, 0);
|
||||
buf->sigcatch [0] = strtoull (p, &p, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_signal;
|
||||
}
|
||||
123
sysdeps/linux/procstate.c
Normal file
123
sysdeps/linux/procstate.c
Normal file
@@ -0,0 +1,123 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procstate.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_state =
|
||||
(1L << GLIBTOP_PROC_STATE_CMD) + (1L << GLIBTOP_PROC_STATE_STATE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_state_uid =
|
||||
(1L << GLIBTOP_PROC_STATE_UID) + (1L << GLIBTOP_PROC_STATE_GID);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_proc_state_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state |
|
||||
_glibtop_sysdeps_proc_state_uid;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_state_s (glibtop *server, glibtop_proc_state *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
struct stat statb;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_state));
|
||||
|
||||
/* IMPORTANT NOTICE: For security reasons it is extremely important
|
||||
* that the 'uid' and 'gid' fields have correct
|
||||
* values; NEVER set their flags values if this
|
||||
* is not the case !!! */
|
||||
|
||||
sprintf (buffer, "/proc/%d", pid);
|
||||
|
||||
if (stat (buffer, &statb))
|
||||
return;
|
||||
|
||||
/* For security reasons we use stat () since it is
|
||||
* more failsafe than parsing the file. */
|
||||
|
||||
buf->uid = statb.st_uid;
|
||||
buf->gid = statb.st_gid;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_state_uid;
|
||||
|
||||
/* Now we read the remaining fields. */
|
||||
|
||||
if (proc_stat_to_buffer(buffer, sizeof buffer, pid))
|
||||
return;
|
||||
|
||||
p = proc_stat_after_cmd(buffer);
|
||||
p = next_token(p);
|
||||
|
||||
switch(*p)
|
||||
{
|
||||
case 'R':
|
||||
buf->state = GLIBTOP_PROCESS_RUNNING;
|
||||
break;
|
||||
|
||||
case 'Z':
|
||||
buf->state = GLIBTOP_PROCESS_ZOMBIE;
|
||||
break;
|
||||
|
||||
case 'S':
|
||||
buf->state = GLIBTOP_PROCESS_INTERRUPTIBLE;
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
buf->state = GLIBTOP_PROCESS_STOPPED;
|
||||
break;
|
||||
|
||||
case 'D':
|
||||
buf->state = GLIBTOP_PROCESS_UNINTERRUPTIBLE;
|
||||
break;
|
||||
|
||||
case 'W':
|
||||
buf->state = GLIBTOP_PROCESS_SWAPPING;
|
||||
break;
|
||||
|
||||
case 'X':
|
||||
buf->state = GLIBTOP_PROCESS_DEAD;
|
||||
break;
|
||||
}
|
||||
|
||||
p = skip_multiple_token (p, 36);
|
||||
buf->last_processor = atoi (p);
|
||||
|
||||
p = skip_token (buffer); /* pid */
|
||||
if (G_UNLIKELY(*p++ != '('))
|
||||
glibtop_error_r (server, "Bad data in /proc/%d/stat", pid);
|
||||
|
||||
g_strlcpy (buf->cmd, p, sizeof buf->cmd);
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_state;
|
||||
}
|
||||
132
sysdeps/linux/proctime.c
Normal file
132
sysdeps/linux/proctime.c
Normal file
@@ -0,0 +1,132 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/proctime.h>
|
||||
#include <glibtop/uptime.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_time =
|
||||
(1L << GLIBTOP_PROC_TIME_UTIME) + (1L << GLIBTOP_PROC_TIME_CUTIME) +
|
||||
(1L << GLIBTOP_PROC_TIME_RTIME) +
|
||||
(1L << GLIBTOP_PROC_TIME_STIME) + (1L << GLIBTOP_PROC_TIME_CSTIME) +
|
||||
(1L << GLIBTOP_PROC_TIME_FREQUENCY) + (1L << GLIBTOP_PROC_TIME_TIMEOUT) +
|
||||
(1L << GLIBTOP_PROC_TIME_IT_REAL_VALUE) + (1L << GLIBTOP_PROC_TIME_START_TIME);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_time_smp =
|
||||
(1L << GLIBTOP_PROC_TIME_XCPU_UTIME) + (1L << GLIBTOP_PROC_TIME_XCPU_STIME);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_proc_time_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
|
||||
|
||||
if (server->ncpu)
|
||||
server->sysdeps.proc_time |= _glibtop_sysdeps_proc_time_smp;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_time_s (glibtop *server, glibtop_proc_time *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
int i;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_time));
|
||||
|
||||
if (proc_stat_to_buffer(buffer, sizeof buffer, pid))
|
||||
return;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return;
|
||||
|
||||
p = skip_multiple_token (p, 11);
|
||||
|
||||
/* clock_t (1/100 s) */
|
||||
buf->utime = strtoull (p, &p, 0);
|
||||
buf->stime = strtoull (p, &p, 0);
|
||||
buf->rtime = buf->utime + buf->stime;
|
||||
|
||||
buf->cutime = strtoull (p, &p, 0);
|
||||
buf->cstime = strtoull (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, 3);
|
||||
|
||||
/* timeout is 0 on 2.4 and "thread_number" on 2.6
|
||||
lets skip it (using previous skip_multiple_token)
|
||||
buf->timeout = strtoull (p, &p, 0);
|
||||
*/
|
||||
buf->it_real_value = strtoull (p, &p, 0);
|
||||
|
||||
/* seconds since epoch */
|
||||
{
|
||||
/*
|
||||
See libgtop documentation.
|
||||
|
||||
#ifdef __KERNEL__
|
||||
...
|
||||
*
|
||||
* Have the 32 bit jiffies value wrap 5 minutes after boot
|
||||
* so jiffies wrap bugs show up earlier.
|
||||
*
|
||||
#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
|
||||
...
|
||||
#endif
|
||||
|
||||
start_time may be incremented by INITIAL_JIFFIES, so start_time
|
||||
may be not be exact. You may also get wrong start_time if your
|
||||
system clock is not synchronised with you hardware clock.
|
||||
'man hwclock'
|
||||
*/
|
||||
buf->start_time = get_boot_time(server) + strtoull (p, &p, 0) / 100;
|
||||
}
|
||||
|
||||
buf->frequency = 100;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_time;
|
||||
|
||||
if (!server->ncpu)
|
||||
return;
|
||||
|
||||
/* FIXME: doesn't work with 2.6 */
|
||||
if (proc_file_to_buffer(buffer, sizeof buffer, "/proc/%d/cpu", pid))
|
||||
return;
|
||||
|
||||
p = skip_multiple_token (p, 3);
|
||||
|
||||
for (i = 0; i <= server->ncpu; i++) {
|
||||
|
||||
if (!check_cpu_line_warn(server, p + 1, i))
|
||||
break;
|
||||
|
||||
p = skip_token(p);
|
||||
buf->xcpu_utime [i] = strtoull (p, &p, 0);
|
||||
buf->xcpu_stime [i] = strtoull (p, &p, 0);
|
||||
}
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_time_smp;
|
||||
}
|
||||
124
sysdeps/linux/procuid.c
Normal file
124
sysdeps/linux/procuid.c
Normal file
@@ -0,0 +1,124 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/procuid.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_uid =
|
||||
(1L << GLIBTOP_PROC_UID_UID) + (1L << GLIBTOP_PROC_UID_EUID) +
|
||||
(1L << GLIBTOP_PROC_UID_GID) + (1L << GLIBTOP_PROC_UID_EGID);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_proc_uid_stat =
|
||||
(1L << GLIBTOP_PROC_UID_PID) + (1L << GLIBTOP_PROC_UID_PPID) +
|
||||
(1L << GLIBTOP_PROC_UID_PGRP) + (1L << GLIBTOP_PROC_UID_SESSION) +
|
||||
(1L << GLIBTOP_PROC_UID_TTY) + (1L << GLIBTOP_PROC_UID_TPGID) +
|
||||
(1L << GLIBTOP_PROC_UID_PRIORITY) + (1L << GLIBTOP_PROC_UID_NICE);
|
||||
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_proc_uid_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid |
|
||||
_glibtop_sysdeps_proc_uid_stat;
|
||||
}
|
||||
|
||||
/* Provides detailed information about a process. */
|
||||
|
||||
void
|
||||
glibtop_get_proc_uid_s (glibtop *server, glibtop_proc_uid *buf, pid_t pid)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_proc_uid));
|
||||
|
||||
if (proc_status_to_buffer(buffer, sizeof buffer, pid))
|
||||
return;
|
||||
|
||||
/* Search substring 'Pid:' */
|
||||
|
||||
p = strstr (buffer, "\nPid:");
|
||||
if (!p) return;
|
||||
|
||||
p = skip_token (p); /* "Pid:" */
|
||||
buf->pid = strtol (p, &p, 0);
|
||||
|
||||
p = skip_token (p); /* "PPid:" */
|
||||
buf->ppid = strtol (p, &p, 0);
|
||||
|
||||
/* Maybe future Linux versions place something between
|
||||
* "PPid" and "Uid", so we catch this here. */
|
||||
p = strstr (p, "\nUid:");
|
||||
if (!p) return;
|
||||
|
||||
p = skip_token (p); /* "Uid:" */
|
||||
buf->uid = strtol (p, &p, 0);
|
||||
buf->euid = strtol (p, &p, 0);
|
||||
|
||||
/* We don't know how many entries on the "Uid:" line
|
||||
* future Linux version will have, so we catch this here. */
|
||||
p = strstr (p, "\nGid:");
|
||||
if (!p) return;
|
||||
|
||||
p = skip_token (p); /* "Gid:" */
|
||||
buf->gid = strtol (p, &p, 0);
|
||||
buf->egid = strtol (p, &p, 0);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_proc_uid;
|
||||
|
||||
if (proc_stat_to_buffer(buffer, sizeof buffer, pid))
|
||||
return;
|
||||
|
||||
p = proc_stat_after_cmd (buffer);
|
||||
if (!p) return;
|
||||
|
||||
p = skip_multiple_token (p, 2);
|
||||
|
||||
buf->pgrp = strtol (p, &p, 0);
|
||||
buf->session = strtol (p, &p, 0);
|
||||
buf->tty = strtol (p, &p, 0);
|
||||
buf->tpgid = strtol (p, &p, 0);
|
||||
|
||||
p = skip_multiple_token (p, 9);
|
||||
|
||||
buf->priority = strtol (p, &p, 0);
|
||||
buf->nice = strtol (p, &p, 0);
|
||||
|
||||
if (buf->tty == 0)
|
||||
/* the old notty val, update elsewhere bef. moving to 0 */
|
||||
buf->tty = -1;
|
||||
|
||||
if (server->os_version_code < LINUX_VERSION_CODE(1,3,39)) {
|
||||
/* map old meanings to new */
|
||||
buf->priority = 2*15 - buf->priority;
|
||||
buf->nice = 15 - buf->nice;
|
||||
}
|
||||
else if (server->os_version_code < LINUX_VERSION_CODE(1,1,30) && buf->tty != -1)
|
||||
/* when tty wasn't full devno */
|
||||
buf->tty = 4*0x100 + buf->tty;
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_proc_uid_stat;
|
||||
}
|
||||
99
sysdeps/linux/procwd.c
Normal file
99
sysdeps/linux/procwd.c
Normal file
@@ -0,0 +1,99 @@
|
||||
/* Copyright (C) 2007 Benoît Dejean
|
||||
This file is part of LibGTop 2.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/procwd.h>
|
||||
#include <glibtop/error.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
void
|
||||
_glibtop_init_proc_wd_s(glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_wd =
|
||||
(1 << GLIBTOP_PROC_WD_EXE) +
|
||||
(1 << GLIBTOP_PROC_WD_ROOT) +
|
||||
(1 << GLIBTOP_PROC_WD_NUMBER);
|
||||
|
||||
}
|
||||
|
||||
static gboolean is_in(GPtrArray *array, const char *str)
|
||||
{
|
||||
guint i;
|
||||
|
||||
for (i = 0; i != array->len; ++i) {
|
||||
if (strcmp(g_ptr_array_index(array, i), str) == 0)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
char**
|
||||
glibtop_get_proc_wd_s(glibtop *server, glibtop_proc_wd *buf, pid_t pid)
|
||||
{
|
||||
GPtrArray *dirs;
|
||||
char path[80];
|
||||
char dir[256];
|
||||
DIR *task;
|
||||
|
||||
memset(buf, 0, sizeof(glibtop_proc_wd));
|
||||
|
||||
g_snprintf(path, sizeof path, "/proc/%u/root", pid);
|
||||
if (safe_readlink(path, buf->root, sizeof buf->root))
|
||||
buf->flags |= (1 << GLIBTOP_PROC_WD_ROOT);
|
||||
|
||||
g_snprintf(path, sizeof path, "/proc/%u/exe", pid);
|
||||
if (safe_readlink(path, buf->exe, sizeof buf->exe))
|
||||
buf->flags |= (1 << GLIBTOP_PROC_WD_EXE);
|
||||
|
||||
dirs = g_ptr_array_sized_new(2);
|
||||
|
||||
g_snprintf(path, sizeof path, "/proc/%u/cwd", pid);
|
||||
if (safe_readlink(path, dir, sizeof dir))
|
||||
g_ptr_array_add(dirs, g_strdup(dir));
|
||||
|
||||
g_snprintf(path, sizeof path, "/proc/%u/task", pid);
|
||||
if ((task = opendir(path)) != NULL) {
|
||||
struct dirent *sub;
|
||||
while ((sub = readdir(task)) != NULL) {
|
||||
/* task dirs have numeric name */
|
||||
if (!isdigit(sub->d_name[0]))
|
||||
continue;
|
||||
g_snprintf(path, sizeof path, "/proc/%u/task/%s/cwd", pid, sub->d_name);
|
||||
if (safe_readlink(path, dir, sizeof dir) && !is_in(dirs, dir))
|
||||
g_ptr_array_add(dirs, g_strdup(dir));
|
||||
}
|
||||
closedir(task);
|
||||
}
|
||||
|
||||
buf->number = dirs->len;
|
||||
buf->flags |= (1 << GLIBTOP_PROC_WD_NUMBER);
|
||||
|
||||
g_ptr_array_add(dirs, NULL);
|
||||
|
||||
return (char**) g_ptr_array_free(dirs, FALSE);
|
||||
}
|
||||
|
||||
83
sysdeps/linux/sem_limits.c
Normal file
83
sysdeps/linux/sem_limits.c
Normal file
@@ -0,0 +1,83 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/sem_limits.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
|
||||
#ifdef _SEM_SEMUN_UNDEFINED
|
||||
|
||||
/* glibc 2.1 will no longer defines semun, instead it defines
|
||||
* _SEM_SEMUN_UNDEFINED so users can define semun on their own.
|
||||
* Thanks to Albert K T Hui <avatar@deva.net>. */
|
||||
|
||||
union semun
|
||||
{
|
||||
int val;
|
||||
struct semid_ds *buf;
|
||||
unsigned short int *array;
|
||||
struct seminfo *__buf;
|
||||
};
|
||||
#endif
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_sem_limits =
|
||||
(1L << GLIBTOP_IPC_SEMMAP) + (1L << GLIBTOP_IPC_SEMMNI) +
|
||||
(1L << GLIBTOP_IPC_SEMMNS) + (1L << GLIBTOP_IPC_SEMMNU) +
|
||||
(1L << GLIBTOP_IPC_SEMMSL) + (1L << GLIBTOP_IPC_SEMOPM) +
|
||||
(1L << GLIBTOP_IPC_SEMUME) + (1L << GLIBTOP_IPC_SEMUSZ) +
|
||||
(1L << GLIBTOP_IPC_SEMVMX) + (1L << GLIBTOP_IPC_SEMAEM);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_sem_limits_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
|
||||
}
|
||||
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
void
|
||||
glibtop_get_sem_limits_s (glibtop *server, glibtop_sem_limits *buf)
|
||||
{
|
||||
struct seminfo seminfo;
|
||||
union semun arg;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_sem_limits));
|
||||
|
||||
buf->flags = _glibtop_sysdeps_sem_limits;
|
||||
|
||||
arg.array = (void *) &seminfo;
|
||||
semctl (0, 0, IPC_INFO, arg);
|
||||
|
||||
buf->semmap = seminfo.semmap;
|
||||
buf->semmni = seminfo.semmni;
|
||||
buf->semmns = seminfo.semmns;
|
||||
buf->semmnu = seminfo.semmnu;
|
||||
buf->semmsl = seminfo.semmsl;
|
||||
buf->semopm = seminfo.semopm;
|
||||
buf->semume = seminfo.semume;
|
||||
buf->semusz = seminfo.semusz;
|
||||
buf->semvmx = seminfo.semvmx;
|
||||
buf->semaem = seminfo.semaem;
|
||||
}
|
||||
58
sysdeps/linux/shm_limits.c
Normal file
58
sysdeps/linux/shm_limits.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/shm_limits.h>
|
||||
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_shm_limits =
|
||||
(1L << GLIBTOP_IPC_SHMMAX) + (1L << GLIBTOP_IPC_SHMMIN) +
|
||||
(1L << GLIBTOP_IPC_SHMMNI) + (1L << GLIBTOP_IPC_SHMSEG) +
|
||||
(1L << GLIBTOP_IPC_SHMALL);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_shm_limits_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
|
||||
}
|
||||
|
||||
/* Provides information about sysv ipc limits. */
|
||||
|
||||
void
|
||||
glibtop_get_shm_limits_s (glibtop *server, glibtop_shm_limits *buf)
|
||||
{
|
||||
struct shminfo shminfo;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_shm_limits));
|
||||
|
||||
shmctl (0, IPC_INFO, (void *) &shminfo);
|
||||
|
||||
buf->shmmax = shminfo.shmmax;
|
||||
buf->shmmin = shminfo.shmmin;
|
||||
buf->shmmni = shminfo.shmmni;
|
||||
buf->shmseg = shminfo.shmseg;
|
||||
buf->shmall = shminfo.shmall;
|
||||
buf->flags = _glibtop_sysdeps_shm_limits;
|
||||
}
|
||||
143
sysdeps/linux/siglist.c
Normal file
143
sysdeps/linux/siglist.c
Normal file
@@ -0,0 +1,143 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/signal.h>
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
#if 0 /* comment */
|
||||
perl -nle 'print "{$1,\t\"$1\",\t\"$2\"}," if m|^#define\s*(SIG[A-Z0-9]+).*?/\*\s*(.*?)\s*\*/|'
|
||||
< /usr/include/bits/signum.h
|
||||
#endif
|
||||
|
||||
|
||||
const glibtop_signame glibtop_sys_siglist [] =
|
||||
{
|
||||
#ifdef SIGHUP
|
||||
{SIGHUP, "SIGHUP", "Hangup (POSIX)."},
|
||||
#endif
|
||||
#ifdef SIGINT
|
||||
{SIGINT, "SIGINT", "Interrupt (ANSI)."},
|
||||
#endif
|
||||
#ifdef SIGQUIT
|
||||
{SIGQUIT, "SIGQUIT", "Quit (POSIX)."},
|
||||
#endif
|
||||
#ifdef SIGILL
|
||||
{SIGILL, "SIGILL", "Illegal instruction (ANSI)."},
|
||||
#endif
|
||||
#ifdef SIGTRAP
|
||||
{SIGTRAP, "SIGTRAP", "Trace trap (POSIX)."},
|
||||
#endif
|
||||
#ifdef SIGABRT
|
||||
{SIGABRT, "SIGABRT", "Abort (ANSI)."},
|
||||
#endif
|
||||
#ifdef SIGIOT
|
||||
{SIGIOT, "SIGIOT", "IOT trap (4.2 BSD)."},
|
||||
#endif
|
||||
#ifdef SIGBUS
|
||||
{SIGBUS, "SIGBUS", "BUS error (4.2 BSD)."},
|
||||
#endif
|
||||
#ifdef SIGFPE
|
||||
{SIGFPE, "SIGFPE", "Floating-point exception (ANSI)."},
|
||||
#endif
|
||||
#ifdef SIGKILL
|
||||
{SIGKILL, "SIGKILL", "Kill, unblockable (POSIX)."},
|
||||
#endif
|
||||
#ifdef SIGUSR1
|
||||
{SIGUSR1, "SIGUSR1", "User-defined signal 1 (POSIX)."},
|
||||
#endif
|
||||
#ifdef SIGSEGV
|
||||
{SIGSEGV, "SIGSEGV", "Segmentation violation (ANSI)."},
|
||||
#endif
|
||||
#ifdef SIGUSR2
|
||||
{SIGUSR2, "SIGUSR2", "User-defined signal 2 (POSIX)."},
|
||||
#endif
|
||||
#ifdef SIGPIPE
|
||||
{SIGPIPE, "SIGPIPE", "Broken pipe (POSIX)."},
|
||||
#endif
|
||||
#ifdef SIGALRM
|
||||
{SIGALRM, "SIGALRM", "Alarm clock (POSIX)."},
|
||||
#endif
|
||||
#ifdef SIGTERM
|
||||
{SIGTERM, "SIGTERM", "Termination (ANSI)."},
|
||||
#endif
|
||||
#ifdef SIGSTKFLT
|
||||
{SIGSTKFLT, "SIGSTKFLT", "Stack fault."},
|
||||
#endif
|
||||
#ifdef SIGCLD
|
||||
{SIGCLD, "SIGCLD", "Same as SIGCHLD (System V)."},
|
||||
#endif
|
||||
#ifdef SIGCHLD
|
||||
{SIGCHLD, "SIGCHLD", "Child status has changed (POSIX)."},
|
||||
#endif
|
||||
#ifdef SIGCONT
|
||||
{SIGCONT, "SIGCONT", "Continue (POSIX)."},
|
||||
#endif
|
||||
#ifdef SIGSTOP
|
||||
{SIGSTOP, "SIGSTOP", "Stop, unblockable (POSIX)."},
|
||||
#endif
|
||||
#ifdef SIGTSTP
|
||||
{SIGTSTP, "SIGTSTP", "Keyboard stop (POSIX)."},
|
||||
#endif
|
||||
#ifdef SIGTTIN
|
||||
{SIGTTIN, "SIGTTIN", "Background read from tty (POSIX)."},
|
||||
#endif
|
||||
#ifdef SIGTTOU
|
||||
{SIGTTOU, "SIGTTOU", "Background write to tty (POSIX)."},
|
||||
#endif
|
||||
#ifdef SIGURG
|
||||
{SIGURG, "SIGURG", "Urgent condition on socket (4.2 BSD)."},
|
||||
#endif
|
||||
#ifdef SIGXCPU
|
||||
{SIGXCPU, "SIGXCPU", "CPU limit exceeded (4.2 BSD)."},
|
||||
#endif
|
||||
#ifdef SIGXFSZ
|
||||
{SIGXFSZ, "SIGXFSZ", "File size limit exceeded (4.2 BSD)."},
|
||||
#endif
|
||||
#ifdef SIGVTALRM
|
||||
{SIGVTALRM, "SIGVTALRM", "Virtual alarm clock (4.2 BSD)."},
|
||||
#endif
|
||||
#ifdef SIGPROF
|
||||
{SIGPROF, "SIGPROF", "Profiling alarm clock (4.2 BSD)."},
|
||||
#endif
|
||||
#ifdef SIGWINCH
|
||||
{SIGWINCH, "SIGWINCH", "Window size change (4.3 BSD, Sun)."},
|
||||
#endif
|
||||
#ifdef SIGPOLL
|
||||
{SIGPOLL, "SIGPOLL", "Pollable event occurred (System V)."},
|
||||
#endif
|
||||
#ifdef SIGIO
|
||||
{SIGIO, "SIGIO", "I/O now possible (4.2 BSD)."},
|
||||
#endif
|
||||
#ifdef SIGPWR
|
||||
{SIGPWR, "SIGPWR", "Power failure restart (System V)."},
|
||||
#endif
|
||||
#ifdef SIGSYS
|
||||
{SIGSYS, "SIGSYS", "Bad system call."},
|
||||
#endif
|
||||
#ifdef SIGUNUSED
|
||||
{SIGUNUSED, "SIGUNUSED", ""},
|
||||
#endif
|
||||
{0, NULL, NULL}
|
||||
};
|
||||
103
sysdeps/linux/swap.c
Normal file
103
sysdeps/linux/swap.c
Normal file
@@ -0,0 +1,103 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/swap.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_swap =
|
||||
(1L << GLIBTOP_SWAP_TOTAL) + (1L << GLIBTOP_SWAP_USED) +
|
||||
(1L << GLIBTOP_SWAP_FREE);
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_swap_paging =
|
||||
(1L << GLIBTOP_SWAP_PAGEIN) + (1L << GLIBTOP_SWAP_PAGEOUT);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_swap_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.swap = _glibtop_sysdeps_swap |
|
||||
_glibtop_sysdeps_swap_paging;
|
||||
}
|
||||
|
||||
/* Provides information about swap usage. */
|
||||
|
||||
#define MEMINFO "/proc/meminfo"
|
||||
#define PROC_STAT "/proc/stat"
|
||||
#define PROC_VMSTAT "/proc/vmstat"
|
||||
|
||||
void
|
||||
glibtop_get_swap_s (glibtop *server, glibtop_swap *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_swap));
|
||||
|
||||
file_to_buffer(server, buffer, sizeof buffer, MEMINFO);
|
||||
|
||||
/* Kernel 2.6 with multiple lines */
|
||||
|
||||
buf->total = get_scaled(buffer, "SwapTotal:");
|
||||
buf->free = get_scaled(buffer, "SwapFree:");
|
||||
buf->used = buf->total - buf->free;
|
||||
|
||||
buf->flags = _glibtop_sysdeps_swap;
|
||||
|
||||
|
||||
if(server->os_version_code >= LINUX_VERSION_CODE(2, 6, 0))
|
||||
{
|
||||
file_to_buffer (server, buffer, sizeof buffer, PROC_VMSTAT);
|
||||
|
||||
p = strstr (buffer, "\npswpin");
|
||||
|
||||
if(p)
|
||||
{
|
||||
p = skip_token(p);
|
||||
buf->pagein = strtoull (p, &p, 0);
|
||||
|
||||
p = skip_token(p);
|
||||
buf->pageout = strtoull (p, &p, 0);
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_swap_paging;
|
||||
}
|
||||
}
|
||||
else /* Linux 2.4 */
|
||||
{
|
||||
file_to_buffer (server, buffer, sizeof buffer, PROC_STAT);
|
||||
|
||||
p = strstr (buffer, "\nswap");
|
||||
|
||||
if(p)
|
||||
{
|
||||
p = skip_token (p);
|
||||
|
||||
buf->pagein = strtoull (p, &p, 0);
|
||||
buf->pageout = strtoull (p, &p, 0);
|
||||
|
||||
buf->flags |= _glibtop_sysdeps_swap_paging;
|
||||
}
|
||||
}
|
||||
}
|
||||
112
sysdeps/linux/sysinfo.c
Normal file
112
sysdeps/linux/sysinfo.c
Normal file
@@ -0,0 +1,112 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/cpu.h>
|
||||
#include <glibtop/sysinfo.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
#define FILENAME "/proc/cpuinfo"
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_sysinfo =
|
||||
(1L << GLIBTOP_SYSINFO_CPUINFO);
|
||||
|
||||
static glibtop_sysinfo sysinfo = { .flags = 0 };
|
||||
|
||||
static void
|
||||
init_sysinfo (glibtop *server)
|
||||
{
|
||||
char* buffer;
|
||||
gchar ** processors;
|
||||
|
||||
if(G_LIKELY(sysinfo.flags)) return;
|
||||
|
||||
if (!g_file_get_contents(FILENAME, &buffer, NULL, NULL)) {
|
||||
glibtop_error_io_r(server, "g_file_get_contents(%s)", FILENAME);
|
||||
}
|
||||
|
||||
/* cpuinfo records are seperated by a blank line */
|
||||
processors = g_strsplit(buffer, "\n\n", 0);
|
||||
|
||||
g_free(buffer);
|
||||
|
||||
sysinfo.ncpu = 0;
|
||||
for (char** this_proc = &processors[0]; *this_proc && **this_proc; this_proc++) {
|
||||
|
||||
if (sysinfo.ncpu >= GLIBTOP_NCPU) {
|
||||
glibtop_warn_r(server, "Cannot deal with more than %d CPUs", GLIBTOP_NCPU);
|
||||
break;
|
||||
}
|
||||
|
||||
gchar **parts, **p;
|
||||
if (g_strrstr (*this_proc, "processor" ) == NULL) {
|
||||
/* skip unknown paragraph */
|
||||
continue;
|
||||
}
|
||||
|
||||
glibtop_entry * const cpuinfo = &sysinfo.cpuinfo[sysinfo.ncpu];
|
||||
|
||||
cpuinfo->labels = g_ptr_array_new ();
|
||||
|
||||
cpuinfo->values = g_hash_table_new_full(g_str_hash, g_str_equal,
|
||||
g_free, g_free);
|
||||
|
||||
cpuinfo->descriptions = g_hash_table_new_full(g_str_hash, g_str_equal,
|
||||
g_free, g_free);
|
||||
|
||||
/* "<key> : <value>" */
|
||||
parts = g_strsplit_set(*this_proc, ":\n", 0);
|
||||
|
||||
for(p = parts; *p && *(p+1); p += 2) {
|
||||
|
||||
/* stole the allocated memory */
|
||||
gchar * const key = g_strstrip( *p );
|
||||
gchar * const value = g_strstrip( *(p+1) );
|
||||
|
||||
g_ptr_array_add(cpuinfo->labels, key);
|
||||
g_hash_table_insert(cpuinfo->values, key, value);
|
||||
}
|
||||
|
||||
|
||||
/* the last key has no value and has not been added */
|
||||
if(*p) g_free(*p);
|
||||
|
||||
/* just g_free instead of g_strvfree because we stole
|
||||
the memory*/
|
||||
|
||||
g_free(parts);
|
||||
|
||||
sysinfo.ncpu++;
|
||||
}
|
||||
|
||||
g_strfreev(processors);
|
||||
|
||||
sysinfo.flags = _glibtop_sysdeps_sysinfo;
|
||||
}
|
||||
|
||||
const glibtop_sysinfo *
|
||||
glibtop_get_sysinfo_s (glibtop *server)
|
||||
{
|
||||
init_sysinfo (server);
|
||||
return &sysinfo;
|
||||
}
|
||||
61
sysdeps/linux/uptime.c
Normal file
61
sysdeps/linux/uptime.c
Normal file
@@ -0,0 +1,61 @@
|
||||
/* Copyright (C) 1998-99 Martin Baulig
|
||||
This file is part of LibGTop 1.0.
|
||||
|
||||
Contributed by Martin Baulig <martin@home-of-linux.org>, April 1998.
|
||||
|
||||
LibGTop is free software; you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
LibGTop is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with LibGTop; see the file COPYING. If not, write to the
|
||||
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glibtop/error.h>
|
||||
#include <glibtop/uptime.h>
|
||||
|
||||
#include "glibtop_private.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
static const unsigned long _glibtop_sysdeps_uptime =
|
||||
(1UL << GLIBTOP_UPTIME_UPTIME) \
|
||||
+ (1UL << GLIBTOP_UPTIME_IDLETIME) \
|
||||
+ (1UL << GLIBTOP_UPTIME_BOOT_TIME);
|
||||
|
||||
/* Init function. */
|
||||
|
||||
void
|
||||
_glibtop_init_uptime_s (glibtop *server)
|
||||
{
|
||||
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
|
||||
}
|
||||
|
||||
/* Provides uptime and idle time. */
|
||||
|
||||
#define FILENAME "/proc/uptime"
|
||||
|
||||
void
|
||||
glibtop_get_uptime_s (glibtop *server, glibtop_uptime *buf)
|
||||
{
|
||||
char buffer [BUFSIZ], *p;
|
||||
|
||||
memset (buf, 0, sizeof (glibtop_uptime));
|
||||
|
||||
file_to_buffer(server, buffer, sizeof buffer, FILENAME);
|
||||
|
||||
buf->uptime = g_ascii_strtod (buffer, &p);
|
||||
buf->idletime = g_ascii_strtod (p, &p);
|
||||
buf->boot_time = get_boot_time(server);
|
||||
|
||||
buf->flags = _glibtop_sysdeps_uptime;
|
||||
}
|
||||
Reference in New Issue
Block a user