$ valgrind --leak-resolution=high --trace-malloc=yes --leak-check=yes --show-reachable=yes -v [프로그램 풀 경로]
실행이 끝난 다음에 malloc/free 된 메모리들에 대한 현황을 ERROR SUMMARY라는 이름으로 알려줍니다. leak된 것들이 있다면 어떤 종류이고 어떤 내용이 들어있는지 등등을 자세히 알려주니 그것을 보시면 디버깅이 손쉬울 겁니다. 혹 출력되는 메시지가 너무 많아 방해가 되면 --trace-malloc=yes 를 빼주셔도 이 경우에는 별 상관 없을겁니다. malloc/free 될때마다 뿌려주는 메시지를 출력안하는 것입니다.
만약 한번의 alloc에 대해 두번의 free가 가해졌다면 아래와 같은 메시지가 그 위치를 알려줍니다. 보시다시피 main.c의 52번째줄에서 이미 free한 메모리 블럭에 대해 main.c의 53번째줄에서 잘못된 free를 수행한 걸로 나옵니다.
ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
==29279==
==29279== 1 errors in context 1 of 1:
==29279== Invalid free() / delete / delete[]
==29279== at 0x40025E87: free (in /usr/lib/valgrind/vgskin_memcheck.so)
==29279== by 0x80489C3: main (main.c:53)
==29279== by 0x4024190A: __libc_start_main (in /lib/libc-2.3.2.so)
==29279== by 0x80488E0: (within /home/youlsa/src/montgomery/actiontag)
==29279== Address 0x4109C024 is 0 bytes inside a block of size 200 free'd
==29279== at 0x40025E87: free (in /usr/lib/valgrind/vgskin_memcheck.so)
==29279== by 0x80489B2: main (main.c:52)
==29279== by 0x4024190A: __libc_start_main (in /lib/libc-2.3.2.so)
==29279== by 0x80488E0: (within /home/youlsa/src/montgomery/actiontag)
==29279== IN SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
/* Define here if you want to swap ports also */ #define REALPORT 23 /* port you which to communicate */ #define FAKEPORT 9000 /* port that appears on the wire */
unsigned int print_hex(char *str, unsigned int str_len) { char *curr_line; char ch; int i = 0, j = 0; unsigned int len = 0; unsigned int total_len = 0; unsigned int index = 0; unsigned int line = 0;
proc monitor {interval} { global FlowNumber tcp ns set nowtime [$ns now]
# for {set i 0} {$i < $FlowNumber} {incr i 1} { set win [open result a] # puts $win "$nowtime [$tcp($i) set cwnd_] [$tcp($i) set ack_]" puts $win "$nowtime [$tcp set cwnd_]" # [$tcp set ack_]" close $win # } $ns after $interval "monitor $interval" }
proc finish { } { puts "inner end1" global ns tf nf filename # f_cwnd $ns flush-trace close $tf # close $nf # close $f_cwnd puts "inner end" exec nam $filename.nam & exit 0; }
#Create six nodes #agent set host1 [$ns node] #puts "$ns $n0" set host2 [$ns node] #puts "$ns $n1" set host3 [$ns node] #puts "$ns $n2" set host4 [$ns node] #puts "$ns $n3" set rout1 [$ns node] #puts "$ns $n4" set rout2 [$ns node]
set sender1 [$ns node] set sender2 [$ns node] set sender3 [$ns node] set sender4 [$ns node]
set recv1 [$ns node] set recv2 [$ns node] set recv3 [$ns node] set recv4 [$ns node] #puts "$ns $n5"
set redq [[$ns link $rout1 $rout2] queue] # set traceq [open reno-queue.tr w] # $redq attach $traceq
#Create a TCP agent and attach it to node n0 set tcp [new Agent/TCP/$tcp_protocol] # set tcp [new Agent/TCP] $tcp set fid_ 1 $tcp set window_ 100 $tcp set packetSize_ $packet_size # set tcp2 [new Agent/TCP/$tcp_protocol] set tcp2 [new Agent/TCP] $tcp2 set fid_ 3 $tcp2 set window_ 100 set tcp3 [new Agent/TCP] $tcp3 set fid_ 4 $tcp3 set window_ 100 set tcp4 [new Agent/TCP] $tcp4 set fid_ 5 $tcp4 set window_ 100 #set tcp [new Agent/TCP]
#$tcp set pace_packet_ 2 # $tcp set rtt 0.01s #$tcp set rate_ 1mb #set tcp [$ns create-connection TCP $n0 TCPSink $n2 0] set snk [new Agent/TCPSink] set snk2 [new Agent/TCPSink] set snk3 [new Agent/TCPSink] set snk4 [new Agent/TCPSink]
$tcp set syn_ true $tcp2 set syn_ true $tcp3 set syn_ true $tcp4 set syn_ true $ns attach-agent $host1 $tcp
#Create a UDP agent and attach it to node n0 set udp [new Agent/UDP] $ns attach-agent $host2 $udp set null [new Agent/UDP] $ns attach-agent $host4 $null $ns connect $udp $null $udp set fid_ 2
#Setup a CBR over UDP connection set cbr [new Application/Traffic/CBR] $cbr attach-agent $udp $cbr set type_ CBR $cbr set packet_size_ 512 #5MBps # $cbr set rate_ 5000000 $cbr set rate_ $rate # [lindex $argv 0]
#proc logTCPwnd {logfile tcpSource timeInterval} { # global ns # set now [$ns now] # set cwnd [$tcpSource set cwnd_] # set awnd [$tcpSource set awnd_] # puts $logfile "$now $cwnd $awnd" # $ns at [expr $now+$timeInterval] "logTCPwnd $logfile $tcpSource $timeInterval" }
#Schedule events for the CBR agents #$ns at 0.0 "logTCPwnd $t_cwndTf $tcp 0.05" #Setup a FTP over TCP Connection set ftp [$tcp attach-source FTP] $ftp set type_ FTP # set ftp2 [new Application/FTP] # $ftp attach-agent $tcp2
set ftp2 [$tcp2 attach-source FTP] set ftp3 [$tcp3 attach-source FTP] set ftp4 [$tcp4 attach-source FTP] $ftp2 set type_ FTP # $ftp2 set packet_size_ 512 $ftp3 set type_ FTP # $ftp3 set packet_size_ 512 $ftp4 set type_ FTP # $ftp4 set packet_size_ 512
# $ns at 0 "monitor 0.5" $ns at 0.0 "$ftp start" # $ns at 0.0 "$ftp2 start" # $ns at 0.0 "$ftp3 start" # $ns at 0.0 "$ftp4 start" $ns at 10.0 "$cbr start" $ns at 110.0 "finish" # $ns at 10.0 "$ftp start" # $ns at 1.0 "$cbr start" # $ns at 10.0 "finish" #Run the simulation $ns run return 1; }
}
아래는 thoughput 스크립트
BEGIN { init=0; i=0; recv = 0 }
{ # Trace line format: normal # if ($2 != "-t") { event = $1 time = $2 if (event == "+" || event == "-") node_id = $3 if (event == "r" || event == "d") node_id = $4 flow_id = $8 pkt_id = $12 pkt_size = $6 # } # Trace line format: new # if ($2 == "-t") { # event = $1 # time = $3 # node_id = $5 # flow_id = $39 # pkt_id = $41 # pkt_size = $37 # }
# Calculate total received packets' size if(event=="+" && node_id==0 && flow_id==1) {