Debian Codegraph @

tc/m_estimator.c

raw
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * m_estimator.c Parse/print estimator module options.
4 *
5 * Authors: Alexey Kuznetsov, <[email protected]>
6 */
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <fcntl.h>
12 #include <sys/socket.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
15 #include <string.h>
16
17 #include "utils.h"
18 #include "tc_util.h"
19 #include "tc_common.h"
20
21 static void est_help(void);
22
23 static void est_help(void)
24 {
25 fprintf(stderr,
26 "Usage: ... estimator INTERVAL TIME-CONST\n"
27 " INTERVAL is interval between measurements\n"
28 " TIME-CONST is averaging time constant\n"
29 "Example: ... est 1sec 8sec\n");
30 }
31
32 int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est)
33 {
34 int argc = *p_argc;
35 char **argv = *p_argv;
36 unsigned int A, time_const;
37
38 NEXT_ARG();
39 if (est->ewma_log)
40 duparg("estimator", *argv);
41 if (matches(*argv, "help") == 0)
42 est_help();
43 if (get_time(&A, *argv))
44 invarg("estimator", "invalid estimator interval");
45 NEXT_ARG();
46 if (matches(*argv, "help") == 0)
47 est_help();
48 if (get_time(&time_const, *argv))
49 invarg("estimator", "invalid estimator time constant");
50 if (tc_setup_estimator(A, time_const, est) < 0) {
51 fprintf(stderr, "Error: estimator parameters are out of range.\n");
52 return -1;
53 }
54 if (show_raw)
55 fprintf(stderr, "[estimator i=%hhd e=%u]\n", est->interval, est->ewma_log);
56 *p_argc = argc;
57 *p_argv = argv;
58 return 0;
59 }