From 3d7ede1657fcc3a5944d0ed8d139b4fbb989330c Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 20 Nov 2024 14:24:22 -0500 Subject: [PATCH 1/6] fix short_path bug --- stdlib/Profile/src/Profile.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/Profile/src/Profile.jl b/stdlib/Profile/src/Profile.jl index 409696c8c9354..3086a9c34e07f 100644 --- a/stdlib/Profile/src/Profile.jl +++ b/stdlib/Profile/src/Profile.jl @@ -572,7 +572,7 @@ function short_path(spath::Symbol, filenamecache::Dict{Symbol, Tuple{String,Stri project_file = joinpath(root, proj) if Base.isfile_casesensitive(project_file) pkgid = Base.project_file_name_uuid(project_file, "") - isempty(pkgid.name) && return path # bad Project file + isempty(pkgid.name) && return path, "", path # bad Project file # return the joined the module name prefix and path suffix _short_path = path[nextind(path, sizeof(root)):end] return path, string("@", pkgid.name), _short_path From c61b2f0a1b95271f9d4249617ceb7e87811e2a5c Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 20 Nov 2024 14:24:29 -0500 Subject: [PATCH 2/6] fix Compiler path --- stdlib/Profile/src/Profile.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/Profile/src/Profile.jl b/stdlib/Profile/src/Profile.jl index 3086a9c34e07f..c70e602ab6687 100644 --- a/stdlib/Profile/src/Profile.jl +++ b/stdlib/Profile/src/Profile.jl @@ -537,7 +537,7 @@ function flatten(data::Vector, lidict::LineInfoDict) end const SRC_DIR = normpath(joinpath(Sys.BUILD_ROOT_PATH, "src")) -const COMPILER_DIR = "././../usr/share/julia/Compiler/" +const COMPILER_DIR = "../usr/share/julia/Compiler/" # Take a file-system path and try to form a concise representation of it # based on the package ecosystem From 3f90bba53846b2503c1b2f44e8ba1923f4bc6b14 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 20 Nov 2024 14:24:39 -0500 Subject: [PATCH 3/6] test Module short names --- stdlib/Profile/test/runtests.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/stdlib/Profile/test/runtests.jl b/stdlib/Profile/test/runtests.jl index c1cb86d84975a..cef81be502d6f 100644 --- a/stdlib/Profile/test/runtests.jl +++ b/stdlib/Profile/test/runtests.jl @@ -204,6 +204,21 @@ end @test getline(values(fdictc)) == getline(values(fdict0)) + 2 end +@testset "Module short names" begin + Profile.clear() + @profile peakflops() + io = IOBuffer() + IOContext(io, :displaysize=>(1000,1000)) + Profile.print(ioc, C=true) + str = String(take!(io)) + @test occursin("@Compiler/src", str) + @test occursin("@Base/src", str) + @test occursin("@InteractiveUtils/src", str) + @test occursin("@LinearAlgebra/src", str) + @test occursin("@juliasrc", str) + @test occursin("@julialib", str) +end + # Profile deadlocking in compilation (debuginfo registration) let cmd = Base.julia_cmd() script = """ From 299f2e4f641d8ec2350dc879ec8b59a70022da83 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 20 Nov 2024 15:59:30 -0500 Subject: [PATCH 4/6] fixes --- stdlib/Profile/Project.toml | 3 ++- stdlib/Profile/src/Profile.jl | 4 ++-- stdlib/Profile/test/runtests.jl | 18 ++++++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/stdlib/Profile/Project.toml b/stdlib/Profile/Project.toml index 13cd11f70d9b4..6b70f9c7cd19d 100644 --- a/stdlib/Profile/Project.toml +++ b/stdlib/Profile/Project.toml @@ -10,9 +10,10 @@ StyledStrings = "1.11.0" [extras] Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" +InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Base64", "Logging", "Serialization", "Test"] +test = ["Base64", "InteractiveUtils", "Logging", "Serialization", "Test"] diff --git a/stdlib/Profile/src/Profile.jl b/stdlib/Profile/src/Profile.jl index c70e602ab6687..502574b366d21 100644 --- a/stdlib/Profile/src/Profile.jl +++ b/stdlib/Profile/src/Profile.jl @@ -554,8 +554,8 @@ function short_path(spath::Symbol, filenamecache::Dict{Symbol, Tuple{String,Stri elseif startswith(path_norm, lib_dir) remainder = only(split(path_norm, lib_dir, keepempty=false)) return (isfile(path_norm) ? path_norm : ""), "@julialib", remainder - elseif startswith(path, COMPILER_DIR) - remainder = only(split(path, COMPILER_DIR, keepempty=false)) + elseif contains(path, COMPILER_DIR) + remainder = split(path, COMPILER_DIR, keepempty=false)[end] possible_compiler_path = normpath(joinpath(Sys.BINDIR, Base.DATAROOTDIR, "julia", "Compiler", remainder)) return (isfile(possible_compiler_path) ? possible_compiler_path : ""), "@Compiler", remainder elseif isabspath(path) diff --git a/stdlib/Profile/test/runtests.jl b/stdlib/Profile/test/runtests.jl index cef81be502d6f..f07c521ca4c78 100644 --- a/stdlib/Profile/test/runtests.jl +++ b/stdlib/Profile/test/runtests.jl @@ -204,19 +204,21 @@ end @test getline(values(fdictc)) == getline(values(fdict0)) + 2 end +import InteractiveUtils + @testset "Module short names" begin Profile.clear() - @profile peakflops() + @profile InteractiveUtils.peakflops() io = IOBuffer() - IOContext(io, :displaysize=>(1000,1000)) + ioc = IOContext(io, :displaysize=>(1000,1000)) Profile.print(ioc, C=true) str = String(take!(io)) - @test occursin("@Compiler/src", str) - @test occursin("@Base/src", str) - @test occursin("@InteractiveUtils/src", str) - @test occursin("@LinearAlgebra/src", str) - @test occursin("@juliasrc", str) - @test occursin("@julialib", str) + @test occursin("@Compiler/src/", str) + @test occursin("@Base/", str) + @test occursin("@InteractiveUtils/src/", str) + @test occursin("@LinearAlgebra/src/", str) + @test occursin("@juliasrc/", str) + @test occursin("@julialib/", str) end # Profile deadlocking in compilation (debuginfo registration) From 98ef6645bc6567345dbbc0eb88bd7415fecb2fd5 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 20 Nov 2024 22:15:42 -0500 Subject: [PATCH 5/6] make tests robust to windows --- stdlib/Profile/test/runtests.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stdlib/Profile/test/runtests.jl b/stdlib/Profile/test/runtests.jl index f07c521ca4c78..7f0b8f4084c42 100644 --- a/stdlib/Profile/test/runtests.jl +++ b/stdlib/Profile/test/runtests.jl @@ -213,10 +213,10 @@ import InteractiveUtils ioc = IOContext(io, :displaysize=>(1000,1000)) Profile.print(ioc, C=true) str = String(take!(io)) - @test occursin("@Compiler/src/", str) + @test occursin("@Compiler/", str) @test occursin("@Base/", str) - @test occursin("@InteractiveUtils/src/", str) - @test occursin("@LinearAlgebra/src/", str) + @test occursin("@InteractiveUtils/", str) + @test occursin("@LinearAlgebra/", str) @test occursin("@juliasrc/", str) @test occursin("@julialib/", str) end From 982f9dc8f1c1a3ecf55185e79e64459b145847f6 Mon Sep 17 00:00:00 2001 From: Ian Butterworth Date: Wed, 20 Nov 2024 22:56:18 -0500 Subject: [PATCH 6/6] fixes for windows --- stdlib/Profile/src/Profile.jl | 10 ++++++---- stdlib/Profile/test/runtests.jl | 13 +++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/stdlib/Profile/src/Profile.jl b/stdlib/Profile/src/Profile.jl index 502574b366d21..f59b49d8a4a36 100644 --- a/stdlib/Profile/src/Profile.jl +++ b/stdlib/Profile/src/Profile.jl @@ -43,6 +43,8 @@ using StyledStrings: @styled_str const nmeta = 4 # number of metadata fields per block (threadid, taskid, cpu_cycle_clock, thread_sleeping) +const slash = Sys.iswindows() ? "\\" : "/" + # deprecated functions: use `getdict` instead lookup(ip::UInt) = lookup(convert(Ptr{Cvoid}, ip)) @@ -944,8 +946,8 @@ function print_flat(io::IO, lilist::Vector{StackFrame}, Base.printstyled(io, pkgname, color=pkgcolor) file_trunc = ltruncate(file, max(1, wfile)) wpad = wfile - textwidth(pkgname) - if !isempty(pkgname) && !startswith(file_trunc, "/") - Base.print(io, "/") + if !isempty(pkgname) && !startswith(file_trunc, slash) + Base.print(io, slash) wpad -= 1 end if isempty(path) @@ -1048,8 +1050,8 @@ function tree_format(frames::Vector{<:StackFrameTree}, level::Int, cols::Int, ma pkgcolor = get!(() -> popfirst!(Base.STACKTRACE_MODULECOLORS), PACKAGE_FIXEDCOLORS, pkgname) remaining_path = ltruncate(filename, max(1, widthfile - textwidth(pkgname) - 1)) linenum = li.line == -1 ? "?" : string(li.line) - slash = (!isempty(pkgname) && !startswith(remaining_path, "/")) ? "/" : "" - styled_path = styled"{$pkgcolor:$pkgname}$slash$remaining_path:$linenum" + _slash = (!isempty(pkgname) && !startswith(remaining_path, slash)) ? slash : "" + styled_path = styled"{$pkgcolor:$pkgname}$(_slash)$remaining_path:$linenum" rich_file = if isempty(path) styled_path else diff --git a/stdlib/Profile/test/runtests.jl b/stdlib/Profile/test/runtests.jl index 7f0b8f4084c42..b73a2a618011b 100644 --- a/stdlib/Profile/test/runtests.jl +++ b/stdlib/Profile/test/runtests.jl @@ -213,12 +213,13 @@ import InteractiveUtils ioc = IOContext(io, :displaysize=>(1000,1000)) Profile.print(ioc, C=true) str = String(take!(io)) - @test occursin("@Compiler/", str) - @test occursin("@Base/", str) - @test occursin("@InteractiveUtils/", str) - @test occursin("@LinearAlgebra/", str) - @test occursin("@juliasrc/", str) - @test occursin("@julialib/", str) + slash = Sys.iswindows() ? "\\" : "/" + @test occursin("@Compiler" * slash, str) + @test occursin("@Base" * slash, str) + @test occursin("@InteractiveUtils" * slash, str) + @test occursin("@LinearAlgebra" * slash, str) + @test occursin("@juliasrc" * slash, str) + @test occursin("@julialib" * slash, str) end # Profile deadlocking in compilation (debuginfo registration)