ManagerTest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 #
00004 ## ManagerTest.py
00005 ##
00006 ## メモリーリークチェック
00007 ## Manager.idlで定義されているオペレーション
00008 ## ステートレスなオペレーション
00009 #
00010 # $Id: ManagerTest.py 1824 2010-01-28 01:51:44Z 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 
00022 
00023 env = RtmEnv(sys.argv, ["localhost:9898"])
00024 mgr_name=socket.gethostname()+".host_cxt/manager.mgr" 
00025 naming = CorbaNaming(env.orb,"localhost:9898")
00026 manager = naming.resolve(mgr_name)._narrow(RTM.Manager)
00027 
00028 time.sleep(2)
00029 
00030 def mem_rss():
00031     (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
00032     return output.split()[7]
00033 
00034 ## file and console out
00035 def print_file_and_cons(out_data, out_flag=0):
00036     ## out_flag:1 is file out only
00037     if out_flag == 1:
00038       fout.write(out_data + '\n')
00039       fout.flush()
00040     ## out_flag:2 is console out only
00041     elif out_flag == 2:
00042       print out_data
00043     ## out_flag:0 is console and file out (default)
00044     else:
00045       print out_data
00046       fout.write(out_data + '\n')
00047       fout.flush()
00048     return
00049 
00050 ## memory leak check
00051 def leak_check(rss_start, rss_end):
00052     if rss_start != rss_end:
00053         fodat = "  result: memory leak was found !!!"
00054     else:
00055         fodat = "  result: memory leak was not found."
00056     print_file_and_cons(fodat)
00057     return
00058 
00059 ## file out setting
00060 test_case = "ManagerTest"
00061 fout = open(test_case + ".log", 'w')
00062 
00063 fodat = "=== " + test_case + " start ==="
00064 print_file_and_cons(fodat)
00065 
00066 loop_cnt = 1000
00067 ## -----------------------------------------------------------------------------
00068 fodat = "get_loadable_modules()"
00069 print_file_and_cons(fodat)
00070 
00071 for i in range(loop_cnt):
00072     ## Manager::get_loadable_modules(); 
00073     manager.get_loadable_modules()
00074 
00075     if i == 0:
00076         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00077         fodat = "   %05d: %s KB start" % (1, rss0)
00078         print_file_and_cons(fodat,1)
00079     rss1 = mem_rss() ; j1 = i
00080     if rss0 != rss1:
00081         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00082         print_file_and_cons(fodat,1)
00083         rss0 = rss1 ; j0 = j1
00084 
00085 rssEnd = mem_rss()
00086 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00087 print_file_and_cons(fodat,1)
00088 leak_check(rssStart, rssEnd)
00089 ## -----------------------------------------------------------------------------
00090 fodat = "get_loaded_modules()"
00091 print_file_and_cons(fodat)
00092 
00093 for i in range(loop_cnt):
00094     ## Manager::get_loaded_modules(); 
00095     manager.get_loaded_modules()
00096 
00097     if i == 0:
00098         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00099         fodat = "   %05d: %s KB start" % (1, rss0)
00100         print_file_and_cons(fodat,1)
00101     rss1 = mem_rss() ; j1 = i
00102     if rss0 != rss1:
00103         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00104         print_file_and_cons(fodat,1)
00105         rss0 = rss1 ; j0 = j1
00106 
00107 rssEnd = mem_rss()
00108 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00109 print_file_and_cons(fodat,1)
00110 leak_check(rssStart, rssEnd)
00111 ## -----------------------------------------------------------------------------
00112 fodat = "get_factory_profiles()"
00113 print_file_and_cons(fodat)
00114 
00115 for i in range(loop_cnt):
00116     ## Manager::get_factory_profiles(); 
00117     manager.get_factory_profiles()
00118 
00119     if i == 0:
00120         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00121         fodat = "   %05d: %s KB start" % (1, rss0)
00122         print_file_and_cons(fodat,1)
00123     rss1 = mem_rss() ; j1 = i
00124     if rss0 != rss1:
00125         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00126         print_file_and_cons(fodat,1)
00127         rss0 = rss1 ; j0 = j1
00128 
00129 rssEnd = mem_rss()
00130 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00131 print_file_and_cons(fodat,1)
00132 leak_check(rssStart, rssEnd)
00133 ## -----------------------------------------------------------------------------
00134 fodat = "get_components()"
00135 print_file_and_cons(fodat)
00136 
00137 for i in range(loop_cnt):
00138     ## Manager::get_components(); 
00139     manager.get_components()
00140 
00141     if i == 0:
00142         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00143         fodat = "   %05d: %s KB start" % (1, rss0)
00144         print_file_and_cons(fodat,1)
00145     rss1 = mem_rss() ; j1 = i
00146     if rss0 != rss1:
00147         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00148         print_file_and_cons(fodat,1)
00149         rss0 = rss1 ; j0 = j1
00150 
00151 rssEnd = mem_rss()
00152 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00153 print_file_and_cons(fodat,1)
00154 leak_check(rssStart, rssEnd)
00155 ## -----------------------------------------------------------------------------
00156 fodat = "get_component_profiles()"
00157 print_file_and_cons(fodat)
00158 
00159 for i in range(loop_cnt):
00160     ## Manager::get_component_profiles(); 
00161     manager.get_component_profiles()
00162 
00163     if i == 0:
00164         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00165         fodat = "   %05d: %s KB start" % (1, rss0)
00166         print_file_and_cons(fodat,1)
00167     rss1 = mem_rss() ; j1 = i
00168     if rss0 != rss1:
00169         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00170         print_file_and_cons(fodat,1)
00171         rss0 = rss1 ; j0 = j1
00172 
00173 rssEnd = mem_rss()
00174 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00175 print_file_and_cons(fodat,1)
00176 leak_check(rssStart, rssEnd)
00177 ## -----------------------------------------------------------------------------
00178 fodat = "get_profile()"
00179 print_file_and_cons(fodat)
00180 
00181 for i in range(loop_cnt):
00182     ## Manager::get_profile(); 
00183     manager.get_profile()
00184 
00185     if i == 0:
00186         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00187         fodat = "   %05d: %s KB start" % (1, rss0)
00188         print_file_and_cons(fodat,1)
00189     rss1 = mem_rss() ; j1 = i
00190     if rss0 != rss1:
00191         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00192         print_file_and_cons(fodat,1)
00193         rss0 = rss1 ; j0 = j1
00194 
00195 rssEnd = mem_rss()
00196 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00197 print_file_and_cons(fodat,1)
00198 leak_check(rssStart, rssEnd)
00199 ## -----------------------------------------------------------------------------
00200 fodat = "get_configuration()"
00201 print_file_and_cons(fodat)
00202 
00203 for i in range(loop_cnt):
00204     ## Manager::get_configuration(); 
00205     manager.get_configuration()
00206 
00207     if i == 0:
00208         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00209         fodat = "   %05d: %s KB start" % (1, rss0)
00210         print_file_and_cons(fodat,1)
00211     rss1 = mem_rss() ; j1 = i
00212     if rss0 != rss1:
00213         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00214         print_file_and_cons(fodat,1)
00215         rss0 = rss1 ; j0 = j1
00216 
00217 rssEnd = mem_rss()
00218 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00219 print_file_and_cons(fodat,1)
00220 leak_check(rssStart, rssEnd)
00221 ## -----------------------------------------------------------------------------
00222 fodat = "set_configuration()"
00223 print_file_and_cons(fodat)
00224 
00225 for i in range(loop_cnt):
00226     ## Manager::set_configuration(in string name, in string value); 
00227     manager.set_configuration("module.load_path", "./")
00228 
00229     if i == 0:
00230         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00231         fodat = "   %05d: %s KB start" % (1, rss0)
00232         print_file_and_cons(fodat,1)
00233     rss1 = mem_rss() ; j1 = i
00234     if rss0 != rss1:
00235         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00236         print_file_and_cons(fodat,1)
00237         rss0 = rss1 ; j0 = j1
00238 
00239 rssEnd = mem_rss()
00240 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00241 print_file_and_cons(fodat,1)
00242 leak_check(rssStart, rssEnd)
00243 ## -----------------------------------------------------------------------------
00244 ##fodat = "get_owner()"
00245 ##print_file_and_cons(fodat)
00246 ##
00247 ##for i in range(loop_cnt):
00248 ##    ## Manager::get_owner(); 
00249 ##    manager.get_owner()
00250 ##
00251 ##    if i == 0:
00252 ##        rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00253 ##        fodat = "   %05d: %s KB start" % (1, rss0)
00254 ##        print_file_and_cons(fodat,1)
00255 ##    rss1 = mem_rss() ; j1 = i
00256 ##    if rss0 != rss1:
00257 ##        fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00258 ##        print_file_and_cons(fodat,1)
00259 ##        rss0 = rss1 ; j0 = j1
00260 ##
00261 ##rssEnd = mem_rss()
00262 ##fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00263 ##print_file_and_cons(fodat,1)
00264 ##leak_check(rssStart, rssEnd)
00265 ## -----------------------------------------------------------------------------
00266 ##fodat = "set_owner()"
00267 ##print_file_and_cons(fodat)
00268 ##
00269 ##for i in range(loop_cnt):
00270 ##    ## Manager::set_owner(in Manager mgr); 
00271 ##    manager.set_owner(manager)
00272 ##
00273 ##    if i == 0:
00274 ##        rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00275 ##        fodat = "   %05d: %s KB start" % (1, rss0)
00276 ##        print_file_and_cons(fodat,1)
00277 ##    rss1 = mem_rss() ; j1 = i
00278 ##    if rss0 != rss1:
00279 ##        fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00280 ##        print_file_and_cons(fodat,1)
00281 ##        rss0 = rss1 ; j0 = j1
00282 ##
00283 ##rssEnd = mem_rss()
00284 ##fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00285 ##print_file_and_cons(fodat,1)
00286 ##leak_check(rssStart, rssEnd)
00287 ## -----------------------------------------------------------------------------
00288 ##fodat = "get_child()"
00289 ##print_file_and_cons(fodat)
00290 ##
00291 ##for i in range(loop_cnt):
00292 ##    ## Manager::get_child(); 
00293 ##    manager.get_child()
00294 ##
00295 ##    if i == 0:
00296 ##        rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00297 ##        fodat = "   %05d: %s KB start" % (1, rss0)
00298 ##        print_file_and_cons(fodat,1)
00299 ##    rss1 = mem_rss() ; j1 = i
00300 ##    if rss0 != rss1:
00301 ##        fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00302 ##        print_file_and_cons(fodat,1)
00303 ##        rss0 = rss1 ; j0 = j1
00304 ##
00305 ##rssEnd = mem_rss()
00306 ##fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00307 ##print_file_and_cons(fodat,1)
00308 ##leak_check(rssStart, rssEnd)
00309 ## -----------------------------------------------------------------------------
00310 ##fodat = "set_child()"
00311 ##print_file_and_cons(fodat)
00312 ##
00313 ##for i in range(loop_cnt):
00314 ##    ## Manager::set_child(in Manager mgr); 
00315 ##    manager.set_child(manager)
00316 ##
00317 ##    if i == 0:
00318 ##        rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00319 ##        fodat = "   %05d: %s KB start" % (1, rss0)
00320 ##        print_file_and_cons(fodat,1)
00321 ##    rss1 = mem_rss() ; j1 = i
00322 ##    if rss0 != rss1:
00323 ##        fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00324 ##        print_file_and_cons(fodat,1)
00325 ##        rss0 = rss1 ; j0 = j1
00326 ##
00327 ##rssEnd = mem_rss()
00328 ##fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00329 ##print_file_and_cons(fodat,1)
00330 ##leak_check(rssStart, rssEnd)
00331 ## -----------------------------------------------------------------------------
00332 fodat = "fork()"
00333 print_file_and_cons(fodat)
00334 
00335 for i in range(loop_cnt):
00336     ## Manager::fork(); 
00337     manager.fork()
00338 
00339     if i == 0:
00340         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00341         fodat = "   %05d: %s KB start" % (1, rss0)
00342         print_file_and_cons(fodat,1)
00343     rss1 = mem_rss() ; j1 = i
00344     if rss0 != rss1:
00345         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00346         print_file_and_cons(fodat,1)
00347         rss0 = rss1 ; j0 = j1
00348 
00349 rssEnd = mem_rss()
00350 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00351 print_file_and_cons(fodat,1)
00352 leak_check(rssStart, rssEnd)
00353 ## -----------------------------------------------------------------------------
00354 ##fodat = "shutdown()"
00355 ##print_file_and_cons(fodat)
00356 ##
00357 ##for i in range(loop_cnt):
00358 ##    ## Manager::shutdown(); 
00359 ##    ###manager.shutdown()             # can't test, because manager is destroyed.
00360 ##
00361 ##    if i == 0:
00362 ##        rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00363 ##        fodat = "   %05d: %s KB start" % (1, rss0)
00364 ##        print_file_and_cons(fodat,1)
00365 ##    rss1 = mem_rss() ; j1 = i
00366 ##    if rss0 != rss1:
00367 ##        fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00368 ##        print_file_and_cons(fodat,1)
00369 ##        rss0 = rss1 ; j0 = j1
00370 ##
00371 ##rssEnd = mem_rss()
00372 ##fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00373 ##print_file_and_cons(fodat,1)
00374 ##leak_check(rssStart, rssEnd)
00375 ## -----------------------------------------------------------------------------
00376 fodat = "restart()"
00377 print_file_and_cons(fodat)
00378 
00379 for i in range(loop_cnt):
00380     ## Manager::restart(); 
00381     manager.restart()
00382 
00383     if i == 0:
00384         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00385         fodat = "   %05d: %s KB start" % (1, rss0)
00386         print_file_and_cons(fodat,1)
00387     rss1 = mem_rss() ; j1 = i
00388     if rss0 != rss1:
00389         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00390         print_file_and_cons(fodat,1)
00391         rss0 = rss1 ; j0 = j1
00392 
00393 rssEnd = mem_rss()
00394 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00395 print_file_and_cons(fodat,1)
00396 leak_check(rssStart, rssEnd)
00397 ## -----------------------------------------------------------------------------
00398 fodat = "get_service()"
00399 print_file_and_cons(fodat)
00400 
00401 for i in range(loop_cnt):
00402     ## Manager::get_service(in string name);
00403     manager.get_service("test")
00404 
00405     if i == 0:
00406         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00407         fodat = "   %05d: %s KB start" % (1, rss0)
00408         print_file_and_cons(fodat,1)
00409     rss1 = mem_rss() ; j1 = i
00410     if rss0 != rss1:
00411         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00412         print_file_and_cons(fodat,1)
00413         rss0 = rss1 ; j0 = j1
00414 
00415 rssEnd = mem_rss()
00416 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00417 print_file_and_cons(fodat,1)
00418 leak_check(rssStart, rssEnd)
00419 ## -----------------------------------------------------------------------------
00420 
00421 fodat = "=== " + test_case + " end ==="
00422 print_file_and_cons(fodat)
00423 fout.close()


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:38