LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Desktop (https://www.linuxquestions.org/questions/linux-desktop-74/)
-   -   Result of awk script (https://www.linuxquestions.org/questions/linux-desktop-74/result-of-awk-script-4175458184/)

ines8989 04-15-2013 06:49 AM

Result of awk script
 
Hi i have tested script for delay.awk to analyse a tcp trace file and i obtain this result

2 0.090344 0.045172

I want to trace the graph of delay for my tcp trace file with this code awk but i did'nt inderstand this result please help me : This is my script awk :

------------------------------------------
BEGIN {highest_packet_id = 0;}
{
action = $1;
time = $2;
node =$3;
type = $5;
packet_id =$6;
if (packet_id > highest_packet_id)
highest_packet_id = packet_id;
if (action == "+"){
if (type == "tcp"){
send_time[packet_id] = time;}
#else {send_time[packet_id] = 0;}
}
else if (action == "r"){
if (type == "tcp"){
rcv_time[packet_id] = time;
}
#else{rcv_time[packet_id] = 0;}
}
}
END {packet_no = 0; total_delay = 0;
for (packet_id = 0; packet_id <=highest_packet_id; packet_id++){
if ((send_time[packet_id]!=0) && (rcv_time[packet_id]!=0)){
start = send_time[packet_id];
end = rcv_time[packet_id];
packet_duration = end-start;}
else
packet_duration = -1;
if (packet_duration > 0)
{packet_no++;
total_delay = total_delay + packet_duration; }
}
printf("%d %f %f\n", packet_no, total_delay, total_delay/packet_no);
}

Thanks for you

Snark1994 04-15-2013 07:23 AM

What did you expect it to print? I suspect you want to move the 'printf' line above the brace preceding it (i.e. change

Code:

        if (packet_duration > 0) {
            packet_no++;
            total_delay = total_delay + packet_duration;
        }
    }
    printf("%d %f %f\n", packet_no, total_delay, total_delay/packet_no);
}

to

Code:

        if (packet_duration > 0) {
            packet_no++;
            total_delay = total_delay + packet_duration;
        }
        printf("%d %f %f\n", packet_no, total_delay, total_delay/packet_no);
    }
}



Also, use [CODE][/CODE] tags around your code to make it more legible.


All times are GMT -5. The time now is 08:41 PM.