Skip to content

Commit c420a0c

Browse files
hannahramadanespain16umaannamalai
authored
fix gc settings attribute error. (#480)
* fix gc settings attribute error. Co-authored-by: Elise Spain <[email protected]> Co-authored-by: Jessica Shortz <jshortz.newrelic.com> Co-authored-by: Uma Annamalai <[email protected]> * [Mega-Linter] Apply linters fixes Co-authored-by: Elise Spain <[email protected]> Co-authored-by: Uma Annamalai <[email protected]> Co-authored-by: hannahramadan <[email protected]>
1 parent c7aa5e8 commit c420a0c

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

newrelic/core/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class AttributesSettings(Settings):
116116

117117

118118
class GCRuntimeMetricsSettings(Settings):
119-
pass
119+
enabled = False
120120

121121

122122
class ThreadProfilerSettings(Settings):

newrelic/samplers/gc_data.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ def __init__(self, settings, environ):
3434

3535
@property
3636
def enabled(self):
37-
if platform.python_implementation() == "PyPy":
37+
settings = global_settings()
38+
if platform.python_implementation() == "PyPy" or not settings:
3839
return False
3940
else:
40-
settings = global_settings()
4141
return settings.gc_runtime_metrics.enabled
4242

4343
@property
@@ -55,18 +55,12 @@ def record_gc(self, phase, info):
5555
self.start_time = time.time()
5656
elif phase == "stop":
5757
total_time = time.time() - self.start_time
58-
self.gc_time_metrics.record_custom_metric(
59-
"GC/time/%d/all" % self.pid, total_time
60-
)
58+
self.gc_time_metrics.record_custom_metric("GC/time/%d/all" % self.pid, total_time)
6159
for gen in range(0, 3):
6260
if gen <= current_generation:
63-
self.gc_time_metrics.record_custom_metric(
64-
"GC/time/%d/%d" % (self.pid, gen), total_time
65-
)
61+
self.gc_time_metrics.record_custom_metric("GC/time/%d/%d" % (self.pid, gen), total_time)
6662
else:
67-
self.gc_time_metrics.record_custom_metric(
68-
"GC/time/%d/%d" % (self.pid, gen), 0
69-
)
63+
self.gc_time_metrics.record_custom_metric("GC/time/%d/%d" % (self.pid, gen), 0)
7064

7165
def start(self):
7266
if hasattr(gc, "callbacks"):
@@ -100,9 +94,7 @@ def __call__(self):
10094
if hasattr(gc, "get_objects"):
10195
object_types = map(type, gc.get_objects())
10296
if self.top_object_count_limit > 0:
103-
highest_types = Counter(object_types).most_common(
104-
self.top_object_count_limit
105-
)
97+
highest_types = Counter(object_types).most_common(self.top_object_count_limit)
10698
for obj_type, count in highest_types:
10799
yield (
108100
"GC/objects/%d/type/%s" % (self.pid, callable_name(obj_type)),

0 commit comments

Comments
 (0)