CreateDeleteRTCTest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 #
00004 ## CreateDeleteRTCTest.py
00005 ##
00006 ## メモリーリークチェック
00007 ## Manager.idlで定義されているオペレーション
00008 ## ステートフルなオペレーション
00009 #
00010 # $Id: CreateDeleteRTCTest.py 1541 2009-08-31 07:21:12Z hakuta $
00011 #
00012 
00013 from rtc_handle import *
00014 from BasicDataType_idl import *
00015 from CorbaNaming import *
00016 import time
00017 import commands
00018 import socket
00019 import RTM
00020 
00021 env = RtmEnv(sys.argv, ["localhost:9898"])
00022 
00023 mgr_name=socket.gethostname()+".host_cxt/manager.mgr"
00024 naming = CorbaNaming(env.orb,"localhost:9898")
00025 manager = naming.resolve(mgr_name)._narrow(RTM.Manager)
00026 
00027 time.sleep(2)
00028 
00029 def mem_rss():
00030     (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
00031     return output.split()[7]
00032 
00033 ## file and console out
00034 def print_file_and_cons(out_data, out_flag=0):
00035     ## out_flag:1 is file out only
00036     if out_flag == 1:
00037       fout.write(out_data + '\n')
00038       fout.flush()
00039     ## out_flag:2 is console out only
00040     elif out_flag == 2:
00041       print out_data
00042     ## out_flag:0 is console and file out (default)
00043     else:
00044       print out_data
00045       fout.write(out_data + '\n')
00046       fout.flush()
00047     return
00048 
00049 ## memory leak check
00050 def leak_check(rss_start, rss_end):
00051     if rss_start != rss_end:
00052         fodat = "  result: memory leak was found !!!"
00053     else:
00054         fodat = "  result: memory leak was not found."
00055     print_file_and_cons(fodat)
00056     return
00057 
00058 ## file out setting
00059 test_case = "CreateDeleteRTCTest"
00060 fout = open(test_case + ".log", 'w')
00061 
00062 fodat = "=== " + test_case + " start ==="
00063 print_file_and_cons(fodat)
00064 
00065 loop_cnt = 1000
00066 ## -----------------------------------------------------------------------------
00067 fodat = "load_module() and unload_module()"
00068 print_file_and_cons(fodat)
00069 
00070 for i in range(loop_cnt):
00071     ## Manager::unload_module(in string pathname);
00072     try:
00073         #retcode = manager.unload_module(".//ConsoleIn.so")
00074         retcode = manager.unload_module(".//ConsoleOut.so")
00075     except:
00076         pass
00077     #print "unload_module() ret=",retcode
00078 
00079     ## Manager::load_module(in string pathname, in string initfunc); 
00080     #retcode = manager.load_module("ConsoleIn.so", "ConsoleInInit")
00081     retcode = manager.load_module("ConsoleOut.so", "ConsoleOutInit")
00082     #print "load_module()   ret=",retcode
00083 
00084     if i == 0:
00085         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00086         fodat = "   %05d: %s KB start" % (1, rss0)
00087         print_file_and_cons(fodat,1)
00088     rss1 = mem_rss() ; j1 = i
00089     if rss0 != rss1:
00090         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00091         print_file_and_cons(fodat,1)
00092         rss0 = rss1 ; j0 = j1
00093 
00094 rssEnd = mem_rss()
00095 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00096 print_file_and_cons(fodat,1)
00097 leak_check(rssStart, rssEnd)
00098 ## -----------------------------------------------------------------------------
00099 fodat = "create_component() and delete_component()"
00100 print_file_and_cons(fodat)
00101 
00102 for i in range(loop_cnt):
00103     ## Manager::delete_component(in string instance_name);
00104     ret0 = manager.delete_component("ConsoleOut0")
00105     #ret0 = manager.delete_component("ConsoleIn0")
00106     #print "  delete_comp() ret=",ret0
00107 
00108     ## Manager::create_component(in string module_name); 
00109     obj0 = manager.create_component("ConsoleOut")
00110     #obj0 = manager.create_component("ConsoleIn")
00111     #print "  create_comp() ret_Ref=",obj0
00112 
00113     if i == 0:
00114         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00115         fodat = "   %05d: %s KB start" % (1, rss0)
00116         print_file_and_cons(fodat,1)
00117     rss1 = mem_rss() ; j1 = i
00118     if rss0 != rss1:
00119         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00120         print_file_and_cons(fodat,1)
00121         rss0 = rss1 ; j0 = j1
00122 
00123 rssEnd = mem_rss()
00124 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00125 print_file_and_cons(fodat,1)
00126 leak_check(rssStart, rssEnd)
00127 ## -----------------------------------------------------------------------------
00128 
00129 fodat = "=== " + test_case + " end ==="
00130 print_file_and_cons(fodat)
00131 fout.close()
00132 
00133 manager.delete_component("ConsoleOut0")
00134 #manager.delete_component("ConsoleIn0")
00135 #retcode = manager.unload_module(".//ConsoleOut.so")


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:03