AddRemoveRTCTest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: euc-jp -*-
00003 #
00004 ## AddRemoveRTCTest.py
00005 ##
00006 ## メモリーリークチェック
00007 ## RTC.idlで定義されているオペレーション
00008 ## RTCの追加・削除に関するオペレーション
00009 #
00010 # $Id: AddRemoveRTCTest.py 1541 2009-08-31 07:21:12Z hakuta $
00011 #
00012 
00013 from rtc_handle import *
00014 from BasicDataType_idl import *
00015 import time
00016 import commands
00017 
00018 env = RtmEnv(sys.argv, ["localhost:9898"])
00019 list0 = env.name_space["localhost:9898"].list_obj()
00020 env.name_space['localhost:9898'].rtc_handles.keys()
00021 ns = env.name_space['localhost:9898']
00022 
00023 time.sleep(2)
00024 
00025 compo0 = ns.rtc_handles["ConsoleIn0.rtc"]
00026 seqin0 = ns.rtc_handles["SequenceInComponent0.rtc"]
00027 
00028 ec = compo0.rtc_ref.get_owned_contexts()
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 = "AddRemoveRTCTest"
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 = "add_component() and remove_component()"
00069 print_file_and_cons(fodat)
00070 
00071 for i in range(loop_cnt):
00072     # ExecutionContext::add_component(in LightweightRTObject comp)
00073     retcode = ec[0].add_component(seqin0.rtc_ref)
00074 
00075     # ExecutionContext::remove_component(in LightweightRTObject comp)
00076     retcode = ec[0].remove_component(seqin0.rtc_ref)
00077 
00078     if i == 0:
00079         rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
00080         fodat = "   %05d: %s KB start" % (1, rss0)
00081         print_file_and_cons(fodat,1)
00082     rss1 = mem_rss() ; j1 = i
00083     if rss0 != rss1:
00084         fodat = "   %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
00085         print_file_and_cons(fodat,1)
00086         rss0 = rss1 ; j0 = j1
00087 
00088 rssEnd = mem_rss()
00089 fodat = "   %05d: %s KB end" % (i+1, rssEnd)
00090 print_file_and_cons(fodat,1)
00091 leak_check(rssStart, rssEnd)
00092 ## -----------------------------------------------------------------------------
00093 
00094 fodat = "=== " + test_case + " end ==="
00095 print_file_and_cons(fodat)
00096 fout.close()


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