Commit Graph

33 Commits (f1cea504a407543f7856461eee3eb61b975321f4)

Author SHA1 Message Date
Zhu Yi b3da2f62b9 canbusload: support busload visualization
Add '-v' option for visualize busload, the output shows a moving
histogram of the past 90 seconds.

canbusload 2024-09-23 17:19:33 (exact bitstuffing)
 can0@500k   487   55558   31048       0  99% |XXXXXXXXXXXXXXXXXXX.|
100%|..........................................................................................
 95%|..............................................................................XXXXXXXXXXXX
 90%|.............................................................................XXXXXXXXXXXXX
 85%|.............................................................................XXXXXXXXXXXXX
 80%|.............................................................................XXXXXXXXXXXXX
 75%|.............................................................................XXXXXXXXXXXXX
 70%|.............................................................................XXXXXXXXXXXXX
 65%|.............................................................................XXXXXXXXXXXXX
 60%|............................................................................XXXXXXXXXXXXXX
 55%|............................................................................XXXXXXXXXXXXXX
 50%|............................................................................XXXXXXXXXXXXXX
 45%|............................................................................XXXXXXXXXXXXXX
 40%|............................................................................XXXXXXXXXXXXXX
 35%|.........................................XXX................................XXXXXXXXXXXXXX
 30%|.........................................XXXX...............................XXXXXXXXXXXXXX
 25%|........................................XXXXXX.............................XXXXXXXXXXXXXXX
 20%|XXXXXXXX...............................XXXXXXXXXXXXXXXXX....XXXXXXXXXXX...XXXXXXXXXXXXXXXX
 15%|XXXXXXXXX.............................XXXXXXXXXXXXXXXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 10%|XXXXXXXXX.XXXXXXXXXXXXXXXXXXX..XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  5%|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Signed-off-by: Zhu Yi <yi.zhu5@cn.bosch.com>
Signed-off-by: Hubert Streidl <hubert.streidl@de.bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
Link: https://lore.kernel.org/r/20250120162332.19157-3-mark.jonas@de.bosch.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2025-01-20 18:07:16 +01:00
Zhu Yi b85418d75c canbusload: support busload statistic
Add '-s' option for display busload statistic, the output contains
minimal, maximum and exponentially-damped moving sums of one second
average (borrowed from Linux load average algorithm) since start or
reset (press 'r' while running).

canbusload 2024-09-23 17:15:18 (exact bitstuffing)
 can0@500k   942  107535   60168       0  18% min:  0%, max: 21%, load: 16%   6%   2% |XXX.................|

Signed-off-by: Zhu Yi <yi.zhu5@cn.bosch.com>
Signed-off-by: Hubert Streidl <hubert.streidl@de.bosch.com>
Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com>
Link: https://lore.kernel.org/r/20250120162332.19157-2-mark.jonas@de.bosch.com
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2025-01-20 18:01:10 +01:00
Oliver Hartkopp dced0a6ec7 canbusload: fix and improve the bitrate output
With the introduction of CAN FD the bitrate has not been printed
correcty. Fix the CAN FD bitrate output and try to shrink the
bitrates by using kilo or Mega suffixes: 500000 -> 500k

Fixes: 6382765bf6 ("canbusload: count databitrate seperately")
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-08-08 17:36:49 +02:00
Oliver Hartkopp fc2473424e canbusload: show RX/TX direction in bargraph
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-08-08 10:04:55 +02:00
Oliver Hartkopp 724e6f7c11 canbusload: use recvmsg() instead of recvfrom()
To access msg_flags for RX/TX direction detection.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-08-07 21:29:49 +02:00
Oliver Hartkopp 7665e1e236 canbusload: add auto detection of CAN interfaces
Rework to use a single CAN socket for the received CAN traffic.
This allows to shutdown and restart various CAN interfaces without
terminating the application.
Additionally an auto detection has been implemented with the 'any' CAN
interface. E.g. with any@500000,2000000 CAN interfaces that have not
been defined before are assigned with the given 'any' bitrates when a
CAN frame from this CAN interface has been received.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-08-07 19:57:08 +02:00
Oliver Hartkopp b592ec5b1f canbusload: fix string length check for CAN FD
The CAN interface description can now have two bitrates.
Extend the length check to handle the CAN FD data bitrate correctly.

Fixes: 6382765bf6 ("canbusload: count databitrate seperately")
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-08-07 13:02:05 +02:00
Oliver Hartkopp dd16f2603b can-utils: make local functions static
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2024-03-12 20:10:00 +01:00
Marc Kleine-Budde 8e2caa8f8a canbusload: main(): switch from pselect() to select()
We don't need to block any signals, so a select() is sufficient. This
also fixes the problem that sigmask is uninitialized and may block the
sig ARLM, which make canbusload hang until a CAN frame is recieved.

Closes: https://github.com/linux-can/can-utils/issues/465
2023-10-06 12:32:42 +02:00
Marc Kleine-Budde 84919edbaa canbusload: redraw mode: use less screen estate
Use less screen estate by not printing unneeded newlines in redraw
mode.
2023-09-27 12:40:38 +02:00
Marc Kleine-Budde 92adbda471 canbusload: convert towards kernel coding style 2023-09-27 12:38:48 +02:00
Yasushi SHOJI 1d43b3c6f3 canbusload: Enhance error message for missing bitrate
When canbusload is executed without bit rate, it exits with an exit
code of 1 and prints help, but without explaining why.  Users cannot
know what was wrong.  When other errors occur, though, canbusload
prints an error message along with the help.

Print an error message when bit rate is not given or "@" is not found.

Signed-off-by: Yasushi SHOJI <yashi@spacecubics.com>
2023-06-02 20:59:39 +09:00
Yasushi SHOJI 16a717c81e canbusload: Follow Bash exit status when signaled
Bash and many other shells use 128 + signum as the exit status when a
program get signal and exit.  Follow the common behavior so that we
know how the programs are killed.

canbusload.c was using a non-safe function, exit(3), in the signal
handler.  This commit replaces it with the way other programs in
can-utils are using; set running = 0 to exit from the while loop.

Signed-off-by: Yasushi SHOJI <yashi@spacecubics.com>
2023-03-20 10:22:41 +09:00
Vincent Mailhol 0cfd56d613 lib: add pr_debug() macro
Add the pr_debug() macro so that:

  #ifdef DEBUG
  	printf("foo");
  #endif

can be replaced by:

  	pr_debug("foo");

Apply the pr_debug() macro wherever relevant.

Currently, there is no consensus whether debug messages should be
printed on stdout or stderr. Most of the modules: canbusload.c,
candump.c and canlogserver.c use stdout but
mcp251xfd/mcp251xfd-dev-coredump.c uses stderr. Harmonize the behavior
by following the major trend and make
mcp251xfd/mcp251xfd-dev-coredump.c also output to stdout.

slcanpty.c does a #define DEBUG, meaning that debug is always turned
on for this file. Remove this and make debug an option like every
other files.

Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20221114163848.3398-5-mailhol.vincent@wanadoo.fr
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2022-11-15 09:49:52 +01:00
Kurt Van Dijck 6382765bf6 canbusload: count databitrate seperately
Signed-off-by: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
2021-06-24 14:44:50 +02:00
Kurt Van Dijck e319afb10f canbusload: count full payload for CANFD frames
Signed-off-by: Kurt Van Dijck <dev.kurt@vandijck-laurijssen.be>
2021-06-24 12:47:37 +02:00
Rosen Penev b153fe3f35
clang-tidy: sort includes alphabetically
Found with llvm-include-order

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2020-10-12 23:28:58 -07:00
Gary Bisson 46895a41c5 Fix comparison type mismatch warnings
Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com>
2020-05-28 20:54:37 +02:00
Alexander Gerasiov 69865c8247 canbusload.c: Reformat help/usage output to be compatible with help2man.
Signed-off-by: Alexander Gerasiov <gq@debian.org>

Gbp-Pq: Name 0002-canbusload.c-Reformat-help-usage-output-to-be-compat.patch
2020-04-27 08:20:08 +03:00
Yegor Yefremov 14ccc06eba Fix spelling in various files
codespell parameters:

codespell -q 3 --skip="*.in,*.sh,*.m4,config,configure,autom4te.cache"

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2019-11-11 14:21:49 +01:00
Yegor Yefremov 7b7331976a Add SPDX identifiers
Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2019-06-19 12:24:24 +02:00
Frank Theile f51c897d68
Consistent arguments to sizeof().
In calls to functions taking a pointer 'p' and a length 'l':
if a struct variable v is passed in for p, then also pass sizeof(v) for
l.
2018-04-03 11:56:28 +02:00
Oliver Hartkopp 110af11db1 canbusload: print bitstuffing mode when showing current time is enabled
When printing the current time on the first line the bitstuffing mode is
displayed depending on the command line settings.

Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2014-02-01 21:30:12 +01:00
Michal Sojka 2206f92de7 canbusload: Add exact CAN frame length calculation (including bitstuffing)
This adds an algorithm for calculating the exact number of bits a CAN
frame occupies on the bus and uses this algorithm in canbusload. It
also moves the other methods for CAN frame length calculation, already
present in canbusload, to the new file.

The added algorithm calculates the exact number of stuffed bit in a
CAN frame. Note that in order to calculate that correctly, we must
also know the frame's CRC. Hence, the algorithm also includes CRC
calculation routine.

The correctness of the algorithm was verified on an oscilloscope for
several different SFF and EFF frames.

Currently only CAN frames are supported. For CANFD frames, a different
algorithm is needed. CANFD uses different CRC polynomials and
calculates the CRC from the staffed bit-stream (CAN calculates CRC
from de-stuffed bit-stream).

Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2014-01-30 16:23:25 +01:00
Uwe Kleine-König 4ddde7b966 trivial: fix typo concerning "bandwidth"
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2014-01-23 21:25:15 +01:00
Oliver Hartkopp 836d3cc012 remove obsolete SVN ID tags
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
2012-11-14 20:57:16 +01:00
Oliver Hartkopp 5077515927 adapt column width format for high busload values 2012-03-08 19:32:45 +01:00
Marc Kleine-Budde 722a09116d treewide: replace berlios contact email by linux-can@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
2012-01-11 12:14:15 +01:00
Kurt Van Dijck a4c200efe6 canbusload: flush output at the end of each cycle
When canbusload is piped to another program, the output
is queued for several cycles. This patch will flush the output
explicitely.

Signed-off-by: Kurt Van Dijck <kurt.van.dijck@eia.be>
2012-01-10 17:41:07 +01:00
Oliver Hartkopp d7fe33eb4b Fixed calculation of needed bits on the physical wire according Ken Tindells
*worst* case calculation for stuff-bits.
(see "Guaranteeing Message Latencies on Controller Area Network" 1st ICC'94)
Due to the bitstuffing estimation the calculated busload may exceed 100%.
2010-09-24 17:56:53 +00:00
Oliver Hartkopp 5655d53acb Remove compiler warning :
warning: suggest explicit braces to avoid ambiguous ‘else’
2010-05-14 12:50:17 +00:00
Oliver Hartkopp adbe6f9bee Whitespace fixes. Indented the code following Linux styleguide to fix
the mess between tabs and spaces.
2008-06-03 08:46:57 +00:00
Oliver Hartkopp 789a021bb9 Added tiny tool to measure CAN busload. 2008-05-27 13:47:20 +00:00