Skip to content

Commit

Permalink
misc: Align tc_iterate behavior
Browse files Browse the repository at this point in the history
The execution of tc_iterate.sh can cause different behaviors depending
on whether the tc_iterate binary is installed. The tc_iterate prog runs
collects tc statistics "count"-times where as the bash loop runs for
"length" seconds. This leads to different measuring durations.

Signed-off-by: Jonas Köppeler <j.koeppeler@tu-berlin.de>
  • Loading branch information
Jonas committed Oct 28, 2024
1 parent 228c493 commit 634603c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
3 changes: 1 addition & 2 deletions flent/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -2311,12 +2311,11 @@ def find_binary(self, interface, interval, length, host='localhost'):
interface = 'eth0'

return "{bash} {script} -i {interface} -I {interval:.2f} " \
"-c {count:.0f} -l {length} -H {host}".format(
"-l {length} -H {host}".format(
bash=bash,
script=script,
interface=interface,
interval=interval,
count=length // interval + 1,
length=length,
host=host)

Expand Down
6 changes: 2 additions & 4 deletions flent/scripts/tc_iterate.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
#!/bin/bash

interface=eth0
count=10
length=20
interval=0.1
command=qdisc
host=localhost

while getopts "i:c:l:I:C:H:" opt; do
while getopts "i:l:I:C:H:" opt; do
case $opt in
i) interface=$OPTARG ;;
c) count=$OPTARG ;;
l) length=$OPTARG ;;
I) interval=$OPTARG ;;
C) command=$OPTARG ;;
Expand All @@ -23,7 +21,7 @@ buffer=""


command_string=$(cat <<EOF
which tc_iterate >/dev/null && exec tc_iterate $buffer -i $interface -c $count -I $interval -C $command;
which tc_iterate >/dev/null && exec tc_iterate $buffer -i $interface -l $length -I $interval -C $command;
endtime=\$(date -d "$length sec" +%s%N);
while (( \$(date +%s%N) <= \$endtime )); do
tc -s $command show dev $interface;
Expand Down
15 changes: 8 additions & 7 deletions misc/tc_iterate.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#define NSEC_PER_SEC (1000000000.0)

struct arg {
int count;
int length;
struct timespec interval;
double finterval;
char *interface;
Expand All @@ -66,7 +66,7 @@ typedef struct arg args;

static const struct option long_options[] = {
{ "interface", required_argument , NULL , 'i' } ,
{ "count" , required_argument , NULL , 'c' } ,
{ "length" , required_argument , NULL , 'l' } ,
{ "interval" , required_argument , NULL , 'I' } ,
{ "command" , required_argument , NULL , 'C' } ,
{ "help" , no_argument , NULL , 'h' } ,
Expand All @@ -80,7 +80,7 @@ void usage (char *err) {
"\t-h --help \n"
"\t-b --buffer \n"
"\t-i --interface [eth0*,wlan0,etc]\n"
"\t-c --count [number of iterations]\n"
"\t-l --length [duration in seconds]\n"
"\t-I --interval [fractional number of seconds]\n"
"\t-C --command [qdisc]\n");
exit(-1);
Expand All @@ -90,13 +90,13 @@ static void defaults(args *a) {
a->interface = "eth0";
a->command = "qdisc";
a->finterval=.2;
a->count=10;
a->length=20;
a->interval.tv_nsec = 0;
a->interval.tv_sec = 0;
a->buffer = 0;
}

#define QSTRING "i:c:I:C:hb"
#define QSTRING "i:l:I:C:hb"

int process_options(int argc, char **argv, args *o)
{
Expand All @@ -113,7 +113,7 @@ int process_options(int argc, char **argv, args *o)

switch (opt)
{
case 'c': o->count = strtoul(optarg,NULL,10); break;
case 'l': o->length = strtoul(optarg,NULL,10); break;
case 'I': o->finterval = strtod(optarg,NULL); break;
case 'C': o->command = optarg; break;
case 'i': o->interface = optarg; break;
Expand Down Expand Up @@ -193,6 +193,7 @@ int forkit(args *a)
sprintf(cmd,"%s show dev %s\n",a->command,a->interface);
int csize = strlen(cmd);
int ctr = 0;
int length_count = a->length/a->finterval;
timerfd_settime(timer,0,&new_value,NULL); // relative timer

do {
Expand All @@ -206,7 +207,7 @@ int forkit(args *a)
result(out,0,BUFFERSIZE,buffer);
perror("reading cmd output");
}
} while (ctr < a->count);
} while (ctr < length_count);
close(tool);
close(in);
if(a->buffer) {
Expand Down

0 comments on commit 634603c

Please sign in to comment.