Skip to content

Commit

Permalink
[#noissue] Reduce memory usage of DisableTrace
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Nov 30, 2021
1 parent 8a3b133 commit 75feb5c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class DisableTrace implements Trace {

private final long id;
private final long startTime;
private final DefaultTraceScopePool scopePool = new DefaultTraceScopePool();
private DefaultTraceScopePool scopePool;
private final ActiveTraceHandle handle;
private boolean closed = false;

Expand Down Expand Up @@ -135,11 +135,17 @@ public SpanEventRecorder currentSpanEventRecorder() {

@Override
public TraceScope getScope(String name) {
if (scopePool == null) {
return null;
}
return scopePool.get(name);
}

@Override
public TraceScope addScope(String name) {
if (scopePool == null) {
scopePool = new DefaultTraceScopePool();
}
return scopePool.add(name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.navercorp.pinpoint.profiler.context;

import com.navercorp.pinpoint.bootstrap.context.Trace;
import com.navercorp.pinpoint.profiler.context.active.ActiveTraceHandle;
import org.junit.Assert;
import org.junit.Test;

import static org.mockito.Mockito.mock;

public class DisableTraceTest {
@Test
public void testGetScope() {
Trace trace = newTrace();
Assert.assertNull(trace.addScope("empty"));
}

@Test
public void testAddScope() {
Trace trace = newTrace();

trace.addScope("aaa");
Assert.assertNotNull(trace.getScope("aaa"));
}

private Trace newTrace() {
ActiveTraceHandle activeTraceHandle = mock(ActiveTraceHandle.class);
return new DisableTrace(1, 2, activeTraceHandle);
}
}

0 comments on commit 75feb5c

Please sign in to comment.