Commit Graph

37 Commits

Author SHA1 Message Date
lucic71 abba2c89ab Fix platform dependent field 2022-07-19 23:56:57 +03:00
sepherosa f757ee415a
cpu_usage: On BSD use long to hold cpu usage to avoid overflow. (#439)
Co-authored-by: Sepherosa Ziehau <sephe@dragonflybsd.org>
2021-12-19 22:31:13 +01:00
Robert Nagy 126fcaef25
add CPU spin support on OpenBSD (#471)
* add CPU spin support on OpenBSD

* use consistent ifdefs
2021-12-15 13:29:32 +01:00
Michael Stapelberg 73c6eb2d4c use param structs everywhere for consistency 2021-11-02 21:45:31 +01:00
Michael Stapelberg 6b2f4cd20c cpup_usage: param struct 2021-11-02 21:20:26 +01:00
Samuel Holland 585d0700c7 avoid out-of-bounds read after invalid %cpu conversion
In the case where no CPU number is given, skipping a character of
padding actually skips the null terminator, causing further iterations
through the loop to read out of bounds. Have sscanf() return the number
of characters read, instead of reconstructing it from the CPU number.

This was observed as a failure in test 024-cpu-usage-invalid-cpu.
2020-03-28 21:02:02 -05:00
Thomas Klausner 5aec4a5da3 Improve NetBSD port. (#361)
Detect and link against ossaudio.

Comment out unused code and functions.
2019-07-29 13:46:20 -07:00
Michael Stapelberg e84f9588df print_cpu_usage: use buffered file API
fixes #343
fixes #344
2019-07-29 21:46:08 +02:00
eplanet 96923a5bc0 Fix non Linux build for #309 2019-01-23 10:44:48 +01:00
Michael Stapelberg a57cdc84e2
Switch to autotools (#316) 2019-01-23 08:56:40 +01:00
eplanet bc5cc6f238 Fix error messages 2018-11-07 23:01:36 +01:00
TwentyFourD 6914f8e5b5
print_cpu_usage.c: Support non-consecutive CPUs
Fixes #308
2018-11-05 12:30:52 +02:00
Gaël PORTAY 0b8aa86ecb print_cpu_usage: fix invalid %cpu placeholder output
Currently, the module cpu_usage prints %cpu0 information for the invalid
%cpu placeholder (i.e. the cpu number is missing).

Consider the following configuration.

	order += "cpu_usage"

	cpu_usage {
		format = "cpu0=%cpu0 cpu1=%cpu1 cpu=%cpu"
		# missing cpu number -------------------^
	}

The configuration above produces the output below.

	$ i3status -c config
	i3status: trying to auto-detect output_format setting
	i3status: auto-detected "term"
	cpu0=-2% cpu1=-49% cpu=-2%
	cpu0=06% cpu1=02% cpu=06%
	cpu0=05% cpu1=06% cpu=05%
	...

The module prints %cpu0 at the third placeholder where it should report
an error.

This commit fixes this behavior by initializing `number' to -1. If the
cpu is missing in %cpu placeholder, the sscanf function does not set
`number'. Because `number' is -1 (lower to 0), an error is reported and
the placeholder is skipped.

	$ i3status -c ./config
	i3status: trying to auto-detect output_format setting
	i3status: auto-detected "term"
	provided CPU number '-1' above detected number of CPU 4
	cpu0= cpu1=-48% cpu=
	provided CPU number '-1' above detected number of CPU 4
	cpu0= cpu1=11% cpu=
	provided CPU number '-1' above detected number of CPU 4
	cpu0= cpu1=03% cpu=
	...
2018-10-21 20:51:53 -04:00
= d003edcba6 Fix for issue 300: Correctly print usage for cpu 10 2018-07-31 00:27:13 -05:00
Felix Buehler 52e9f6f63b able to print percentage
its now possible to have percentage before and after a variable. except
for the date. But percentage with dates does not make much sense to me, so
i skipped it.
2018-07-13 15:03:31 +02:00
eplanet 94651257ce Multiple CPU support for cpu_usage (#209)
This change addresses the issue #199 asking for multiple CPU support. It
takes an arbitrary CPU number and outputs its usage using the same
arithmetics as for CPU aggregation. It currently doesn't support
FreeBSD.
2017-03-26 06:54:07 -04:00
Mihai Coman 9375959b68 Add 'format_below_threshold' option for 'disk' module
Add 'format_above_threshold' option for 'cpu_temperature' module
Add 'format_above_threshold' option for 'cpu_usage' module
Add 'format_above_threshold' option for 'load' module
2016-11-15 01:09:05 +02:00
Mark Schreiber 1e8dab273d Add CPU usage color thresholds
CPU usage had previously not supported the color option.  Add support
for a "degraded" state above which the degraded color is used, and a
higher "bad" state above which the "bad" color is used.  One possible
use for these might be indicating whether one or all cores are
saturated.

Unlike the color settings for other, these are set high enough to be
disabled by default.  This is done because i3status determines CPU
usage over only the last display interval, which means that, a user
with a low refresh rate might see frequent, potentially-annoying color
changes.
2016-04-13 09:11:32 -07:00
Brendan Van Hook a13b2e7288 Added support for lemonbar 2015-10-04 14:52:32 -04:00
Jasper Lievisse Adriaanse ae50bbe257 sys/dkstat.h has been removed from OpenBSD and it's functionality actually lived/lives in sys/sched.h 2015-04-02 20:31:17 +02:00
Baptiste Daroussin c9dc67e054 print_cpu_usage: Fix warnings on non linux
Move linux variable under LINUX boundaries
2015-03-25 08:19:13 +01:00
Michael Stapelberg d74e904bf4 clang-format-3.5 -i **/*.[ch], update modeline
From here on, we’ll use clang-format to automatically format the source.

This has worked well in i3, so we are introducing it for i3status.
2015-03-16 10:01:07 +01:00
Mats 4f7da73885 Unify use of string comparisons
* strncmp(s1, s2, strlen(s2)) → BEGINS_WITH(s1, s2)
* strncmp(s1, s2, strlen(s1)) → strcmp(s1, s2)
* Prefer case-insensitive comparison for options
2014-03-12 08:28:16 +01:00
Arnaud Degroote 32551729e8 Allow to print cpu usage on NetBSD 2013-10-07 19:31:01 +02:00
Scott Tincman 0eeded8bc0 DragonFlyBSD support added 2012-11-15 12:31:17 +01:00
Mateusz Poszwa 859a7690a6 Avoid division by zero when calculating CPU usage. 2012-06-28 12:05:01 +02:00
Michael Stapelberg 296eb5e706 Error handling: Never output null as full_text (JSON), prefix messages with i3status (Thanks Artemis)
The former made i3bar crash, the latter is helpful for debugging.
2012-05-09 18:56:57 +02:00
Jasper Lievisse Adriaanse 75a741484e Fix CPU usage on OpenBSD. Currently only takes the first cpu into account, but works fine otherwise. 2012-04-29 11:13:06 +02:00
Michael Stapelberg 1b3aa40485 add yajl compat code 2012-04-08 14:05:47 +02:00
Michael Stapelberg 12b1bfa9b8 Properly output JSON with libyajl 2012-03-25 22:05:00 +02:00
Michael Stapelberg d5b4c8e368 Implement the i3bar JSON protocol
This hardcodes all the JSON parts. Strings are not properly escaped currently.
The best/easiest way to fix this is by actually using libyajl.
2012-02-16 23:30:54 +00:00
Mateusz Poszwa 42e61c4f6e fix parentheses in cc1457c4f0 2011-08-29 16:06:40 +02:00
Michael Stapelberg 7870fdae86 initialize variables to fix compiler warning 2011-08-26 00:33:56 +02:00
Connor Lane Smith cc1457c4f0 make modules more resilient to failure 2011-08-25 23:27:10 +02:00
Baptiste Daroussin f288fd2e4f Add support for cpu usage on FreeBSD 2011-07-24 02:12:22 +02:00
Michael Stapelberg 0b299f740d Fix trailing whitespaces, document cpu_usage in manpage 2011-05-06 13:17:26 +02:00
Peter Bui 8b18e8e33c Add print_cpu_usage 2011-05-06 13:13:11 +02:00