ManagerTest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- coding: euc-jp -*-
3 #
4 ## ManagerTest.py
5 
12 
13 from rtc_handle import *
14 from BasicDataType_idl import *
15 from CorbaNaming import *
16 import time
17 import commands
18 import socket
19 import RTM
20 
21 
22 
23 env = RtmEnv(sys.argv, ["localhost:9898"])
24 mgr_name=socket.gethostname()+".host_cxt/manager.mgr"
25 naming = CorbaNaming(env.orb,"localhost:9898")
26 manager = naming.resolve(mgr_name)._narrow(RTM.Manager)
27 
28 time.sleep(2)
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 = "ManagerTest"
61 fout = open(test_case + ".log", 'w')
62 
63 fodat = "=== " + test_case + " start ==="
65 
66 loop_cnt = 1000
67 ## -----------------------------------------------------------------------------
68 fodat = "get_loadable_modules()"
70 
71 for i in range(loop_cnt):
72  ## Manager::get_loadable_modules();
73  manager.get_loadable_modules()
74 
75  if i == 0:
76  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
77  fodat = " %05d: %s KB start" % (1, rss0)
78  print_file_and_cons(fodat,1)
79  rss1 = mem_rss() ; j1 = i
80  if rss0 != rss1:
81  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
82  print_file_and_cons(fodat,1)
83  rss0 = rss1 ; j0 = j1
84 
85 rssEnd = mem_rss()
86 fodat = " %05d: %s KB end" % (i+1, rssEnd)
87 print_file_and_cons(fodat,1)
88 leak_check(rssStart, rssEnd)
89 ## -----------------------------------------------------------------------------
90 fodat = "get_loaded_modules()"
92 
93 for i in range(loop_cnt):
94  ## Manager::get_loaded_modules();
95  manager.get_loaded_modules()
96 
97  if i == 0:
98  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
99  fodat = " %05d: %s KB start" % (1, rss0)
100  print_file_and_cons(fodat,1)
101  rss1 = mem_rss() ; j1 = i
102  if rss0 != rss1:
103  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
104  print_file_and_cons(fodat,1)
105  rss0 = rss1 ; j0 = j1
106 
107 rssEnd = mem_rss()
108 fodat = " %05d: %s KB end" % (i+1, rssEnd)
109 print_file_and_cons(fodat,1)
110 leak_check(rssStart, rssEnd)
111 ## -----------------------------------------------------------------------------
112 fodat = "get_factory_profiles()"
113 print_file_and_cons(fodat)
114 
115 for i in range(loop_cnt):
116  ## Manager::get_factory_profiles();
117  manager.get_factory_profiles()
118 
119  if i == 0:
120  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
121  fodat = " %05d: %s KB start" % (1, rss0)
122  print_file_and_cons(fodat,1)
123  rss1 = mem_rss() ; j1 = i
124  if rss0 != rss1:
125  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
126  print_file_and_cons(fodat,1)
127  rss0 = rss1 ; j0 = j1
128 
129 rssEnd = mem_rss()
130 fodat = " %05d: %s KB end" % (i+1, rssEnd)
131 print_file_and_cons(fodat,1)
132 leak_check(rssStart, rssEnd)
133 ## -----------------------------------------------------------------------------
134 fodat = "get_components()"
135 print_file_and_cons(fodat)
136 
137 for i in range(loop_cnt):
138  ## Manager::get_components();
139  manager.get_components()
140 
141  if i == 0:
142  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
143  fodat = " %05d: %s KB start" % (1, rss0)
144  print_file_and_cons(fodat,1)
145  rss1 = mem_rss() ; j1 = i
146  if rss0 != rss1:
147  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
148  print_file_and_cons(fodat,1)
149  rss0 = rss1 ; j0 = j1
150 
151 rssEnd = mem_rss()
152 fodat = " %05d: %s KB end" % (i+1, rssEnd)
153 print_file_and_cons(fodat,1)
154 leak_check(rssStart, rssEnd)
155 ## -----------------------------------------------------------------------------
156 fodat = "get_component_profiles()"
157 print_file_and_cons(fodat)
158 
159 for i in range(loop_cnt):
160  ## Manager::get_component_profiles();
161  manager.get_component_profiles()
162 
163  if i == 0:
164  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
165  fodat = " %05d: %s KB start" % (1, rss0)
166  print_file_and_cons(fodat,1)
167  rss1 = mem_rss() ; j1 = i
168  if rss0 != rss1:
169  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
170  print_file_and_cons(fodat,1)
171  rss0 = rss1 ; j0 = j1
172 
173 rssEnd = mem_rss()
174 fodat = " %05d: %s KB end" % (i+1, rssEnd)
175 print_file_and_cons(fodat,1)
176 leak_check(rssStart, rssEnd)
177 ## -----------------------------------------------------------------------------
178 fodat = "get_profile()"
179 print_file_and_cons(fodat)
180 
181 for i in range(loop_cnt):
182  ## Manager::get_profile();
183  manager.get_profile()
184 
185  if i == 0:
186  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
187  fodat = " %05d: %s KB start" % (1, rss0)
188  print_file_and_cons(fodat,1)
189  rss1 = mem_rss() ; j1 = i
190  if rss0 != rss1:
191  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
192  print_file_and_cons(fodat,1)
193  rss0 = rss1 ; j0 = j1
194 
195 rssEnd = mem_rss()
196 fodat = " %05d: %s KB end" % (i+1, rssEnd)
197 print_file_and_cons(fodat,1)
198 leak_check(rssStart, rssEnd)
199 ## -----------------------------------------------------------------------------
200 fodat = "get_configuration()"
201 print_file_and_cons(fodat)
202 
203 for i in range(loop_cnt):
204  ## Manager::get_configuration();
205  manager.get_configuration()
206 
207  if i == 0:
208  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
209  fodat = " %05d: %s KB start" % (1, rss0)
210  print_file_and_cons(fodat,1)
211  rss1 = mem_rss() ; j1 = i
212  if rss0 != rss1:
213  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
214  print_file_and_cons(fodat,1)
215  rss0 = rss1 ; j0 = j1
216 
217 rssEnd = mem_rss()
218 fodat = " %05d: %s KB end" % (i+1, rssEnd)
219 print_file_and_cons(fodat,1)
220 leak_check(rssStart, rssEnd)
221 ## -----------------------------------------------------------------------------
222 fodat = "set_configuration()"
223 print_file_and_cons(fodat)
224 
225 for i in range(loop_cnt):
226  ## Manager::set_configuration(in string name, in string value);
227  manager.set_configuration("module.load_path", "./")
228 
229  if i == 0:
230  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
231  fodat = " %05d: %s KB start" % (1, rss0)
232  print_file_and_cons(fodat,1)
233  rss1 = mem_rss() ; j1 = i
234  if rss0 != rss1:
235  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
236  print_file_and_cons(fodat,1)
237  rss0 = rss1 ; j0 = j1
238 
239 rssEnd = mem_rss()
240 fodat = " %05d: %s KB end" % (i+1, rssEnd)
241 print_file_and_cons(fodat,1)
242 leak_check(rssStart, rssEnd)
243 ## -----------------------------------------------------------------------------
244 ##fodat = "get_owner()"
245 ##print_file_and_cons(fodat)
246 
332 fodat = "fork()"
333 print_file_and_cons(fodat)
334 
335 for i in range(loop_cnt):
336  ## Manager::fork();
337  manager.fork()
338 
339  if i == 0:
340  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
341  fodat = " %05d: %s KB start" % (1, rss0)
342  print_file_and_cons(fodat,1)
343  rss1 = mem_rss() ; j1 = i
344  if rss0 != rss1:
345  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
346  print_file_and_cons(fodat,1)
347  rss0 = rss1 ; j0 = j1
348 
349 rssEnd = mem_rss()
350 fodat = " %05d: %s KB end" % (i+1, rssEnd)
351 print_file_and_cons(fodat,1)
352 leak_check(rssStart, rssEnd)
353 ## -----------------------------------------------------------------------------
354 ##fodat = "shutdown()"
355 ##print_file_and_cons(fodat)
356 
376 fodat = "restart()"
377 print_file_and_cons(fodat)
378 
379 for i in range(loop_cnt):
380  ## Manager::restart();
381  manager.restart()
382 
383  if i == 0:
384  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
385  fodat = " %05d: %s KB start" % (1, rss0)
386  print_file_and_cons(fodat,1)
387  rss1 = mem_rss() ; j1 = i
388  if rss0 != rss1:
389  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
390  print_file_and_cons(fodat,1)
391  rss0 = rss1 ; j0 = j1
392 
393 rssEnd = mem_rss()
394 fodat = " %05d: %s KB end" % (i+1, rssEnd)
395 print_file_and_cons(fodat,1)
396 leak_check(rssStart, rssEnd)
397 ## -----------------------------------------------------------------------------
398 fodat = "get_service()"
399 print_file_and_cons(fodat)
400 
401 for i in range(loop_cnt):
402  ## Manager::get_service(in string name);
403  manager.get_service("test")
404 
405  if i == 0:
406  rss0 = mem_rss() ; j0 = 0 ; rssStart = rss0
407  fodat = " %05d: %s KB start" % (1, rss0)
408  print_file_and_cons(fodat,1)
409  rss1 = mem_rss() ; j1 = i
410  if rss0 != rss1:
411  fodat = " %05d: %s KB -> %d KB. count diff -> %d" % (i+1, rss1,int(rss1)-int(rss0),int(j1)-int(j0) )
412  print_file_and_cons(fodat,1)
413  rss0 = rss1 ; j0 = j1
414 
415 rssEnd = mem_rss()
416 fodat = " %05d: %s KB end" % (i+1, rssEnd)
417 print_file_and_cons(fodat,1)
418 leak_check(rssStart, rssEnd)
419 ## -----------------------------------------------------------------------------
420 
421 fodat = "=== " + test_case + " end ==="
422 print_file_and_cons(fodat)
423 fout.close()
def mem_rss()
Definition: ManagerTest.py:30
def print_file_and_cons(out_data, out_flag=0)
file and console out
Definition: ManagerTest.py:35
def leak_check(rss_start, rss_end)
memory leak check
Definition: ManagerTest.py:51


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:25:58