Commit Graph

9 Commits

Author SHA1 Message Date
Tony Narlock
c036017db3 Fix FreeBSD memory usage
Total memory would go out of bounds for machines ~ > 3.5gB of
memory due to the limit of what u_int can hold.

Use ``getpagesize()`` and bitshift pagesize so it fits.

See also: https://github.com/thewtex/tmux-mem-cpu-load/issues/29
2016-01-09 10:41:28 -06:00
Pawel "l0ner" Soltys
87cc9b1ce8 Code Refactoring part 2: unified load_string() function on all platforms
All the platforms were using identical logic based on getloadavg() function to
get the load avg stats (except linux, which was using sinfo struct, but can use getloadavg() function). I've noticed this while working on NetBSD port.

Also: fixed a typo on freebsd.
2015-02-19 21:26:35 +01:00
Pawel "l0ner" Soltys
240752d800 Code Refactornig
Since the headers for cpu, memory and load functions are virtually the same for
all platforms, I've decided to move them into common/ dir and do some
refacotring:

* removed per-platform header files
* implemented get_cpu_count() function across all platforms. We are using it cpu
  on every platform, yet not on every one this was implemented as a separate
  function.
* removed platform detection through preprocessor from main: we don't need this
  there anymore, since the headers are common for all platforms. CMake will
  handle setting of correct source files for us now.
* Unified used defines for CPU states across all platforms and made linux use
  them. Added some platform detection to cpu.h in order to set them correctly
  across the platforms.
* moved getsysctl.h to common/ dir, since it's used on Net and Free BSD, and
  thus become a common include.
2015-02-19 19:47:45 +01:00
Pawel "l0ner" Soltys
1512a0bda0 NetBSD port.
NetBSD port shares with FreeBSD:
 - load_string()
 - getsysctl()

With OpenBSD:
 - error()
2015-02-16 23:29:27 +01:00
Pawel "l0ner" Soltys
91594b7a5a Use u_long for storing cpu stats instead of detecting architecture
As suggested to me by "Jasper Lievisse Adriaanse" in an email:

On 2015-02-16 09:02 Jasper Lievisse Adriaanse <jasper@openbsd.org> wrote:
> You can actually use 'long' instead of juggling between 64 and 32 bit return
> types. I've impemented something similiar for libgtop years ago and never had
> any issues when using 'long' for both 64 and 32 platforms. Here's the
> refernce: https://git.gnome.org/browse/libgtop/tree/sysdeps/openbsd/cpu.c#n62

This is a better idea than what I've implemented. Also this should resolve
eventual occurrence of "unable to get cpu stats" problem on 64bit platforms we
do not detect.
2015-02-16 18:38:21 +01:00
Pawel "l0ner" Soltys
cf2a094f13 Fix for cpu sysctl failing on 64bit FreeBSD
same as commit  80d70b7a4d5ee9a4ba79deae0e840c65ccaf4131
2015-02-13 19:56:47 +01:00
Pawel "l0ner" Soltys
869d43f102 Fixed RAM usage calculation on FreeBSD
- Instead of displaying hardware ram quantity, display ram available to be
  allocated by applications. FreeBSD uses some ram for kernel, segment mappings
  and other stuff. Those memory pages are not available for allocation by
  applications.
- Calculate correctly ram usage. Active + Wired (buffers). Nothing else.

For more info see:
- http://www.cyberciti.biz/files/scripts/freebsd-memory.pl.txt
- conky source code on github
- output of top and vmstat on FreeBSD
- http://www.zabbix.com/forum/showthread.php?t=21826
- https://support.zabbix.com/browse/ZBXNEXT-774

htop on FreeBSD uses linux procfs compatibility layer, and thus it's readings
are a little off.
2015-02-13 18:46:28 +01:00
Pawel "l0ner" Soltys
9bd9e79d36 Strip unnecessary whitespaces 2015-01-20 15:03:49 +01:00
Pawel "l0ner" Soltys
112004f3db FreeBSD and OpenBSD ports
- Removed OpenBSD stuff from freebsd port
- Renamed bsd folder to freebsd since now it contains only
  freebsd-relevant files.
- Changed CMake instructions to account for bsd port changes
- modified main source file to account for openbsd port
2015-01-20 15:03:48 +01:00