aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fns.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/fns.c b/src/fns.c
index dc55999efb6..21be77b7696 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -2494,24 +2494,31 @@ and can edit it until it has been confirmed.")
2494 } 2494 }
2495} 2495}
2496 2496
2497DEFUN ("load-average", Fload_average, Sload_average, 0, 0, 0, 2497DEFUN ("load-average", Fload_average, Sload_average, 0, 1, 0,
2498 "Return list of 1 minute, 5 minute and 15 minute load averages.\n\ 2498 "Return list of 1 minute, 5 minute and 15 minute load averages.\n\
2499Each of the three load averages is multiplied by 100,\n\ 2499Each of the three load averages is multiplied by 100,\n\
2500then converted to integer.\n\ 2500then converted to integer.\n\
2501When USE-FLOATS is non-nil, floats will be used instead of integers.\n\
2502These floats are not multiplied by 100.\n\n\
2501If the 5-minute or 15-minute load averages are not available, return a\n\ 2503If the 5-minute or 15-minute load averages are not available, return a\n\
2502shortened list, containing only those averages which are available.") 2504shortened list, containing only those averages which are available.")
2503 () 2505 (use_floats)
2506 Lisp_Object use_floats;
2504{ 2507{
2505 double load_ave[3]; 2508 double load_ave[3];
2506 int loads = getloadavg (load_ave, 3); 2509 int loads = getloadavg (load_ave, 3);
2507 Lisp_Object ret; 2510 Lisp_Object ret = Qnil;
2508 2511
2509 if (loads < 0) 2512 if (loads < 0)
2510 error ("load-average not implemented for this operating system"); 2513 error ("load-average not implemented for this operating system");
2511 2514
2512 ret = Qnil; 2515 while (loads-- > 0)
2513 while (loads > 0) 2516 {
2514 ret = Fcons (make_number ((int) (load_ave[--loads] * 100.0)), ret); 2517 Lisp_Object load = (NILP (use_floats) ?
2518 make_number ((int) (100.0 * load_ave[loads]))
2519 : make_float (load_ave[loads]));
2520 ret = Fcons (load, ret);
2521 }
2515 2522
2516 return ret; 2523 return ret;
2517} 2524}