Beispiel #1
0
        def traced_function(*args, **kwargs):
            # Everything outside traced_function is done at decoration-time.
            # Everything inside traced_function is done at run-time and must be fast.
            if not log._enabled:  # This check must be at run-time.
                return func(*args, **kwargs)

            def get_arg_value(name, index, default):
                if name in kwargs:
                    return kwargs[name]
                elif index < len(args):
                    return args[index]
                else:
                    return default

            if is_method:
                name = "%s.%s" % (args[0].__class__.__name__, func.__name__)
            else:
                name = "%s.%s" % (func.__module__, func.__name__)

            # Be sure to repr before calling func. Argument values may change.
            arg_values = {
                name: repr(get_arg_value(name, index, default))
                for name, index, default in args_to_log
            }

            start = trace_time.Now()
            log.add_trace_event("B", start, category, name, arg_values)
            try:
                return func(*args, **kwargs)
            finally:
                end = trace_time.Now()
                log.add_trace_event("E", end, category, name)
Beispiel #2
0
    def traced_function(*args, **kwargs):
      # Everything outside traced_function is done at decoration-time.
      # Everything inside traced_function is done at run-time and must be fast.
      if not log._enabled:  # This check must be at run-time.
        return func(*args, **kwargs)

      def get_arg_value(name, index, default):
        if name in kwargs:
          return kwargs[name]
        elif index < len(args):
          return args[index]
        else:
          return default

      if is_method:
        name = "%s.%s" % (args[0].__class__.__name__, func.__name__)
      else:
        name = "%s.%s" % (func.__module__, func.__name__)

      # Be sure to repr before calling func, because the argument values may change.
      arg_values = {
          name: repr(get_arg_value(name, index, default))
          for name, index, default in args_to_log}

      start = time.time()
      log.add_trace_event("B", start, category, name, arg_values)
      try:
        return func(*args, **kwargs)
      finally:
        end = time.time()
        log.add_trace_event("E", end, category, name)
Beispiel #3
0
def trace(name, **kwargs):
    category = "python"
    start = trace_time.Now()
    args_to_log = {key: repr(value) for key, value in kwargs.iteritems()}
    log.add_trace_event("B", start, category, name, args_to_log)
    try:
        yield
    finally:
        end = trace_time.Now()
        log.add_trace_event("E", end, category, name)
Beispiel #4
0
def trace(name, **kwargs):
  category = "python"
  start = time.time()
  args_to_log = {key: repr(value) for key, value in kwargs.iteritems()}
  log.add_trace_event("B", start, category, name, args_to_log)
  try:
    yield
  finally:
    end = time.time()
    log.add_trace_event("E", end, category, name)