Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion stdlib/Profile/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
18 changes: 10 additions & 8 deletions stdlib/Profile/src/Profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -537,7 +539,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
Expand All @@ -554,8 +556,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)
Expand All @@ -572,7 +574,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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions stdlib/Profile/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ end
@test getline(values(fdictc)) == getline(values(fdict0)) + 2
end

import InteractiveUtils

@testset "Module short names" begin
Profile.clear()
@profile InteractiveUtils.peakflops()
io = IOBuffer()
ioc = IOContext(io, :displaysize=>(1000,1000))
Profile.print(ioc, C=true)
str = String(take!(io))
slash = Sys.iswindows() ? "\\" : "/"
@test occursin("@Compiler" * slash, str)
Copy link
Member

Choose a reason for hiding this comment

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

These tests have been seen failing quite frequently in CI since merging. Is there something wrong with the PR or test design?

Copy link
Member Author

Choose a reason for hiding this comment

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

Somehow the profiler sometimes misses all of the compilation. Perhaps peakflops could be replaced with something like putting a sleep in a generated function eval. Or just test the underlying functions more precisely.

@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)
let cmd = Base.julia_cmd()
script = """
Expand Down