Skip to content

Commit 3e85b23

Browse files
Copilotbrianrob
andcommitted
Refactor: Extract AddSampleFromStack helper method to eliminate duplication
Co-authored-by: brianrob <6210322+brianrob@users.noreply.github.com>
1 parent 8a94463 commit 3e85b23

1 file changed

Lines changed: 19 additions & 27 deletions

File tree

src/PerfView/OtherSources/DebuggerStackSource.cs

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,23 @@ private struct DebuggerCallStackFrame
3030
public StackSourceFrameIndex frame;
3131
}
3232

33+
private void AddSampleFromStack(GrowableArray<DebuggerCallStackFrame> stack, StackSourceSample sample, ref float time)
34+
{
35+
StackSourceCallStackIndex parent = StackSourceCallStackIndex.Invalid;
36+
for (int i = stack.Count - 1; i >= 0; --i)
37+
{
38+
parent = Interner.CallStackIntern(stack[i].frame, parent);
39+
}
40+
41+
stack.Clear();
42+
43+
sample.Metric = 1;
44+
sample.StackIndex = parent;
45+
sample.TimeRelativeMSec = time;
46+
time++;
47+
AddSample(sample);
48+
}
49+
3350
private void Read(TextReader reader)
3451
{
3552
var framePattern = new Regex(@"\b(\w+?)\!(\S\(?[\S\s]*\)?)");
@@ -93,20 +110,7 @@ private void Read(TextReader reader)
93110
// clear the stack
94111
if (stack.Count != 0)
95112
{
96-
97-
StackSourceCallStackIndex parent = StackSourceCallStackIndex.Invalid;
98-
for (int i = stack.Count - 1; i >= 0; --i)
99-
{
100-
parent = Interner.CallStackIntern(stack[i].frame, parent);
101-
}
102-
103-
stack.Clear();
104-
105-
sample.Metric = 1;
106-
sample.StackIndex = parent;
107-
sample.TimeRelativeMSec = time;
108-
time++;
109-
AddSample(sample);
113+
AddSampleFromStack(stack, sample, ref time);
110114
}
111115
newCallStackFound = true;
112116

@@ -117,19 +121,7 @@ private void Read(TextReader reader)
117121
// Handle the last sample if there are any remaining frames
118122
if (stack.Count != 0)
119123
{
120-
StackSourceCallStackIndex parent = StackSourceCallStackIndex.Invalid;
121-
for (int i = stack.Count - 1; i >= 0; --i)
122-
{
123-
parent = Interner.CallStackIntern(stack[i].frame, parent);
124-
}
125-
126-
stack.Clear();
127-
128-
sample.Metric = 1;
129-
sample.StackIndex = parent;
130-
sample.TimeRelativeMSec = time;
131-
time++;
132-
AddSample(sample);
124+
AddSampleFromStack(stack, sample, ref time);
133125
}
134126

135127
Interner.DoneInterning();

0 commit comments

Comments
 (0)