Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display sys infos #46

Merged
merged 15 commits into from
Feb 23, 2024
Merged

feat: display sys infos #46

merged 15 commits into from
Feb 23, 2024

Conversation

hendriknielaender
Copy link
Owner

@hendriknielaender hendriknielaender commented Feb 6, 2024

Implement enhanced system information retrieval for Linux, macOS, and Windows within platform.zig. This includes accurate fetching of CPU name, core count, and total memory.

  • OS
  • Arch
  • CPU Name
  • CPU cores
  • Memory

Tested on:

  • MacOS
  • Linux
  • Windows

@hendriknielaender hendriknielaender added the enhancement New feature or request label Feb 6, 2024
@hendriknielaender hendriknielaender self-assigned this Feb 6, 2024
@hendriknielaender hendriknielaender marked this pull request as ready for review February 11, 2024 10:36
@FObersteiner
Copy link
Collaborator

I've modified a few thing on the Linux side of things. Overall, I think this is a cool feature :) I'm not sure if /proc/cpuinfo (meminfo) is available on all Linuxes (there are plenty...) but we can fix that later on I guess, if somebody really needs it.

@hendriknielaender
Copy link
Owner Author

I've modified a few thing on the Linux side of things. Overall, I think this is a cool feature :) I'm not sure if /proc/cpuinfo (meminfo) is available on all Linuxes (there are plenty...) but we can fix that later on I guess, if somebody really needs it.

Thanks for improving & testing it 👍 Totally agree, if there is a distro where its missing we will fix this in the future.

}

fn exec(allocator: std.mem.Allocator, args: []const []const u8) ![]const u8 {
const stdout = (try std.ChildProcess.exec(.{ .allocator = allocator, .argv = args })).stdout;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works when compiled in Debug and ReleaseFast mode but causes an "unreachable code" exception in ReleaseSafe. Haven't found out why yet...

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most likely that happens due to a failed assertion or an error that is not properly handled. I don't really know the zig internals for handling this case in ReleaseSafe.

const result = std.ChildProcess.exec(.{ .allocator = allocator, .argv = args }) catch |err| {
  return err;
};
const stdout = result.stdout;
`
``

util/os/windows.zig Show resolved Hide resolved
util/os/osx.zig Outdated Show resolved Hide resolved
util/os/windows.zig Show resolved Hide resolved
@Bryysen
Copy link
Collaborator

Bryysen commented Feb 17, 2024

Sorry for being late to the party! First of all this a cool feature. I've skimmed through the code but I'll need more time to digest some of it because I'm not too familiar with platform-specific problems like this. I did test it on my Linux machine and it works fine, however when I quickly tested it on my Windows machine I got the compilation errors

Error message
  C:\Users\USERNAME\Desktop\zBench-main>"..\zig-windows-x86_64-0.11.0\zig.exe" build test_examples
  zig test basic Debug native: error: the following command failed with 1 compilation errors:
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\zig.exe test C:\Users\King\Desktop\zBench-main\examples\basic.zig --cache-dir C:\Users\King\Desktop\zBench-main\zig-c
  zig test bubble_sort Debug native: error: the following command failed with 1 compilation errors:
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\zig.exe test C:\Users\King\Desktop\zBench-main\examples\bubble_sort.zig --cache-dir C:\Users\King\Desktop\zBench-main
  zig test sleep Debug native: error: the following command failed with 1 compilation errors:
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\zig.exe test C:\Users\King\Desktop\zBench-main\examples\sleep.zig --cache-dir C:\Users\King\Desktop\zBench-main\zig-c
  Build Summary: 0/7 steps succeeded; 3 failed (disable with --summary none)
  test_examples transitive failure
  +- zig test basic Debug native 1 errors
  +- install basic transitive failure
  |  +- zig test basic Debug native (reused)
  +- zig test bubble_sort Debug native 1 errors
  +- install bubble_sort transitive failure
  |  +- zig test bubble_sort Debug native (reused)
  +- zig test sleep Debug native 1 errors
  +- install sleep transitive failure
     +- zig test sleep Debug native (reused)
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\lib\std\os\windows.zig:1892:28: error: unable to evaluate comptime expression
                  break :blk asm volatile (
                             ^~~
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\lib\std\os\windows.zig:1907:15: note: called from here
      return teb().ProcessEnvironmentBlock;
             ~~~^~                                                                           
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\lib\std\io.zig:36:30: note: called from here
          return os.windows.peb().ProcessParameters.hStdOutput;                                    
                 ~~~~~~~~~~~~~~^~ 
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\lib\std\io.zig:50:34: note: called from here
          .handle = getStdOutHandle(),
                    ~~~~~~~~~~~~~~~^~                                       
  zbench.zig:251:125: note: called from here
      out_stream: std.io.BufferedWriter(1024, @TypeOf(std.io.getStdOut().writer())) = .{ .unbuffered_writer = std.io.getStdOut().writer() },
                                                                                                              ~~~~~~~~~~~~~~~~^~
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\lib\std\os\windows.zig:1892:28: error: unable to evaluate comptime expression
                  break :blk asm volatile (
                             ^~~
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\lib\std\os\windows.zig:1907:15: note: called from here
      return teb().ProcessEnvironmentBlock;
             ~~~^~
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\lib\std\io.zig:36:30: note: called from here
          return os.windows.peb().ProcessParameters.hStdOutput;
                 ~~~~~~~~~~~~~~^~
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\lib\std\io.zig:50:34: note: called from here
          .handle = getStdOutHandle(),
                    ~~~~~~~~~~~~~~~^~
  zbench.zig:251:125: note: called from here
      out_stream: std.io.BufferedWriter(1024, @TypeOf(std.io.getStdOut().writer())) = .{ .unbuffered_writer = std.io.getStdOut().writer() },
                                                                                                              ~~~~~~~~~~~~~~~~^~
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\lib\std\os\windows.zig:1892:28: error: unable to evaluate comptime expression
                  break :blk asm volatile (
                             ^~~
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\lib\std\os\windows.zig:1907:15: note: called from here
      return teb().ProcessEnvironmentBlock;
             ~~~^~
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\lib\std\io.zig:36:30: note: called from here
          return os.windows.peb().ProcessParameters.hStdOutput;
                 ~~~~~~~~~~~~~~^~
  C:\Users\USERNAME\Desktop\zig-windows-x86_64-0.11.0\lib\std\io.zig:50:34: note: called from here
          .handle = getStdOutHandle(),
                    ~~~~~~~~~~~~~~~^~
  zbench.zig:251:125: note: called from here
      out_stream: std.io.BufferedWriter(1024, @TypeOf(std.io.getStdOut().writer())) = .{ .unbuffered_writer = std.io.getStdOut().writer() },

Which point to an error on this line and shouldn't even be related to this PR I'm pretty sure 😅

I'll look into this later when I get some time

@FObersteiner
Copy link
Collaborator

FObersteiner commented Feb 17, 2024

Which point to an error on this line and shouldn't even be related to this PR I'm pretty sure 😅

I'll look into this later when I get some time

looks like #49 to me - we might move tackling this issue to a bigger overhaul, which you drafted in #39 ?

@Bryysen
Copy link
Collaborator

Bryysen commented Feb 17, 2024

Which point to an error on this line and shouldn't even be related to this PR I'm pretty sure 😅
I'll look into this later when I get some time

looks like #49 to me

I've been gone for a while so I haven't been up to date with the latest issues, my bad! Yeah I'll sort this out ASAP (I'm confused how the PR that introduced the change passed the CI though? 🤔)

@FObersteiner
Copy link
Collaborator

FObersteiner commented Feb 17, 2024

I'm confused how the PR that introduced the change passed the CI though? 🤔

good point; I'm not sure what exactly windows-latest encompasses - I ran this on a "real" Windows 10 (Enterprise) machine and I guess Windows != Windows

edit: it's Windows Server. Historically, those have been quiet different compared to "normal" Windows OS

@Bryysen
Copy link
Collaborator

Bryysen commented Feb 20, 2024

Alright #51 should sort the windows issue out, once that gets merged we should be able to test this feature on windows.

@FObersteiner
Copy link
Collaborator

FObersteiner commented Feb 23, 2024

Alright #51 should sort the windows issue out, once that gets merged we should be able to test this feature on windows.

I think this PR #46 can be merged as well, right?

@hendriknielaender hendriknielaender merged commit a211139 into main Feb 23, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants