Пример #1
0
 def _add_lazy_post_import_hook(self, file_path, hook_called_per_function_call):
   #print(file_path)
   
   def _add_per_function_hook_for_module(target_module):
     with open(file_path, "rt") as file:
       ast_tree = ast.parse(file.read(), filename=file_path)
     
     top_level_ast_function_list = (f for f in ast_tree.body if isinstance(f, ast.FunctionDef))
     for ast_function in top_level_ast_function_list:
       wrapt.wrap_function_wrapper(target_module, ast_function.name, hook_called_per_function_call)
     
     top_level_ast_class_list = (f for f in ast_tree.body if isinstance(f, ast.ClassDef))
     #print(list(top_level_ast_class_list))
     for ast_class in top_level_ast_class_list:
       
       ast_class_function_list = (f for f in ast_class.body if isinstance(f, ast.FunctionDef))
       for ast_class_function in ast_class_function_list:
         actual_class = getattr(target_module, ast_class.name)
         wrapt.wrap_function_wrapper(actual_class, ast_class_function.name, hook_called_per_function_call)
   
   target_module_name = os.path.basename(file_path)[:-(len(".py"))]
     
   relative_path = file_path.split(self._top_level_directory_path)[1]
   modules_above_target_module_string = relative_path.split(target_module_name)[0]
   modules_above_target_module = [x for x in modules_above_target_module_string.split("\\") if len(x) > 0]
   if len(modules_above_target_module) > 0:
     target_module_path = ".".join(modules_above_target_module) + "." + target_module_name
   else:
     target_module_path = target_module_name
   #print("\t" + target_module_path)
   wrapt.register_post_import_hook(_add_per_function_hook_for_module, target_module_path)
Пример #2
0
def configure_summary_writer():
    """Configures override of tf.summary.FileWriter.add_summary().

  This is only performed for hyperparameter runs. See SummaryFileWriterWrapper
  above for more details.
  """
    # We only hook the summary if the env vars are set.
    # Specifically, Trial Id must not be empty, so this only happens on
    # hyperparameter runs.
    trial_id = os.environ.get('CLOUD_ML_TRIAL_ID', None)
    if not trial_id:
        return

    hp_metric_tag = os.environ.get('CLOUD_ML_HP_METRIC_TAG', '')
    wrapper = SummaryFileWriterWrapper(hp_metric_tag)
    register_post_import_hook(wrapper.run_post_import_hook, 'tensorflow')
Пример #3
0
def patch():
    for module in ['mysql.connector', 'MySQLdb']:
        wrapt.register_post_import_hook(instrument_mysql, module)
Пример #4
0
def patch():
    wrapt.register_post_import_hook(instrument_django_core_handlers_wsgi,
                                    'django.core.handlers.wsgi')
Пример #5
0
def path():
    wrapt.register_post_import_hook(instrument_redis_client, "redis.connection")
Пример #6
0
def patch():
    wrapt.register_post_import_hook(instrument_requests_api, 'requests.api')
    wrapt.register_post_import_hook(instrument_requests_sessions, 'request.sessions')
Пример #7
0
def patch():
    wrapt.register_post_import_hook(instrument_sqlite3, 'sqlite3')
    wrapt.register_post_import_hook(instrument_sqlite3_dbapi2,
                                    'sqlite3.dbapi2')