Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.

Commit da3840c

Browse files
committed
WPERF-977 Arm Statistical Profiling Extension (SPE) sampling support
See merge request Linaro/WindowsPerf/vs-extension!108 === ChangeLog === * chore: remove slopy extra empty line * feat: update SPE filters groupbox header and placeholder texts * feat: update spe sample displayed name to use the Feature name * fix: tests after updating color highlighter * chore: update extension version * fix: update typo when unchecking SPE checkbox * chore: make config check happen on each setting dialog call * chore: fix issue with rebase * feat: update SPE support on Options update * feat: disable SPE button on if SPE is unavailable * feat: fix overhead percent in SPE output * fix: line highlighter errors * fix: lower case all filepaths * feat: added memory to the form * fix: add handleSPESamplingFinished call to the end of the sampling run * fix: trailing character on spe filter list * fix: remove default frequency on SPE * fix: update highlighter file paths to be case insensitive * feat: add SPE output handling * feat: start handling SPE sampling display * feat: add spe sampling settings * refator: update namespace on wperf defaults * feat: spearate SPE events from the rest of events
1 parent be4badd commit da3840c

21 files changed

+349
-108
lines changed

WindowsPerfGUI.Tests/LineHighlightingTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public class ColorGeneratorTests
4040
{
4141
[Test]
4242
[Description("Testing return values of the color generator")]
43-
[TestCase(0, 3, ExpectedResult = "00ff00")]
44-
[TestCase(50, 3, ExpectedResult = "feff00")]
45-
[TestCase(100, 3, ExpectedResult = "ff0000")]
46-
[TestCase(150, 3, ExpectedResult = "ff0000")] // Test beyond 100%
43+
[TestCase(0, 3, ExpectedResult = "56fe56")]
44+
[TestCase(50, 3, ExpectedResult = "fefe56")]
45+
[TestCase(100, 3, ExpectedResult = "fe5656")]
46+
[TestCase(150, 3, ExpectedResult = "fe5656")] // Test beyond 100%
4747
public string GenerateColor_ReturnsExpectedColor_ForGivenPercentage(
4848
double percentage,
4949
int colorResolution

WindowsPerfGUI/Commands/CountingSettingsCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
using WindowsPerfGUI.Options;
3232
using WindowsPerfGUI.Resources.Locals;
3333
using WindowsPerfGUI.ToolWindows.CountingSetting;
34-
using WindowsPerfGUI.ToolWindows.SamplingSetting;
34+
using WindowsPerfGUI.Utils;
3535

3636
namespace WindowsPerfGUI.Commands
3737
{

WindowsPerfGUI/Commands/SamplingExplorerCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
using WindowsPerfGUI.Options;
3232
using WindowsPerfGUI.Resources.Locals;
3333
using WindowsPerfGUI.ToolWindows.SamplingExplorer;
34-
using WindowsPerfGUI.ToolWindows.SamplingSetting;
34+
using WindowsPerfGUI.Utils;
3535

3636
namespace WindowsPerfGUI.Commands
3737
{

WindowsPerfGUI/Options/WPerfOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
using System.ComponentModel;
3333
using System.Runtime.InteropServices;
3434
using WindowsPerfGUI.SDK.WperfOutputs;
35-
using WindowsPerfGUI.ToolWindows.SamplingSetting;
35+
using WindowsPerfGUI.Utils;
3636

3737
namespace WindowsPerfGUI.Options
3838
{

WindowsPerfGUI/Options/WPerfPath.xaml.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
using WindowsPerfGUI.Resources.Locals;
3535
using WindowsPerfGUI.SDK;
3636
using WindowsPerfGUI.SDK.WperfOutputs;
37-
using WindowsPerfGUI.ToolWindows.SamplingSetting;
37+
using WindowsPerfGUI.Utils;
3838

3939
namespace WindowsPerfGUI.Options
4040
{
@@ -97,6 +97,7 @@ private void ValidateButton_Click(object sender, RoutedEventArgs e)
9797
throw new Exception(errorWperfList);
9898
SetPredefinedEventsAndMetrics(wperfList, shouldForce: true);
9999
WPerfOptions.Instance.UpdateWperfOptions(versions, wperfList);
100+
WperfDefaults.HasSPESupport = wperf.CheckIsSPESupported();
100101
}
101102
catch (Exception ex)
102103
{

WindowsPerfGUI/SDK/WperfClient.cs

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
using WindowsPerfGUI.SDK.WperfOutputs;
3636
using WindowsPerfGUI.ToolWindows.CountingSetting;
3737
using WindowsPerfGUI.ToolWindows.SamplingSetting;
38+
using WindowsPerfGUI.Utils;
3839
using WindowsPerfGUI.Utils.SDK;
3940

4041
namespace WindowsPerfGUI.SDK
@@ -127,22 +128,32 @@ protected void InitProcess()
127128
/// </returns>
128129
public bool CheckIsSPESupported()
129130
{
130-
(WperfVersion versionSerializedOutput, _) = GetVersion();
131-
foreach (var component in versionSerializedOutput.Components)
131+
try
132132
{
133-
if (!component.FeatureString.Contains("+spe"))
133+
(WperfVersion versionSerializedOutput, _) = GetVersion();
134+
foreach (var component in versionSerializedOutput.Components)
134135
{
135-
return false;
136+
if (!component.FeatureString.Contains("+spe"))
137+
{
138+
return false;
139+
}
136140
}
137-
}
138141

139-
(WperfTest testSerializedOutput, _) = GetTest();
142+
(WperfTest testSerializedOutput, _) = GetTest();
143+
144+
TestResult speDeviceConf = testSerializedOutput
145+
.TestResults.Find(el => el.TestName == "spe_device.version_name");
146+
if (speDeviceConf == null) { return false; }
140147

141-
TestResult speDeviceConf = testSerializedOutput
142-
.TestResults.Find(el => el.TestName == "spe_device.version_name");
143-
if (speDeviceConf == null) { return false; }
148+
WperfDefaults.SPEFeatureName = speDeviceConf.Result;
149+
return speDeviceConf.Result.StartsWith("FEAT_SPE");
150+
}
151+
catch (Exception)
152+
{
153+
154+
return false;
155+
}
144156

145-
return speDeviceConf.Result.StartsWith("FEAT_SPE");
146157

147158
}
148159

@@ -198,8 +209,17 @@ public async Task StartSamplingAsync()
198209
try
199210
{
200211
await _wperfProcess.StartBackgroundProcessAsync(samplingArgs);
201-
(WperfSampling serializedOutput, string stdError) = StopSampling();
202-
OnSamplingFinished?.Invoke(this, (serializedOutput, stdError));
212+
if (SamplingSettings.samplingSettingsFrom.IsSPEEnabled)
213+
{
214+
(WperfSPE serializedOutput, string stdError) = StopSPESampling();
215+
OnSPESamplingFinished?.Invoke(this, (serializedOutput, stdError));
216+
}
217+
else
218+
{
219+
(WperfSampling serializedOutput, string stdError) = StopSampling();
220+
OnSamplingFinished?.Invoke(this, (serializedOutput, stdError));
221+
}
222+
203223
}
204224
catch (Exception e)
205225
{
@@ -316,6 +336,12 @@ string stdError
316336
)> OnSamplingFinished
317337
{ get; set; }
318338

339+
public EventHandler<(
340+
WperfSPE serializedOutput,
341+
string stdError
342+
)> OnSPESamplingFinished
343+
{ get; set; }
344+
319345
public EventHandler<(
320346
List<CountingEvent> countingEvents,
321347
string stdError
@@ -328,6 +354,11 @@ string stdError
328354
SamplingSettings.IsSampling = false;
329355
string stdOutput = string.Join("\n", _wperfProcess.StdOutput.Output);
330356
string stdError = string.Join("\n", _wperfProcess.StdError.Output);
357+
if (SamplingSettings.samplingSettingsFrom.IsSPEEnabled)
358+
{
359+
WperfSPE wperfSPE = WperfSPE.FromJson(stdOutput);
360+
361+
}
331362
WperfSampling serializedOutput = WperfSampling.FromJson(stdOutput);
332363
LogToOutput(
333364
stdOutput,
@@ -336,7 +367,20 @@ string stdError
336367
);
337368
return (serializedOutput, stdError);
338369
}
339-
370+
public (WperfSPE serializedOutput, string stdError) StopSPESampling()
371+
{
372+
_wperfProcess.StopProcess();
373+
SamplingSettings.IsSampling = false;
374+
string stdOutput = string.Join("\n", _wperfProcess.StdOutput.Output);
375+
string stdError = string.Join("\n", _wperfProcess.StdError.Output);
376+
WperfSPE serializedOutput = WperfSPE.FromJson(stdOutput);
377+
LogToOutput(
378+
stdOutput,
379+
stdError,
380+
SamplingSettings.GenerateCommandLineArgsArray(SamplingSettings.samplingSettingsFrom)
381+
);
382+
return (serializedOutput, stdError);
383+
}
340384
public (List<CountingEvent> countingEvents, string stdError) StopCounting()
341385
{
342386
_wperfProcess.StopProcess();

WindowsPerfGUI/SDK/WperfOutputs/WperfList.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,31 @@
2828
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2929
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030

31+
using Newtonsoft.Json;
3132
using System.Collections.Generic;
3233
using System.Linq;
33-
using Newtonsoft.Json;
3434

3535
namespace WindowsPerfGUI.SDK.WperfOutputs
3636
{
3737
public partial class WperfList
3838
{
39+
private List<PredefinedEvent> predefinedEvents;
40+
3941
[JsonProperty("Predefined_Events")]
40-
public List<PredefinedEvent> PredefinedEvents { get; set; }
42+
public List<PredefinedEvent> PredefinedEvents
43+
{
44+
get { return predefinedEvents; }
45+
set
46+
{
47+
predefinedEvents = value.Where(e => e.EventType != "[Kernel PMU event]" && e.EventType != "[SPE filter]").ToList();
48+
PredefinedSPEFilters = value.Where(e => e.EventType == "[SPE filter]").ToList();
49+
}
50+
}
51+
52+
public const string SPE_EVENT_BASE_NAME = "arm_spe_0";
53+
public const string SPE_EVENT_SEPARATOR = "/";
54+
55+
public List<PredefinedEvent> PredefinedSPEFilters { get; set; }
4156

4257
public (PredefinedEvent, int) GetPredefinedEventFromAliasName(string aliasName)
4358
{
@@ -47,6 +62,7 @@ public partial class WperfList
4762
{
4863
return (predefinedEvent.value, predefinedEvent.i);
4964
}
65+
5066
}
5167
return (null, -1);
5268
}

WindowsPerfGUI/ToolWindows/CountingSetting/CountingSettingDialog.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
using WindowsPerfGUI.SDK;
4646
using WindowsPerfGUI.SDK.WperfOutputs;
4747
using WindowsPerfGUI.ToolWindows.SamplingSetting;
48+
using WindowsPerfGUI.Utils;
4849
using WindowsPerfGUI.Utils.ListSearcher;
4950

5051
namespace WindowsPerfGUI.ToolWindows.CountingSetting

WindowsPerfGUI/ToolWindows/SamplingExplorer/FormattedSamplingResults.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,26 @@ public void ClearSampling()
6262
HighlighterDict.Clear();
6363
RootSampledEvent = new List<SamplingSection>();
6464
}
65+
private ulong RecalculateOverhead(SamplingSection rootSamplingSection)
66+
{
67+
ulong hits = 0;
68+
foreach (SamplingSection samplingEvents in rootSamplingSection.Children)
69+
{
70+
hits += (ulong)samplingEvents.Hits;
71+
}
6572

73+
return hits;
74+
}
75+
private ulong CalculateAllSamplesGenerated(WperfSampling rootSampling)
76+
{
77+
ulong hits = 0;
78+
foreach (SampledEvent sampledEvent in rootSampling.SamplingSummary.SampledEvents)
79+
{
80+
hits += (ulong)CalculateSampleHits(sampledEvent);
81+
}
82+
83+
return hits;
84+
}
6685
double CalculateSampleHits(SampledEvent sampledEvent)
6786
{
6887
double allHits = 0;
@@ -96,7 +115,11 @@ public void FormatSamplingResults(
96115
};
97116
RootSampledEvent.Add(rootSample);
98117

99-
double allHits = wperSamplingOutput.SamplingSummary.SamplesGenerated;
118+
if (rootSample.Hits == 0)
119+
rootSample.Hits = CalculateAllSamplesGenerated(wperSamplingOutput);
120+
121+
122+
double allHits = (double)rootSample.Hits;
100123

101124
foreach (SampledEvent sampledEvent in wperSamplingOutput.SamplingSummary.SampledEvents)
102125
{
@@ -173,6 +196,8 @@ public void FormatSamplingResults(
173196
}
174197
}
175198

199+
200+
176201
OnPropertyChanged("RootSampledEvent");
177202
}
178203

WindowsPerfGUI/ToolWindows/SamplingExplorer/LineHighlighting/ColorGenerator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2929
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030

31-
using System.Windows.Media;
3231
using Microsoft.VisualStudio.Imaging;
32+
using System.Windows.Media;
3333

3434
namespace WindowsPerfGUI.ToolWindows.SamplingExplorer.LineHighlighting
3535
{
@@ -62,11 +62,11 @@ private static Color GetColorFromPercentage(double percentage, int colorResoluti
6262
if (colorResolution < MIN_COLOR_RESOLUTION || colorResolution > MAX_COLOR_RESOLUTION)
6363
colorResolution = DEFAULT_COLOR_RESOLUTION;
6464

65-
double percentageChunk = 100.0 / (double)colorResolution;
65+
double percentageChunk = Math.Floor(100.0 / (double)colorResolution);
6666
double hueChunk = (double)(GREEN_HUE - RED_HUE) / ((double)colorResolution - 1);
6767
int amountOfChunks = (int)
6868
Math.Min(Math.Floor(percentage / percentageChunk), colorResolution - 1);
69-
return GetColorFromHSL(GREEN_HUE - (hueChunk * amountOfChunks) + RED_HUE, 1, 0.5);
69+
return GetColorFromHSL(GREEN_HUE - (hueChunk * amountOfChunks) + RED_HUE, 1, 0.67);
7070
}
7171

7272
/// <summary>

0 commit comments

Comments
 (0)