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

add missing docstrings for Base.Sys #52777

Merged
merged 36 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
424998b
Added Docstring for Base.sys :CPU_NAME,JIT,cpu_info,cpu_summary
11happy Jan 6, 2024
7fa4956
Removed Whitespace
11happy Jan 6, 2024
1205874
Incorporated suggestions as per documentation style
11happy Jan 7, 2024
d70aa64
Removed Jldoctest
11happy Jan 7, 2024
2e70a60
Update base/sysinfo.jl
11happy Jan 8, 2024
321f497
Update base/sysinfo.jl
11happy Jan 8, 2024
28df075
Update base/sysinfo.jl
11happy Jan 8, 2024
4e20ecc
Update base/sysinfo.jl
11happy Jan 8, 2024
aab0507
Suggested Changes
11happy Jan 8, 2024
f1a6291
Removed White Space
11happy Jan 8, 2024
e84a16a
Removed White Space
11happy Jan 8, 2024
2096423
Added show function
11happy Jan 11, 2024
3e63af5
Formatted the code
11happy Jan 11, 2024
3f38416
Fixed/Added Suggested Changes
11happy Jan 11, 2024
0a3cf6f
Removed WhiteSpace
11happy Jan 11, 2024
e11dfd9
Added Space
11happy Jan 11, 2024
eaf73a8
Added Proper Indent
11happy Jan 11, 2024
3f6bec7
Update base/sysinfo.jl
11happy Jan 11, 2024
88e6fae
Update base/sysinfo.jl
11happy Jan 11, 2024
f35cb86
suggested changed
11happy Jan 11, 2024
a41c271
Merge branch 'FourthPR' of https://github.com/11happy/julia into Four…
11happy Jan 11, 2024
526ac1e
Public CPUinfo,Added Tests for show
11happy Jan 12, 2024
60fdb2f
Update base/sysinfo.jl
11happy Jan 13, 2024
fc3d652
Update test/sysinfo.jl
11happy Jan 13, 2024
4b3722a
minor fixes
11happy Jan 13, 2024
8f84372
added cpu_summary method
11happy Jan 13, 2024
8d92a49
removed export of Sys.JIT,Sys.CPU_NAME,Sys.cpu_summary,Sys.cpu_info
11happy Jan 15, 2024
143169d
resolved merge conflict
11happy Jan 16, 2024
3309d86
Update base/sysinfo.jl
11happy Jan 16, 2024
5e2cdbd
Update test/sysinfo.jl
11happy Jan 16, 2024
06f5a4c
Update base/sysinfo.jl
11happy Jan 16, 2024
6cf7d26
Update base/sysinfo.jl
11happy Jan 16, 2024
718740e
Update base/sysinfo.jl
11happy Jan 16, 2024
adbf6b0
Update base/sysinfo.jl
11happy Jan 16, 2024
a391a4e
Formatted the code
11happy Jan 16, 2024
d4e3a3d
Update test/sysinfo.jl
stevengj Jan 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 75 additions & 2 deletions base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,37 @@ Standard word size on the current machine, in bits.
"""
const WORD_SIZE = Core.sizeof(Int) * 8

global SC_CLK_TCK::Clong, CPU_NAME::String, JIT::String
global SC_CLK_TCK::Clong
11happy marked this conversation as resolved.
Show resolved Hide resolved

"""
stevengj marked this conversation as resolved.
Show resolved Hide resolved
Sys.CPU_NAME::String

A string representing the name of CPU.
stevengj marked this conversation as resolved.
Show resolved Hide resolved

# Examples
For example, `Sys.CPU_NAME` might equal `"tigerlake"` on an
[Intel Core "Tiger Lake" CPU](https://en.wikipedia.org/wiki/Tiger_Lake),
or `"apple-m1"` on an [Apple M1 CPU](https://en.wikipedia.org/wiki/Apple_M1).

Note: Included in the detailed system information via `versioninfo(verbose=true)`.
"""
global CPU_NAME::String

"""
Sys.JIT::String

A string representing the specific Just-In-Time (JIT) compiler being utilized in the current runtime.
stevengj marked this conversation as resolved.
Show resolved Hide resolved

# Examples
Currently, this equals `"ORCJIT"` for the LLVM "ORC" ("On-Request Compilation") JIT library:
```jldoctest
julia> Sys.JIT
"ORCJIT"
```
11happy marked this conversation as resolved.
Show resolved Hide resolved

Note: Included in the detailed system information via `versioninfo(verbose=true)`.
"""
global JIT::String

function __init__()
env_threads = nothing
Expand Down Expand Up @@ -139,6 +169,24 @@ mutable struct UV_cpu_info_t
cpu_times!idle::UInt64
cpu_times!irq::UInt64
end

"""
11happy marked this conversation as resolved.
Show resolved Hide resolved
Sys.CPUinfo

The `CPUinfo` type is a mutable struct with the following fields:
- `model::String`: CPU model information.
- `speed::Int32`: CPU speed (in MHz).
- `cpu_times!user::UInt64`: Time spent in user mode. CPU state shows CPU time used by user space processes.
11happy marked this conversation as resolved.
Show resolved Hide resolved
- `cpu_times!nice::UInt64`: Time spent in nice mode. CPU state is a subset of the "user" state and shows the CPU time used by processes that have a positive niceness, meaning a lower priority than other tasks.
- `cpu_times!sys::UInt64`: Time spent in system mode. CPU state shows the amount of CPU time used by the kernel.
- `cpu_times!idle::UInt64`: Time spent in idle mode. CPU state shows the CPU time that's not actively being used.
- `cpu_times!irq::UInt64`: Time spent handling interrupts. CPU state shows the amount of time the CPU has been servicing hardware interrupts.

11happy marked this conversation as resolved.
Show resolved Hide resolved
The times are in units of `1/Sys.SC_CLK_TCK` seconds if `Sys.SC_CLK_TCK > 0`; otherwise they are in
unknown units.

Note: Included in the detailed system information via `versioninfo(verbose=true)`.
"""
mutable struct CPUinfo
model::String
speed::Int32
Expand All @@ -153,6 +201,8 @@ CPUinfo(info::UV_cpu_info_t) = CPUinfo(unsafe_string(info.model), info.speed,
info.cpu_times!user, info.cpu_times!nice, info.cpu_times!sys,
info.cpu_times!idle, info.cpu_times!irq)

public CPUinfo

function _show_cpuinfo(io::IO, info::Sys.CPUinfo, header::Bool=true, prefix::AbstractString=" ")
tck = SC_CLK_TCK
if header
Expand All @@ -174,7 +224,7 @@ function _show_cpuinfo(io::IO, info::Sys.CPUinfo, header::Bool=true, prefix::Abs
end
end

show(io::IO, info::CPUinfo) = _show_cpuinfo(io, info, true, " ")
show(io::IO, ::MIME"text/plain", info::CPUinfo) = _show_cpuinfo(io, info, true, " ")

function _cpu_summary(io::IO, cpu::AbstractVector{CPUinfo}, i, j)
if j-i < 9
Expand All @@ -201,6 +251,17 @@ function _cpu_summary(io::IO, cpu::AbstractVector{CPUinfo}, i, j)
println(io)
end

"""
Sys.cpu_summary(io::IO=stdout, cpu::AbstractVector{CPUinfo}=cpu_info())

Print a summary of CPU information to the `io` stream (defaulting to [`stdout`](@ref)), organizing and displaying aggregated data for CPUs with the same model, for a given array of `CPUinfo` data structures
describing a set of CPUs (which defaults to the return value of the [`Sys.cpu_info`](@ref) function).

The summary includes aggregated information for each distinct CPU model,
providing details such as average CPU speed and total time spent in different modes (user, nice, sys, idle, irq) across all cores with the same model.
stevengj marked this conversation as resolved.
Show resolved Hide resolved

Note: Included in the detailed system information via `versioninfo(verbose=true)`.
"""
function cpu_summary(io::IO=stdout, cpu::AbstractVector{CPUinfo} = cpu_info())
model = cpu[1].model
first = 1
Expand All @@ -213,6 +274,18 @@ function cpu_summary(io::IO=stdout, cpu::AbstractVector{CPUinfo} = cpu_info())
_cpu_summary(io, cpu, first, length(cpu))
end

"""
Sys.cpu_info()

Return a vector of `CPUinfo` objects, where each object represents information about a CPU core.

This is pretty-printed in a tabular format by `Sys.cpu_summary`, which is included in the output
of `versioninfo(verbose=true)`, so most users will not need to access the `CPUinfo`
data structures directly.

The function provides information about each CPU, including model, speed, and usage statistics such as user time, nice time, system time, idle time, and interrupt time.

"""
function cpu_info()
UVcpus = Ref{Ptr{UV_cpu_info_t}}()
count = Ref{Int32}()
Expand Down
17 changes: 14 additions & 3 deletions test/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,18 @@ end
end

@testset "Base.Sys docstrings" begin
undoc = Docs.undocumented_names(Sys)
@test_broken isempty(undoc)
@test undoc == [:CPU_NAME, :JIT, :cpu_info, :cpu_summary]
@test isempty(Docs.undocumented_names(Sys))
end

@testset "show" begin
example_cpus = [Base.Sys.CPUinfo("Apple M1 Pro", 2400, 0x000000000d913b08, 0x0000000000000000, 0x0000000005f4243c, 0x00000000352a550a, 0x0000000000000000)
Base.Sys.CPUinfo("Apple M1 Pro", 2400, 0x000000000d9040c2, 0x0000000000000000, 0x0000000005d4768c, 0x00000000356b3d22, 0x0000000000000000)
Base.Sys.CPUinfo("Apple M1 Pro", 2400, 0x00000000026784da, 0x0000000000000000, 0x0000000000fda30e, 0x0000000046a731ea, 0x0000000000000000)
Base.Sys.CPUinfo("Apple M1 Pro", 2400, 0x00000000017726c0, 0x0000000000000000, 0x00000000009491de, 0x0000000048134f1e, 0x0000000000000000)]

@test repr(example_cpus[1]) == "Base.Sys.CPUinfo(\"Apple M1 Pro\", 2400, 0x000000000d913b08, 0x0000000000000000, 0x0000000005f4243c, 0x00000000352a550a, 0x0000000000000000)"
@test repr("text/plain", example_cpus[1]) == "Apple M1 Pro: \n speed user nice sys idle irq\n 2400 MHz 2276216 s 0 s 998861 s 8919667 s 0 s"
stevengj marked this conversation as resolved.
Show resolved Hide resolved
Sys.SC_CLK_TCK, save_SC_CLK_TCK = 100, Sys.SC_CLK_TCK
stevengj marked this conversation as resolved.
Show resolved Hide resolved
@test sprint(Sys.cpu_summary, example_cpus) == "Apple M1 Pro: \n speed user nice sys idle irq\n#1 2400 MHz 2276216 s 0 s 998861 s 8919667 s 0 s\n#2 2400 MHz 2275576 s 0 s 978101 s 8962204 s 0 s\n#3 2400 MHz 403386 s 0 s 166224 s 11853624 s 0 s\n#4 2400 MHz 245859 s 0 s 97367 s 12092250 s 0 s\n"
Sys.SC_CLK_TCK = save_SC_CLK_TCK
end