def main(): # pragma: no cover logger.info('Starting docker-pygen ...') kwargs = parse_arguments().__dict__ if kwargs.get('debug'): set_log_level('DEBUG') logger.debug('Startup arguments: %s', ', '.join('%s=%s' % item for item in kwargs.items())) app = PyGen(**kwargs) setup_signals(app) logger.debug('Signal handlers set up for SIGTERM, SIGINT and SIGHUP') try: app.update_target() logger.debug('Starting event watch loop') app.watch() finally: logger.info('Exiting...') app.stop()
def main(): parser = argparse.ArgumentParser(description=""" Pull binaries needed by perf.data from device to binary_cache directory.""" ) parser.add_argument('-i', '--perf_data_path', default='perf.data', type=extant_file, help=""" The path of profiling data.""") parser.add_argument('-lib', '--native_lib_dir', type=extant_dir, nargs='+', help=""" Path to find debug version of native shared libraries used in the app.""", action='append') parser.add_argument('--disable_adb_root', action='store_true', help=""" Force adb to run in non root mode.""") parser.add_argument('--ndk_path', nargs=1, help='Find tools in the ndk path.') parser.add_argument('--log', choices=['debug', 'info', 'warning'], default='info', help='set log level') args = parser.parse_args() set_log_level(args.log) ndk_path = None if not args.ndk_path else args.ndk_path[0] builder = BinaryCacheBuilder(ndk_path, args.disable_adb_root) symfs_dirs = flatten_arg_list(args.native_lib_dir) builder.build_binary_cache(args.perf_data_path, symfs_dirs)
def _read_config(self, signum=None, frame=None): logit("info", "_read_config called!") try: self.parser.read(CONFIG_FILE) except ConfigParser.MissingSectionHeaderError as e: # The file exists, but doesn't have the correct format. raise exc.InvalidConfigurationFile(e) def safe_get(section, option, default=None): try: return self.parser.get(section, option) except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): return default self.log_level = safe_get("frame", "log_level", "INFO") set_log_level(self.log_level) self.reg_url = safe_get("host", "reg_url") if not self.reg_url: logit("error", "No registration URL in photo.cfg; exiting") exit() self.dl_url = safe_get("host", "dl_url") if not self.dl_url: logit("error", "No download URL configured in photo.cfg; exiting") exit() self.check_url = safe_get("host", "check_url", None) self.frameset = safe_get("frameset", "name", "") self.name = safe_get("frame", "name", "undefined") self.pkid = safe_get("frame", "pkid", "") self.description = safe_get("frame", "description", "") self.orientation = safe_get("frame", "orientation", "H") # When to start the image rotation self.interval_base = safe_get("frame", "interval_base", "*:*") # How often to change image self.interval_time = int(safe_get("frame", "interval_time", 10)) # Units of time for the image change interval self.interval_units = safe_get("frame", "interval_units", "minutes") self.interval = _normalize_interval(self.interval_time, self.interval_units) logit("info", "Setting image interval to", self.interval) self.set_image_interval() check_interval = int(safe_get("frame", "host_check", 120)) check_units = safe_get("frame", "host_check_units", "minutes") self.check_interval = _normalize_interval(check_interval, check_units) logit("info", "Setting host check interval to", self.check_interval) self.brightness = safe_get("monitor", "brightness") self.contrast = safe_get("monitor", "contrast") self.saturation = safe_get("monitor", "saturation")
def scheduler(self, sched): set_log_level(logging.INFO) logging.info(f"scheduler() {self.batterystatus()}") timez = self._add_times_to_schedule(self.conf['schedule']) now = datetime.now() for run in timez.keys(): if timez[run]['time'] > now: if timez[run]['state']: state = self.switchon else: state = self.switchoff sched.add_job(state, 'date', run_date=timez[run]['time']) logging.info(f"{timez[run]['emoji']:2} {run:10}: {timez[run]['time']}") logging.info(info_jobs(sched.get_jobs()))
def main(): parser = optparse.OptionParser(usage='usage: %prog [options] [test_names]') parser.add_option('-e', '--environment_type', help='Environment type', default=None) parser.add_option('-n', '--name', help='Environment name', default=None) parser.add_option('-p', '--environment_params', help='Environment parameters if creating an environment ' 'for the test', default=None) parser.add_option('-t', '--test_params', help='Test parameters', default=None) utils.add_options(parser) global _options _options, args = parser.parse_args() del sys.argv[1:] utils.set_log_level(_options.verbose) utils.set_options(_options) unittest.main()
def verify_state(self): logging.debug("verify_state()") if self.mystery_state == Light.UNKN: status = self.status() # XXX wouldn't need VERIFY_TABLE if status & self.state were the same type to verify against if VERIFY_TABLE[status] == self.state: logging.info(f"status is ✅ {status} 💡") self.mystery_state = VERIFY_TABLE[status] elif VERIFY_TABLE[status] == Light.UNKN: logging.info("status is ❓") self.mystery_state = Light.UNKN elif VERIFY_TABLE[status] != self.state: logging.info("status is 🚫 toggling 💡") self.toggle() self.mystery_state = Light.UNKN else: logging.info("✅ status correct. quieting log messages") set_log_level(logging.WARNING) # XXX this might not be working ... just suck it up and accept the log messages ... could do this via apscheduler.job.pause() but that would require a dance
def load_settings(env=None): global settings_dict, curr_env mass_redis_settings = EnvSettings() mass_redis_settings.cpg = ConfigParser.SafeConfigParser() if env is None or env == EnvironmentType.LOCAL: mass_redis_settings.cpg.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), r'config.txt')) else: mass_redis_settings.cpg.read(os.path.join(os.path.abspath(os.path.dirname(__file__)), r'config_%s.txt' % env)) mass_redis_settings.ENV = mass_redis_settings.cpg.get('general', 'env') # Set only once so that this maintains a reference to the environment the app is running in # Don't want to do this on subsequent loads since when user requests a provider in a different environment if curr_env is None: curr_env = mass_redis_settings.ENV mass_redis_settings.LOG_ROOT = mass_redis_settings.cpg.get('general', 'log_root') mass_redis_settings.LOG_NAME = 'generic_redis_cache.log' mass_redis_settings.LOG_LEVEL = mass_redis_settings.cpg.get('general', 'log_level') utils.init_log(mass_redis_settings.LOG_NAME, mass_redis_settings.LOG_ROOT) level = logging.getLevelName(mass_redis_settings.LOG_LEVEL) utils.set_log_level(level, mass_redis_settings.LOG_NAME) logger = logging.getLogger(mass_redis_settings.LOG_NAME) # Redis Settings mass_redis_settings.REDIS_HOST = mass_redis_settings.cpg.get('general', 'redis_server') mass_redis_settings.REDIS_PORT = mass_redis_settings.cpg.get('general', 'redis_port') mass_redis_settings.REDIS_PASSWORD = mass_redis_settings.cpg.get('general', 'redis_password') mass_redis_settings.REDIS_DB = mass_redis_settings.cpg.get('general', 'redis_db') # For debugging purposes, log settings data logger.info('log_root: %s, log_name:%s, log_level:%s' % (mass_redis_settings.LOG_ROOT, mass_redis_settings.LOG_NAME, mass_redis_settings.LOG_LEVEL)) settings_dict[mass_redis_settings.ENV] = mass_redis_settings
def main(kwargs): if kwargs['--verbose']: utils.set_log_level(utils.DEBUG) # Create the Tic Tac Toe board board = Board(int(kwargs['--size'])) nn_dims = (board.num_cells, board.num_cells*2, board.num_cells) # TODO: Clean up player creation # Create the list of players if kwargs['--p1'] == 'human': p1 = HumanPlayer() elif kwargs['--p1'] == 'NN': p1 = NNPlayer(dims=nn_dims) if kwargs['--p2'] == 'human': p2 = HumanPlayer() elif kwargs['--p2'] == 'NN': p2 = NNPlayer(dims=nn_dims) game = Game(board=board, players=(p1, p2), num_rounds=int(kwargs['--num_rounds'])) game.play() print(game.score_board)
from io import Surface from viz import Brain, TimeViewer from utils import verbose, set_log_level, set_log_file __version__ = "0.5dev" set_log_level()
def main(): parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) target_group = parser.add_argument_group( title='Select profiling target').add_mutually_exclusive_group( required=True) target_group.add_argument( '-p', '--app', help="""Profile an Android app, given the package name. Like `-p com.example.android.myapp`.""") target_group.add_argument('-np', '--native_program', help="""Profile a native program running on the Android device. Like `-np surfaceflinger`.""" ) target_group.add_argument( '-cmd', help="""Profile running a command on the Android device. Like `-cmd "pm -l"`.""") target_group.add_argument( '--pid', nargs='+', help="""Profile native processes running on device given their process ids.""") target_group.add_argument('--tid', nargs='+', help="""Profile native threads running on device given their thread ids.""") target_group.add_argument('--system_wide', action='store_true', help="""Profile system wide.""") app_target_group = parser.add_argument_group( title='Extra options for profiling an app') app_target_group.add_argument('--compile_java_code', action='store_true', help="""Used with -p. On Android N and Android O, we need to compile Java code into native instructions to profile Java code. Android O also needs wrap.sh in the apk to use the native instructions.""" ) app_start_group = app_target_group.add_mutually_exclusive_group() app_start_group.add_argument('-a', '--activity', help="""Used with -p. Profile the launch time of an activity in an Android app. The app will be started or restarted to run the activity. Like `-a .MainActivity`.""" ) app_start_group.add_argument( '-t', '--test', help="""Used with -p. Profile the launch time of an instrumentation test in an Android app. The app will be started or restarted to run the instrumentation test. Like `-t test_class_name`.""") record_group = parser.add_argument_group('Select recording options') record_group.add_argument( '-r', '--record_options', default='-e task-clock:u -f 1000 -g --duration 10', help="""Set recording options for `simpleperf record` command. Use `run_simpleperf_on_device.py record -h` to see all accepted options. Default is "-e task-clock:u -f 1000 -g --duration 10".""" ) record_group.add_argument( '-lib', '--native_lib_dir', type=extant_dir, help="""When profiling an Android app containing native libraries, the native libraries are usually stripped and lake of symbols and debug information to provide good profiling result. By using -lib, you tell app_profiler.py the path storing unstripped native libraries, and app_profiler.py will search all shared libraries with suffix .so in the directory. Then the native libraries will be downloaded on device and collected in build_cache.""") record_group.add_argument( '-o', '--perf_data_path', default='perf.data', help='The path to store profiling data. Default is perf.data.') record_group.add_argument( '-nb', '--skip_collect_binaries', action='store_true', help="""By default we collect binaries used in profiling data from device to binary_cache directory. It can be used to annotate source code and disassembly. This option skips it.""" ) other_group = parser.add_argument_group('Other options') other_group.add_argument( '--ndk_path', type=extant_dir, help="""Set the path of a ndk release. app_profiler.py needs some tools in ndk, like readelf.""") other_group.add_argument( '--disable_adb_root', action='store_true', help="""Force adb to run in non root mode. By default, app_profiler.py will try to switch to root mode to be able to profile released Android apps.""") other_group.add_argument('--log', choices=['debug', 'info', 'warning'], default='info', help='set log level') def check_args(args): if (not args.app) and (args.compile_java_code or args.activity or args.test): log_exit( '--compile_java_code, -a, -t can only be used when profiling an Android app.' ) args = parser.parse_args() set_log_level(args.log) check_args(args) if args.app: profiler = AppProfiler(args) elif args.native_program: profiler = NativeProgramProfiler(args) elif args.cmd: profiler = NativeCommandProfiler(args) elif args.pid: profiler = NativeProcessProfiler(args) elif args.tid: profiler = NativeThreadProfiler(args) elif args.system_wide: profiler = SystemWideProfiler(args) profiler.profile()
def exit_signal(*args): logger.info('Exiting ...') exit(0 if signal.SIGTERM else 1) signal.signal(signal.SIGTERM, exit_signal) signal.signal(signal.SIGINT, exit_signal) def update_signal(*args): worker.send_update() signal.signal(signal.SIGHUP, update_signal) if __name__ == '__main__': # pragma: no cover set_log_level('INFO') arguments = parse_arguments() if arguments.debug: set_log_level('DEBUG') worker = Worker(arguments.manager, arguments.retries, arguments.events, arguments.metrics) setup_signals(worker) logger.debug('Signal handlers set up for SIGTERM, SIGINT and SIGHUP') try: worker.start()
# Parse each conversation for state in json_archive['conversation_state']: conv = Conversation(state) conv.parse() conv.print_summary() conv.serialize() LOG_INFO('Finished parsing conversations!') if __name__ == "__main__": LOG_INFO('Started script') parser = argparse.ArgumentParser() parser.add_argument('-f', '--file-path', default='raw/Hangouts.json', type=str, dest='file_path', help='Path to raw data file') parser.add_argument('-l', '--log-level', default=1, type=int, dest='log_level', help='Minimum logging level to output') args = parser.parse_args() utils.set_log_level(args.log_level) main(args.file_path)
kwargs = parse_arguments().__dict__ if kwargs.get('debug'): set_log_level('DEBUG') logger.debug('Startup arguments: %s', ', '.join('%s=%s' % item for item in kwargs.items())) app = PyGen(**kwargs) setup_signals(app) logger.debug('Signal handlers set up for SIGTERM, SIGINT and SIGHUP') try: app.update_target() logger.debug('Starting event watch loop') app.watch() finally: logger.info('Exiting...') app.stop() if __name__ == '__main__': # pragma: no cover set_log_level('INFO') main()
def off_state(self): set_log_level(logging.INFO) self.switchoff()
def on_state(self): set_log_level(logging.INFO) self.switchon()
#!/usr/bin/env python from __future__ import absolute_import from __future__ import division from __future__ import print_function import os import ggplot import pickle import argparse import datetime import pandas as pd import utils utils.set_log_level(1) from utils import LOG_ERROR, LOG_DEBUG, LOG_INFO, LOG_WARN def main(file_path): # Validate raw data path if not os.path.exists(file_path): LOG_ERROR('Could not find file: {}'.format(file_path)) return # Validate raw data file type if not file_path.endswith('.pkl'): LOG_ERROR('File path must be a pickle file') return with open(file_path, 'rb') as f: