AttachDetachRTCTest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 #
4 ## AttachDetachRTCTest.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 
22 ns = env.name_space['localhost:9898']
23 
24 time.sleep(2)
25 
26 compo1 = ns.rtc_handles["ConsoleIn0.rtc"]
27 compo0 = ns.rtc_handles["ConsoleOut0.rtc"]
28 seqin0 = ns.rtc_handles["SequenceInComponent0.rtc"]
29 
30 ec = compo0.rtc_ref.get_owned_contexts()
31 
32 def mem_rss():
33  (stat, output) = commands.getstatusoutput("ps alxww | grep \"[r]\"tcd")
34  return output.split()[7]
35 
36 ## file and console out
37 def print_file_and_cons(out_data, out_flag=0):
38  ## out_flag:1 is file out only
39  if out_flag == 1:
40  fout.write(out_data + '\n')
41  fout.flush()
42  ## out_flag:2 is console out only
43  elif out_flag == 2:
44  print out_data
45  ## out_flag:0 is console and file out (default)
46  else:
47  print out_data
48  fout.write(out_data + '\n')
49  fout.flush()
50  return
51 
52 ## memory leak check
53 def leak_check(rss_start, rss_end):
54  if rss_start != rss_end:
55  fodat = " result: memory leak was found !!!"
56  else:
57  fodat = " result: memory leak was not found."
58  print_file_and_cons(fodat)
59  return
60 
61 ## file out setting
62 test_case = "AttachDetachRTCTest"
63 fout = open(test_case + ".log", 'w')
64 
65 fodat = "=== " + test_case + " start ==="
67 
68 loop_cnt = 1000
69 ## -----------------------------------------------------------------------------
70 fodat = "attach_context() and detach_context()"
72 
73 for i in range(loop_cnt):
74  # LightweightRTObject::attach_context(in ExecutionContext exec_context)
75  ec_id = compo0.rtc_ref.attach_context(ec[0]) # set used OK. single use NG.
76  #print "attach_context() ret=",ec_id
77 
78  # LightweightRTObject::detach_context(in ExecutionContextHandle_t exec_handle)
79  retcode = compo0.rtc_ref.detach_context(ec_id)
80  #print "detach_context() ret=",retcode
81 
82  if i == 0:
83  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
84  fodat = " %05d: %s KB start" % (1, rss0)
85  print_file_and_cons(fodat,1)
86  rss1 = mem_rss() ; j1 = i
87  if rss0 != rss1:
88  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
89  print_file_and_cons(fodat,1)
90  rss0 = rss1 ; j0 = j1
91 
92 rssEnd = mem_rss()
93 fodat = " %05d: %s KB end" % (i+1, rssEnd)
94 print_file_and_cons(fodat,1)
95 leak_check(rssStart, rssEnd)
96 ## -----------------------------------------------------------------------------
97 
98 fodat = "=== " + test_case + " end ==="
100 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