Skip to content

Commit

Permalink
[Mega-Linter] Apply linters fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
umaannamalai authored and github-actions[bot] committed Jun 29, 2023
1 parent 9f5a233 commit 0686cd8
Showing 1 changed file with 18 additions and 30 deletions.
48 changes: 18 additions & 30 deletions newrelic/api/profile_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,27 @@
# limitations under the License.

import functools
import sys
import os
import sys

from newrelic.packages import six

from newrelic.api.time_trace import current_trace
from newrelic import __file__ as AGENT_PACKAGE_FILE
from newrelic.api.function_trace import FunctionTrace
from newrelic.common.object_wrapper import FunctionWrapper, wrap_object
from newrelic.api.time_trace import current_trace
from newrelic.common.object_names import callable_name
from newrelic.common.object_wrapper import FunctionWrapper, wrap_object
from newrelic.packages import six

from newrelic import __file__ as AGENT_PACKAGE_FILE
AGENT_PACKAGE_DIRECTORY = os.path.dirname(AGENT_PACKAGE_FILE) + '/'
AGENT_PACKAGE_DIRECTORY = os.path.dirname(AGENT_PACKAGE_FILE) + "/"


class ProfileTrace(object):

def __init__(self, depth):
self.function_traces = []
self.maximum_depth = depth
self.current_depth = 0

def __call__(self, frame, event, arg): # pragma: no cover

if event not in ['call', 'c_call', 'return', 'c_return',
'exception', 'c_exception']:
if event not in ["call", "c_call", "return", "c_return", "exception", "c_exception"]:
return

parent = current_trace()
Expand All @@ -49,8 +45,7 @@ def __call__(self, frame, event, arg): # pragma: no cover
# coroutine systems based on greenlets so don't run
# if we detect may be using greenlets.

if (hasattr(sys, '_current_frames') and
parent.thread_id not in sys._current_frames()):
if hasattr(sys, "_current_frames") and parent.thread_id not in sys._current_frames():
return

co = frame.f_code
Expand Down Expand Up @@ -84,7 +79,7 @@ def _callable():
except Exception:
pass

if event in ['call', 'c_call']:
if event in ["call", "c_call"]:
# Skip the outermost as we catch that with the root
# function traces for the profile trace.

Expand All @@ -100,19 +95,17 @@ def _callable():
self.function_traces.append(None)
return

if event == 'call':
if event == "call":
func = _callable()
if func:
name = callable_name(func)
else:
name = '%s:%s#%s' % (func_filename, func_name,
func_line_no)
name = "%s:%s#%s" % (func_filename, func_name, func_line_no)
else:
func = arg
name = callable_name(arg)
if not name:
name = '%s:@%s#%s' % (func_filename, func_name,
func_line_no)
name = "%s:@%s#%s" % (func_filename, func_name, func_line_no)

function_trace = FunctionTrace(name=name, parent=parent)
function_trace.__enter__()
Expand All @@ -127,7 +120,7 @@ def _callable():
self.function_traces.append(function_trace)
self.current_depth += 1

elif event in ['return', 'c_return', 'c_exception']:
elif event in ["return", "c_return", "c_exception"]:
if not self.function_traces:
return

Expand All @@ -143,9 +136,7 @@ def _callable():
self.current_depth -= 1


def ProfileTraceWrapper(wrapped, name=None, group=None, label=None,
params=None, depth=3):

def ProfileTraceWrapper(wrapped, name=None, group=None, label=None, params=None, depth=3):
def wrapper(wrapped, instance, args, kwargs):
parent = current_trace()

Expand Down Expand Up @@ -192,7 +183,7 @@ def wrapper(wrapped, instance, args, kwargs):
_params = params

with FunctionTrace(_name, _group, _label, _params, parent=parent, source=wrapped):
if not hasattr(sys, 'getprofile'):
if not hasattr(sys, "getprofile"):
return wrapped(*args, **kwargs)

profiler = sys.getprofile()
Expand All @@ -212,11 +203,8 @@ def wrapper(wrapped, instance, args, kwargs):


def profile_trace(name=None, group=None, label=None, params=None, depth=3):
return functools.partial(ProfileTraceWrapper, name=name,
group=group, label=label, params=params, depth=depth)
return functools.partial(ProfileTraceWrapper, name=name, group=group, label=label, params=params, depth=depth)


def wrap_profile_trace(module, object_path, name=None,
group=None, label=None, params=None, depth=3):
return wrap_object(module, object_path, ProfileTraceWrapper,
(name, group, label, params, depth))
def wrap_profile_trace(module, object_path, name=None, group=None, label=None, params=None, depth=3):
return wrap_object(module, object_path, ProfileTraceWrapper, (name, group, label, params, depth))

0 comments on commit 0686cd8

Please sign in to comment.