TOP
|
[ 录入者:admin | 时间:2007-10-28 00:34:01
| 作者: | 来源:
| 浏览:965次 ] |
在Jist的主页里,给出了几种模拟器的对比,我对如何获取NS2的模拟运行时间和占用内存的方法比较感兴趣,因为自己的工作可能将来也要涉及模拟器优化,因此首先要学会测量的方法。
1.运行时间
time ./ns xxx.tcl
下面是在我机器上ls的测量结果:
fang@ns-serv2:~/ns-allinone-2.31$ time ls bin include lib ns-2.31 README tclcl xgraph-12.1 cweb install man otcl sgb tclcl-1.19 zlib-1.2.3 gt-itm INSTALL.WIN32 nam-1.13 otcl-1.13 tcl8.4.14 tk8.4.14
real 0m0.003s user 0m0.002s sys 0m0.001s
2.占用内存
基本方法是检查/proc/$PROCESS_PID/status里的内容,在网上找了找,修改了别人的代码:
#!/bin/sh
USAGE="Usage: $0 processName"
if [ $# -ne 1 ]; then echo $USAGE exit 1 fi
# In case the monitored process has not yet started # keep searching until its PID is found PROCESS_PID="" while : do PROCESS_PID=`pidof $1`
if [ "$PROCESS_PID.X" != ".X" ]; then break fi done
LOG_FILE="memusage.log"
echo "ElapsedTime,VmSize,VmRSS" > $LOG_FILE
ELAPSED_TIME=`date +%H:%M:%S:%N` PERIOD=1 # 检查间隔,单位为秒
while : do if [ -d /proc/$PROCESS_PID ] ; then VM_SIZE=`awk '/VmSize/ {print $2}' < /proc/$PROCESS_PID/status` if [ "$VM_SIZE.X" = ".X" ]; then continue fi VM_RSS=`awk '/VmRSS/ {print $2}' < /proc/$PROCESS_PID/status` if [ "$VM_RSS.X" = ".X" ]; then continue fi
echo "$ELAPSED_TIME,$VM_SIZE,$VM_RSS" >> $LOG_FILE sleep $PERIOD VM_SIZE="" VM_RSS="" ELAPSED_TIME=`date +%H:%M:%S:%N` else echo "$1 is no longer a running process" exit 0 fi done
保存为memcheck, 然后chmod 755 memcheck改变其可执行属性。
首先运行./memcheck ns 接着启动某个模拟进程 ./ns xxx.tcl 运行完了ns会自动退出,memcheck也会退出,只要查看memusage.log内容即可。
给出我运行的例子:
putty窗口1:fang@ns-serv2:~$ ./memcheck ns 等待...
putty窗口2:fang@ns-serv2:~/ns-allinone-2.31/ns-2.31$ ./ns tcl/ex/simple-wireless.tcl num_nodes is set 2 warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl INITIALIZE THE LIST xListHead Starting Simulation... channel.cc:sendUp - Calc highestAntennaZ_ and distCST_ highestAntennaZ_ = 1.5, distCST_ = 550.0 SORTING LISTS ...DONE! NS EXITING...
putty窗口1:fang@ns-serv2:~$ ./memcheck ns ns is no longer a running process
putty窗口1:fang@ns-serv2:~$ cat memusage.log ElapsedTime,VmSize,VmRSS 00:25:47:094364000,11468,6232
单位为kB
按照这里的解释:
任务虚拟地址空间的大小 VmSize 应用程序正在使用的物理内存的大小 VmRSS |
|
|
|