• Home
  • Raw
  • Download

Lines Matching refs:self

194     def __init__(self, root_authority=True):  argument
198 self.hdc_path = hdc_path
199 self.root_authority = root_authority
201 def run_hdc_cmd(self, hdc_args, log_output=True): argument
202 hdc_args = [self.hdc_path] + hdc_args
218 def check_run(self, hdc_args): argument
219 result, out = self.run_hdc_cmd(hdc_args)
224 def _not_use_root(self): argument
225 result, out = self.run_hdc_cmd(['shell', 'whoami'])
229 self.run_hdc_cmd(['unroot'])
231 self.run_hdc_cmd(['wait-for-device'])
233 def switch_root(self): argument
234 if not self.root_authority:
235 self._not_use_root()
237 result, out = self.run_hdc_cmd(['shell', 'whoami'])
242 build_type = self.get_attribute('ro.build.type')
245 self.run_hdc_cmd(['root'])
247 self.run_hdc_cmd(['wait-for-device'])
248 result, out = self.run_hdc_cmd(['shell', 'whoami'])
251 def get_attribute(self, name): argument
252 result, out = self.run_hdc_cmd(['shell', 'getprop',
257 def get_device_architecture(self): argument
258 output = self.check_run(['shell', 'uname', '-m'])
263 def __init__(self, path, lib_name): argument
264 self.path = path
265 self.name = lib_name
270 def __init__(self, device_arch, hdc): argument
271 self.hdc = hdc
272 self.device_arch = device_arch
274 self.build_id_map_of_host = {}
275 self.build_id_map_of_device = {}
276 self.host_lib_count_map = {}
277 self.request_architectures = self.__get_need_architectures(device_arch)
279 def get_host_local_libs(self, local_lib_dir): argument
280 self.build_id_map_of_host.clear()
284 self.__append_host_local_lib(os.path.join(root, name),
287 def get_device_local_libs(self): argument
288 self.build_id_map_of_device.clear()
291 self.hdc.check_run(['shell', 'mkdir', '-p', SYMBOL_FILES_DIR])
292 self.hdc.run_hdc_cmd(['file recv', SYMBOL_FILES_DIR + BUILD_ID_FILE])
299 self.build_id_map_of_device[items[0]] = items[1]
302 def update_device_local_libs(self): argument
304 for build_id in self.build_id_map_of_host:
305 if build_id not in self.build_id_map_of_device:
306 elf_struct = self.build_id_map_of_host[build_id]
307 self.hdc.check_run(['file send', elf_struct.path,
311 for build_id in self.build_id_map_of_device:
312 if build_id not in self.build_id_map_of_host:
313 name = self.build_id_map_of_device[build_id]
314 self.hdc.run_hdc_cmd(['shell', 'rm', SYMBOL_FILES_DIR + name])
318 for build_id in self.build_id_map_of_host:
320 self.build_id_map_of_host[
324 self.hdc.check_run(['file send', BUILD_ID_FILE,
328 def __append_host_local_lib(self, path, name): argument
333 if arch not in self.request_architectures:
336 elf_struct = self.build_id_map_of_host.get(build_id)
338 count = self.host_lib_count_map.get(name, 0)
339 self.host_lib_count_map[name] = count + 1
344 self.build_id_map_of_host[build_id] = ElfStruct(path,
350 def __get_need_architectures(self, device_arch): argument
365 def __init__(self, args, control_module=""): argument
366 self.args = args
367 self.hdc = HdcInterface(root_authority=not args.not_hdc_root)
368 self.device_root = self.hdc.switch_root()
369 self.device_arch = self.hdc.get_device_architecture()
370 self.record_subproc = None
371 self.is_control = bool(control_module)
372 self.control_mode = control_module
374 def profile(self): argument
375 if not self.is_control or self.control_mode == "prepare":
377 self.download()
379 if not self.combine_args():
382 self.exec_control()
383 self.profiling()
385 if not self.is_control:
387 self.get_profiling_data()
388 if self.control_mode == "stop":
389 self.wait_data_generate_done()
392 def download(self): argument
394 if self.args.local_lib_dir:
395 self.download_libs()
397 def download_libs(self): argument
398 executor = LocalLibDownload(self.device_arch, self.hdc)
399 executor.get_host_local_libs(self.args.local_lib_dir)
403 def combine_args(self): argument
404 if self.args.package_name:
405 if self.args.ability:
406 self.kill_process()
407 self.start_profiling(['--app', self.args.package_name])
408 if self.args.ability:
409 ability = self.args.package_name + '/' + self.args.ability
411 result = self.hdc.run_hdc_cmd(start_cmd)
413 self.record_subproc.terminate()
417 elif self.args.local_program:
418 pid = self.hdc.check_run(['shell', 'pidof',
419 self.args.local_program])
421 print("Can't find pid of %s" % self.args.local_program)
424 self.start_profiling(['-p', str(pid)])
425 elif self.args.cmd:
426 cmds = self.args.cmd.split(' ')
428 self.start_profiling(cmd)
429 elif self.args.pid:
430 self.start_profiling(['-p', ','.join(self.args.pid)])
431 elif self.args.tid:
432 self.start_profiling(['-t', ','.join(self.args.tid)])
433 elif self.args.system_wide:
434 self.start_profiling(['-a'])
437 def kill_process(self): argument
438 if self.get_app_process():
439 self.hdc.check_run(['shell', 'aa', 'force-stop', self.args.app])
443 pid = self.get_app_process()
449 self.run_in_app_dir(['kill', '-9', str(pid)])
451 def get_app_process(self): argument
452 result, output = self.hdc.run_hdc_cmd(
453 ['shell', 'pidof', self.args.package_name])
456 def run_in_app_dir(self, args): argument
457 if self.device_root:
458 hdc_args = ['shell', 'cd /data/data/' + self.args.package_name +
461 hdc_args = ['shell', 'run-as', self.args.package_name] + args
462 return self.hdc.run_hdc_cmd(hdc_args, log_output=False)
464 def start_profiling(self, selected_args): argument
466 record_options = self.args.record_options.split(' ')
468 if self.is_control:
470 '--control', self.control_mode, '-o',
475 if self.args.local_lib_dir and self.hdc.run_hdc_cmd(
479 hdc_args = [self.hdc.hdc_path, 'shell'] + args
481 self.record_subproc = subprocess.Popen(hdc_args)
483 def profiling(self): argument
490 return_code = self.record_subproc.wait()
492 self.end_profiling()
493 self.record_subproc = None
499 def end_profiling(self): argument
506 (result, out) = self.hdc.run_hdc_cmd(
512 self.hdc.run_hdc_cmd(['shell', 'pkill',
516 def get_profiling_data(self): argument
518 full_path = os.path.join(current_path, self.args.output_perf_data)
519 self.hdc.check_run(['file recv', '/data/local/tmp/perf.data',
521 self.hdc.run_hdc_cmd(['shell', 'rm',
524 def exec_control(self): argument
525 hdc_args = [self.hdc.hdc_path, 'shell',
527 '--control', self.control_mode]
529 self.record_subproc = subprocess.Popen(hdc_args)
531 def wait_data_generate_done(self): argument
534 (result, out) = self.hdc.run_hdc_cmd(
539 self.get_profiling_data()