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

Commit 0468785

Browse files
committed
WPERF-987 Spe detection
See merge request Linaro/WindowsPerf/vs-extension!106 === ChangeLog === * chore: update lookup function to StartsWith instead of Contains * feat: check for SPE support at launch * refactor: wperfOptions * feat: add check SPE support client method * feat: add SPE support attribute in WperfDefaults * feat: update wperf version output parser
1 parent c7d4af1 commit 0468785

File tree

8 files changed

+88
-60
lines changed

8 files changed

+88
-60
lines changed

WindowsPerfGUI/Options/WPerfOptions.cs

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

3637
namespace WindowsPerfGUI.Options
3738
{
@@ -50,8 +51,45 @@ public class WPerfOptions : BaseOptionModel<WPerfOptions>
5051
public string WperfPath { get; set; } = "wperf.exe";
5152
public bool WperfVersionCheckIgnore { get; set; } = false;
5253
public bool IsWperfInitialized { get; set; } = false;
53-
54+
public bool HasSPESupport { get; set; } = false;
5455
public WperfVersion WperfCurrentVersion { get; set; }
5556
public WperfList WperfList { get; set; }
57+
public void UpdateWperfVersion(WperfVersion wperfVersion)
58+
{
59+
IsWperfInitialized = true;
60+
WperfCurrentVersion = wperfVersion;
61+
}
62+
public void UpdateWperfOptions(WperfVersion wperfVersion, WperfList wperfList)
63+
{
64+
UpdateWperfVersion(wperfVersion);
65+
if (wperfList != null)
66+
{
67+
WperfList = wperfList;
68+
}
69+
Save();
70+
}
71+
public void UpdateWperfOptions(WperfVersion wperfVersion, bool hasSPESupport)
72+
{
73+
UpdateWperfVersion(wperfVersion);
74+
75+
HasSPESupport = hasSPESupport;
76+
WperfDefaults.HasSPESupport = hasSPESupport;
77+
Save();
78+
}
79+
#nullable enable
80+
public void UpdateWperfOptions(WperfVersion wperfVersion, WperfList? wperfList, bool? hasSPESupport)
81+
{
82+
UpdateWperfVersion(wperfVersion);
83+
if (wperfList != null)
84+
{
85+
WperfList = wperfList;
86+
}
87+
if (hasSPESupport != null)
88+
{
89+
HasSPESupport = (bool)hasSPESupport;
90+
}
91+
Save();
92+
}
93+
#nullable disable
5694
}
5795
}

WindowsPerfGUI/Options/WPerfPath.xaml.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ private void ValidateButton_Click(object sender, RoutedEventArgs e)
9696
if (errorWperfList != "")
9797
throw new Exception(errorWperfList);
9898
SetPredefinedEventsAndMetrics(wperfList, shouldForce: true);
99+
WPerfOptions.Instance.UpdateWperfOptions(versions, wperfList);
99100
}
100101
catch (Exception ex)
101102
{
@@ -123,12 +124,13 @@ private void SetWperfVersion(WperfVersion wperfVersion, bool shouldForce = false
123124
string component = item.component.Component;
124125
string componentVersion = item.component.ComponentVersion;
125126
string gitVersion = item.component.GitVersion;
127+
string featureString = item.component.FeatureString;
126128

127129
MainStack.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
128130

129131
TextBlock componentLabel = TextBlockFactory(component, offset);
130132
TextBlock componentVersionLabel = TextBlockFactory(
131-
$"{componentVersion} ({gitVersion})",
133+
$"{componentVersion} ({gitVersion}) -- ${featureString}",
132134
offset,
133135
true
134136
);
@@ -142,9 +144,6 @@ private void SetWperfVersion(WperfVersion wperfVersion, bool shouldForce = false
142144
return;
143145
}
144146

145-
WPerfOptions.Instance.IsWperfInitialized = true;
146-
WPerfOptions.Instance.WperfCurrentVersion = wperfVersion;
147-
WPerfOptions.Instance.Save();
148147
}
149148

150149
private void SetPredefinedEventsAndMetrics(WperfList wperfList, bool shouldForce = false)
@@ -156,8 +155,7 @@ private void SetPredefinedEventsAndMetrics(WperfList wperfList, bool shouldForce
156155
return;
157156
}
158157

159-
WPerfOptions.Instance.WperfList = wperfList;
160-
WPerfOptions.Instance.Save();
158+
161159
}
162160

163161
public static TextBlock TextBlockFactory(string text, int offset, bool isRight = false)

WindowsPerfGUI/SDK/WperfClient.cs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,35 @@ protected void InitProcess()
117117
return (serializedOutput, stdError);
118118
}
119119

120+
/// <summary>
121+
/// This returns wether or not SPE is supported on this machine
122+
/// it runs the command wperf -version --json and wperf test --json
123+
/// it then checks for "spe_device.version_name" in the test results and the feature string in the version results
124+
/// </summary>
125+
/// <returns>
126+
/// bool
127+
/// </returns>
128+
public bool CheckIsSPESupported()
129+
{
130+
(WperfVersion versionSerializedOutput, _) = GetVersion();
131+
foreach (var component in versionSerializedOutput.Components)
132+
{
133+
if (!component.FeatureString.Contains("+spe"))
134+
{
135+
return false;
136+
}
137+
}
138+
139+
(WperfTest testSerializedOutput, _) = GetTest();
140+
141+
TestResult speDeviceConf = testSerializedOutput
142+
.TestResults.Find(el => el.TestName == "spe_device.version_name");
143+
if (speDeviceConf == null) { return false; }
144+
145+
return speDeviceConf.Result.StartsWith("FEAT_SPE");
146+
147+
}
148+
120149
/// <summary>
121150
/// This returns the list of Wperf's predefined events and metrics
122151
/// it runs the command wperf list -v --json
@@ -219,7 +248,7 @@ public async Task StartCountingAsync()
219248
}
220249
}
221250

222-
static public List<CountingEvent> GetCountingEventsFromJSONFile(string filePath)
251+
public static List<CountingEvent> GetCountingEventsFromJSONFile(string filePath)
223252
{
224253
List<CountingEvent> countingEvents = new();
225254

@@ -244,7 +273,7 @@ static public List<CountingEvent> GetCountingEventsFromJSONFile(string filePath)
244273
return countingEvents;
245274
}
246275

247-
static private void ProcessSingleCount(
276+
private static void ProcessSingleCount(
248277
WperfCounting count,
249278
List<CountingEvent> countingEvents,
250279
bool accumulatePerCoreAndEvent = false
@@ -284,12 +313,14 @@ static private void ProcessSingleCount(
284313
public EventHandler<(
285314
WperfSampling serializedOutput,
286315
string stdError
287-
)> OnSamplingFinished { get; set; }
316+
)> OnSamplingFinished
317+
{ get; set; }
288318

289319
public EventHandler<(
290320
List<CountingEvent> countingEvents,
291321
string stdError
292-
)> OnCountingFinished { get; set; }
322+
)> OnCountingFinished
323+
{ get; set; }
293324

294325
public (WperfSampling serializedOutput, string stdError) StopSampling()
295326
{

WindowsPerfGUI/SDK/WperfOutputs/WperfVersion.cs

Lines changed: 4 additions & 1 deletion
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.Collections.Generic;
3231
using Newtonsoft.Json;
32+
using System.Collections.Generic;
3333

3434
namespace WindowsPerfGUI.SDK.WperfOutputs
3535
{
@@ -49,6 +49,9 @@ public partial class Version
4949

5050
[JsonProperty("GitVer")]
5151
public string GitVersion { get; set; }
52+
53+
[JsonProperty("FeatureString")]
54+
public string FeatureString { get; set; }
5255
}
5356

5457
public partial class WperfVersion

WindowsPerfGUI/ToolWindows/MyToolWindowControl.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,5 @@
5757
Padding="4"
5858
Placeholder="File path... " />
5959
<Button Click="Button_Click" Content="{x:Static resx:MainLanguagePack.ToolWindow}" />
60-
<Button Click="Button_Click_1" Content="Reset" />
6160
</StackPanel>
6261
</UserControl>

WindowsPerfGUI/ToolWindows/MyToolWindowControl.xaml.cs

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@
3030

3131

3232
using System.Windows.Controls;
33-
using WindowsPerfGUI.SDK.WperfOutputs;
34-
using WindowsPerfGUI.ToolWindows.SamplingExplorer;
35-
using WindowsPerfGUI.ToolWindows.SamplingExplorer.LineHighlighting;
33+
using WindowsPerfGUI.Options;
3634

3735
namespace WindowsPerfGUI.ToolWindows
3836
{
@@ -42,48 +40,10 @@ public MyToolWindowControl()
4240
{
4341
InitializeComponent();
4442
}
45-
46-
private static readonly FormattedSamplingResults FormattedSamplingResults = new();
47-
48-
private static void HighlightEditor(SamplingSection samplingSection)
49-
{
50-
if (
51-
samplingSection.SectionType
52-
!= SamplingSection.SamplingSectionType.SAMPLE_SOURCE_CODE
53-
)
54-
{
55-
foreach (SamplingSection child in samplingSection.Children)
56-
{
57-
HighlightEditor(child);
58-
}
59-
}
60-
61-
if (!samplingSection.IsFileExists)
62-
{
63-
return;
64-
}
65-
66-
HighlighterDict.AddFileToHighlight(samplingSection);
67-
}
68-
69-
private void Test()
70-
{
71-
FormattedSamplingResults.FormatSamplingResults(
72-
WperfSampling.FromJson(
73-
"{\r\n\"sampling\": {\r\n\"pe_file\": \"C:\\\\Users\\\\nader\\\\OneDrive\\\\Desktop\\\\sampling\\\\windowsPerfSample\\\\WindowsPerfSample.exe\",\r\n\"pdb_file\": \"C:\\\\Users\\\\nader\\\\OneDrive\\\\Desktop\\\\sampling\\\\windowsPerfSample\\\\WindowsPerfSample.pdb\",\r\n\"sample_display_row\": 50,\r\n\"samples_generated\": 60,\r\n\"samples_dropped\": 0,\r\n\"base_address\": 140697426990076,\r\n\"runtime_delta\": 140692058210304,\r\n\"modules\":[{\"name\":\"KERNEL32.DLL\",\"address\":140726913466368,\"path\":\"C:\\\\Windows\\\\System32\\\\KERNEL32.DLL\"},{\"name\":\"KERNELBASE.dll\",\"address\":140726849830912,\"path\":\"C:\\\\Windows\\\\System32\\\\KERNELBASE.dll\"},{\"name\":\"VCRUNTIME140D.dll\",\"address\":140721964122112,\"path\":\"C:\\\\Windows\\\\SYSTEM32\\\\VCRUNTIME140D.dll\"},{\"name\":\"WindowsPerfSample.exe\",\"address\":140697426919424,\"path\":\"C:\\\\Users\\\\nader\\\\OneDrive\\\\Desktop\\\\sampling\\\\windowsPerfSample\\\\WindowsPerfSample.exe\"},{\"name\":\"ntdll.dll\",\"address\":140726927622144,\"path\":\"C:\\\\Windows\\\\SYSTEM32\\\\ntdll.dll\"},{\"name\":\"ucrtbased.dll\",\"address\":140721524113408,\"path\":\"C:\\\\Windows\\\\SYSTEM32\\\\ucrtbased.dll\"}],\r\n\"modules_info\": [{\"sections\":[{\"section\":\".textbss\",\"offset\":4096,\"virtual_size\":65536},{\"section\":\".text\",\"offset\":69632,\"virtual_size\":30657},{\"section\":\".rdata\",\"offset\":102400,\"virtual_size\":6791},{\"section\":\".data\",\"offset\":110592,\"virtual_size\":528},{\"section\":\".pdata\",\"offset\":114688,\"virtual_size\":5360},{\"section\":\".idata\",\"offset\":122880,\"virtual_size\":2559},{\"section\":\".msvcjmc\",\"offset\":126976,\"virtual_size\":275},{\"section\":\".00cfg\",\"offset\":131072,\"virtual_size\":337},{\"section\":\".rsrc\",\"offset\":135168,\"virtual_size\":1084},{\"section\":\".reloc\",\"offset\":139264,\"virtual_size\":431}],\"module\":\"WindowsPerfSample.exe\",\"pdb_file\":\"C:\\\\Users\\\\nader\\\\OneDrive\\\\Desktop\\\\sampling\\\\windowsPerfSample\\\\WindowsPerfSample.pdb\",\"pe_name\":\"C:\\\\Users\\\\nader\\\\OneDrive\\\\Desktop\\\\sampling\\\\windowsPerfSample\\\\WindowsPerfSample.exe\"}],\r\n\"events\": [{\"type\":\"vfp_spec\",\"samples\":[{\"overhead\":65,\"count\":39,\"symbol\":\"simd_hot\"},{\"overhead\":30,\"count\":18,\"symbol\":\"df_hot\"},{\"overhead\":3.33333,\"count\":2,\"symbol\":\"__CheckForDebuggerJustMyCode\"},{\"overhead\":1.66667,\"count\":1,\"symbol\":\"unknown\"}],\"interval\":200000,\"printed_sample_num\":4,\r\n\"pcs\":[{\"address\":140697426997464,\"count\":9},{\"address\":140697426997508,\"count\":7},{\"address\":140697426997500,\"count\":5},{\"address\":140697426997480,\"count\":4},{\"address\":140697426997468,\"count\":4},{\"address\":140697426997488,\"count\":2},{\"address\":140697426997460,\"count\":2},{\"address\":140697426997496,\"count\":2},{\"address\":140697426997492,\"count\":1},{\"address\":140697426997516,\"count\":1},{\"address\":140697426997188,\"count\":14},{\"address\":140697426997176,\"count\":1},{\"address\":140697426997216,\"count\":1},{\"address\":140697426997196,\"count\":1},{\"address\":140697426997192,\"count\":1},{\"address\":140697426998368,\"count\":1},{\"address\":140697426998452,\"count\":1},{\"address\":140726745318480,\"count\":1}],\r\n\"annotate\": [{\"function_name\": \"simd_hot\",\r\n\"source_code\":[{\"line_number\":53,\"hits\":37,\"filename\":\"C:\\\\Users\\\\nader\\\\source\\\\repos\\\\windowsperfsample\\\\lib.c\"},{\"line_number\":52,\"hits\":2,\"filename\":\"C:\\\\Users\\\\nader\\\\source\\\\repos\\\\windowsperfsample\\\\lib.c\"}]},\r\n{\"function_name\": \"df_hot\",\r\n\"source_code\":[{\"line_number\":15732480,\"hits\":18,\"filename\":\"C:\\\\Users\\\\nader\\\\source\\\\repos\\\\windowsperfsample\\\\lib.c\"}]},\r\n{\"function_name\": \"__CheckForDebuggerJustMyCode\",\r\n\"source_code\":[{\"line_number\":23,\"hits\":1,\"filename\":\"D:\\\\a\\\\_work\\\\1\\\\s\\\\src\\\\vctools\\\\crt\\\\vcstartup\\\\src\\\\misc\\\\debugger_jmc.c\"},{\"line_number\":27,\"hits\":1,\"filename\":\"D:\\\\a\\\\_work\\\\1\\\\s\\\\src\\\\vctools\\\\crt\\\\vcstartup\\\\src\\\\misc\\\\debugger_jmc.c\"}]}]}\r\n]}\r\n}"
74-
)
75-
);
76-
FormattedSamplingResults.RootSampledEvent.ForEach(HighlightEditor);
77-
}
78-
7943
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
8044
{
81-
Test();
82-
}
83-
84-
private void Button_Click_1(object sender, System.Windows.RoutedEventArgs e)
85-
{
86-
HighlighterDict.Clear();
45+
bool speSupport = WPerfOptions.Instance.HasSPESupport;
46+
Debug.WriteLine(speSupport);
8747
}
8848
}
8949
}

WindowsPerfGUI/Utils/WperfDefaults.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ namespace WindowsPerfGUI.ToolWindows.SamplingSetting
3333
static class WperfDefaults
3434
{
3535
public const string WPERF_MIN_VERSION = "3.8.0";
36-
36+
public static bool HasSPESupport = false;
3737
#nullable enable
3838
public static string? Frequency;
3939
public static int? TotalGPCNum;

WindowsPerfGUI/WindowsPerfGUIPackage.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,8 @@ protected override async Task OnAfterPackageLoadedAsync(CancellationToken cancel
107107
{
108108
(WperfVersion versions, string stdVersionError) = wperfClient.GetVersion();
109109
if (!string.IsNullOrEmpty(stdVersionError)) throw new Exception("Unable to get WindowsPerf version");
110-
111-
WPerfOptions.Instance.WperfCurrentVersion = versions;
112-
await WPerfOptions.Instance.SaveAsync();
110+
bool speSupport = wperfClient.CheckIsSPESupported();
111+
WPerfOptions.Instance.UpdateWperfOptions(versions, speSupport);
113112
string wperfVersion = versions.Components.FirstOrDefault().ComponentVersion;
114113
if (wperfVersion != WperfDefaults.WPERF_MIN_VERSION)
115114
await VS.MessageBox.ShowWarningAsync(

0 commit comments

Comments
 (0)