API to retrieve CPU and App architecture #7
Description
The goal is to have a simple API that will return:
- Operating system architecture
- Application architecture
SharpRaven has some implementation although it mixes things a bit:
One thing to keep in mind is the difference of OS arch and App arch. An app can be 32 bit on a 64 bit operating system.
.NET Standard 2.0 include API for both:
RuntimeInformation.OSArchitecture
RuntimeInformation.ProcessArchitecture
Both return a value from the enum:
public enum Architecture
{
X86, X64, Arm, Arm64,
}
That is good news. It is also supported by Xamarin/iOS/Mac/Android but we still need to find a way on other targets since this is not available on .NET Framework prior to 4.7.1 according to MSDN
To verify the CPU arch, the SharpRaven version linked above also considers environment variable, which should always be available on Windows but is not reliable on macOS nor Linux since it's non-POSIX, bash extension. The code also calls into Win32 API when verifying the OS version supports it. It does so without a IsWindows
call before doing so. This should be considered on the new implementation.
To check the App arch, a reliable way is simply: IntPtr.Size == 8
means 64bit. Although not sure if it's ia32 or arm32 or what. With that it's also known that the OS arch is 64 bit which could be a quick path for OS arch API.
On Windows a platform call like this can be considered.
A possibility for macOS, with P/Invoke is get_arch_name_from_types
As any other API in this repo, would be great to get it tested with CoreRT or other AoT runtimes like Unity or what not.
Benchmarking different calls would be interesting although challenging since the benchmark will behave differently in different platforms.