AddRemoveRTCTest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 #
4 ## AddRemoveRTCTest.py
5 
12 
13 from rtc_handle import *
14 from BasicDataType_idl import *
15 import time
16 import commands
17 
18 env = RtmEnv(sys.argv, ["localhost:9898"])
19 list0 = env.name_space["localhost:9898"].list_obj()
20 env.name_space['localhost:9898'].rtc_handles.keys()
21 ns = env.name_space['localhost:9898']
22 
23 time.sleep(2)
24 
25 compo0 = ns.rtc_handles["ConsoleIn0.rtc"]
26 seqin0 = ns.rtc_handles["SequenceInComponent0.rtc"]
27 
28 ec = compo0.rtc_ref.get_owned_contexts()
29 
30 def mem_rss():
31  (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
32  return output.split()[7]
33 
34 ## file and console out
35 def print_file_and_cons(out_data, out_flag=0):
36  ## out_flag:1 is file out only
37  if out_flag == 1:
38  fout.write(out_data + '\n')
39  fout.flush()
40  ## out_flag:2 is console out only
41  elif out_flag == 2:
42  print out_data
43  ## out_flag:0 is console and file out (default)
44  else:
45  print out_data
46  fout.write(out_data + '\n')
47  fout.flush()
48  return
49 
50 ## memory leak check
51 def leak_check(rss_start, rss_end):
52  if rss_start != rss_end:
53  fodat = " result: memory leak was found !!!"
54  else:
55  fodat = " result: memory leak was not found."
56  print_file_and_cons(fodat)
57  return
58 
59 ## file out setting
60 test_case = "AddRemoveRTCTest"
61 fout = open(test_case + ".log", 'w')
62 
63 fodat = "=== " + test_case + " start ==="
65 
66 loop_cnt = 1000
67 ## -----------------------------------------------------------------------------
68 fodat = "add_component() and remove_component()"
70 
71 for i in range(loop_cnt):
72  # ExecutionContext::add_component(in LightweightRTObject comp)
73  retcode = ec[0].add_component(seqin0.rtc_ref)
74 
75  # ExecutionContext::remove_component(in LightweightRTObject comp)
76  retcode = ec[0].remove_component(seqin0.rtc_ref)
77 
78  if i == 0:
79  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
80  fodat = " %05d: %s KB start" % (1, rss0)
81  print_file_and_cons(fodat,1)
82  rss1 = mem_rss() ; j1 = i
83  if rss0 != rss1:
84  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
85  print_file_and_cons(fodat,1)
86  rss0 = rss1 ; j0 = j1
87 
88 rssEnd = mem_rss()
89 fodat = " %05d: %s KB end" % (i+1, rssEnd)
90 print_file_and_cons(fodat,1)
91 leak_check(rssStart, rssEnd)
92 ## -----------------------------------------------------------------------------
93 
94 fodat = "=== " + test_case + " end ==="
96 fout.close()
def print_file_and_cons(out_data, out_flag=0)
file and console out
def leak_check(rss_start, rss_end)
memory leak check


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:50