mirror of
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git
synced 2024-11-15 22:15:13 +08:00
8589eb4efd
Every tool in the iproute2 package have one or more function to show an help message to the user. Some of these functions print the help line by line with a series of printf call, e.g. ip/xfrm_state.c does 60 fprintf calls. If we group all the calls to a single one and just concatenate strings, we save a lot of libc calls and thus object size. The size difference of the compiled binaries calculated with bloat-o-meter is: ip/ip: add/remove: 0/0 grow/shrink: 5/15 up/down: 103/-4796 (-4693) Total: Before=672591, After=667898, chg -0.70% ip/rtmon: add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-54 (-54) Total: Before=48879, After=48825, chg -0.11% tc/tc: add/remove: 0/2 grow/shrink: 31/10 up/down: 882/-6133 (-5251) Total: Before=351912, After=346661, chg -1.49% bridge/bridge: add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-459 (-459) Total: Before=70502, After=70043, chg -0.65% misc/lnstat: add/remove: 0/1 grow/shrink: 1/0 up/down: 48/-486 (-438) Total: Before=9960, After=9522, chg -4.40% tipc/tipc: add/remove: 0/0 grow/shrink: 1/1 up/down: 18/-62 (-44) Total: Before=79182, After=79138, chg -0.06% While at it, indent some strings which were starting at column 0, and use tabs where possible, to have a consistent style across helps. Signed-off-by: Matteo Croce <mcroce@redhat.com> Signed-off-by: David Ahern <dsahern@gmail.com>
65 lines
1.6 KiB
C
65 lines
1.6 KiB
C
/*
|
|
* m_estimator.c Parse/print estimator module options.
|
|
*
|
|
* This program is free software; you can u32istribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version
|
|
* 2 of the License, or (at your option) any later version.
|
|
*
|
|
* Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
|
|
*
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <fcntl.h>
|
|
#include <sys/socket.h>
|
|
#include <netinet/in.h>
|
|
#include <arpa/inet.h>
|
|
#include <string.h>
|
|
|
|
#include "utils.h"
|
|
#include "tc_util.h"
|
|
#include "tc_common.h"
|
|
|
|
static void est_help(void);
|
|
|
|
static void est_help(void)
|
|
{
|
|
fprintf(stderr,
|
|
"Usage: ... estimator INTERVAL TIME-CONST\n"
|
|
" INTERVAL is interval between measurements\n"
|
|
" TIME-CONST is averaging time constant\n"
|
|
"Example: ... est 1sec 8sec\n");
|
|
}
|
|
|
|
int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est)
|
|
{
|
|
int argc = *p_argc;
|
|
char **argv = *p_argv;
|
|
unsigned int A, time_const;
|
|
|
|
NEXT_ARG();
|
|
if (est->ewma_log)
|
|
duparg("estimator", *argv);
|
|
if (matches(*argv, "help") == 0)
|
|
est_help();
|
|
if (get_time(&A, *argv))
|
|
invarg("estimator", "invalid estimator interval");
|
|
NEXT_ARG();
|
|
if (matches(*argv, "help") == 0)
|
|
est_help();
|
|
if (get_time(&time_const, *argv))
|
|
invarg("estimator", "invalid estimator time constant");
|
|
if (tc_setup_estimator(A, time_const, est) < 0) {
|
|
fprintf(stderr, "Error: estimator parameters are out of range.\n");
|
|
return -1;
|
|
}
|
|
if (show_raw)
|
|
fprintf(stderr, "[estimator i=%u e=%u]\n", est->interval, est->ewma_log);
|
|
*p_argc = argc;
|
|
*p_argv = argv;
|
|
return 0;
|
|
}
|