503
503
504
504
# Take a file-system path and try to form a concise representation of it
505
505
# based on the package ecosystem
506
- function short_path (spath:: Symbol , filenamecache:: Dict{Symbol, String} )
506
+ function short_path (spath:: Symbol , filenamecache:: Dict{Symbol, Tuple{ String,String} } )
507
507
return get! (filenamecache, spath) do
508
508
path = Base. fixup_stdlib_path (string (spath))
509
509
if isabspath (path)
@@ -523,19 +523,19 @@ function short_path(spath::Symbol, filenamecache::Dict{Symbol, String})
523
523
isempty (pkgid. name) && return path # bad Project file
524
524
# return the joined the module name prefix and path suffix
525
525
path = path[nextind (path, sizeof (root)): end ]
526
- return string (" @" , pkgid. name, path)
526
+ return string (" @" , pkgid. name) , path
527
527
end
528
528
end
529
529
end
530
530
end
531
- return path
531
+ return " " , path
532
532
elseif isfile (joinpath (Sys. BINDIR, Base. DATAROOTDIR, " julia" , " base" , path))
533
533
# do the same mechanic for Base (or Core/Compiler) files as above,
534
534
# but they start from a relative path
535
- return joinpath ( " @Base" , normpath (path) )
535
+ return " @Base" , normpath (path)
536
536
else
537
537
# for non-existent relative paths (such as "REPL[1]"), just consider simplifying them
538
- return normpath (path) # drop leading "./"
538
+ return " " , normpath (path) # drop leading "./"
539
539
end
540
540
end
541
541
end
@@ -766,7 +766,7 @@ function flat(io::IO, data::Vector{UInt64}, lidict::Union{LineInfoDict, LineInfo
766
766
m = m[keep]
767
767
end
768
768
util_perc = (1 - (nsleeping / totalshots)) * 100
769
- filenamemap = Dict {Symbol,String} ()
769
+ filenamemap = Dict {Symbol,Tuple{ String,String} } ()
770
770
if isempty (lilist)
771
771
if is_subsection
772
772
Base. print (io, " Total snapshots: " )
790
790
791
791
function print_flat (io:: IO , lilist:: Vector{StackFrame} ,
792
792
n:: Vector{Int} , m:: Vector{Int} ,
793
- cols:: Int , filenamemap:: Dict{Symbol,String} ,
793
+ cols:: Int , filenamemap:: Dict{Symbol,Tuple{ String,String} } ,
794
794
fmt:: ProfileFormat )
795
795
if fmt. sortedby === :count
796
796
p = sortperm (n)
@@ -802,7 +802,7 @@ function print_flat(io::IO, lilist::Vector{StackFrame},
802
802
lilist = lilist[p]
803
803
n = n[p]
804
804
m = m[p]
805
- filenames = String[short_path (li. file, filenamemap) for li in lilist]
805
+ filenames = String[joinpath ( short_path (li. file, filenamemap) ... ) for li in lilist]
806
806
funcnames = String[string (li. func) for li in lilist]
807
807
wcounts = max (6 , ndigits (maximum (n)))
808
808
wself = max (9 , ndigits (maximum (m)))
@@ -889,7 +889,10 @@ function indent(depth::Int)
889
889
return indent
890
890
end
891
891
892
- function tree_format (frames:: Vector{<:StackFrameTree} , level:: Int , cols:: Int , maxes, filenamemap:: Dict{Symbol,String} , showpointer:: Bool )
892
+ # mimics Stacktraces
893
+ const PACKAGE_FIXEDCOLORS = Dict {String, Any} (" @Base" => :light_black , " @Core" => :light_black )
894
+
895
+ function tree_format (frames:: Vector{<:StackFrameTree} , level:: Int , cols:: Int , maxes, filenamemap:: Dict{Symbol,Tuple{String,String}} , showpointer:: Bool )
893
896
nindent = min (cols>> 1 , level)
894
897
ndigoverhead = ndigits (maxes. overhead)
895
898
ndigcounts = ndigits (maxes. count)
@@ -924,16 +927,20 @@ function tree_format(frames::Vector{<:StackFrameTree}, level::Int, cols::Int, ma
924
927
else
925
928
fname = string (li. func)
926
929
end
927
- filename = short_path (li. file, filenamemap)
930
+ pkgname, filename = short_path (li. file, filenamemap)
928
931
if showpointer
929
932
fname = string (
930
933
" 0x" ,
931
934
string (li. pointer, base = 16 , pad = 2 * sizeof (Ptr{Cvoid})),
932
935
" " ,
933
936
fname)
934
937
end
938
+ pkgcolor = get! (() -> popfirst! (Base. STACKTRACE_MODULECOLORS), PACKAGE_FIXEDCOLORS, pkgname)
939
+ remaining_path = rtruncto (filename, widthfile - length (pkgname) - 1 )
935
940
strs[i] = string (stroverhead, " ╎" , base, strcount, " " ,
936
- rtruncto (filename, widthfile),
941
+ sprint ((io,x) -> printstyled (io, x; color= pkgcolor), pkgname; context= stdout ),
942
+ startswith (remaining_path, " /" ) ? " " : " /" ,
943
+ remaining_path,
937
944
" :" ,
938
945
li. line == - 1 ? " ?" : string (li. line),
939
946
" ; " ,
@@ -1101,7 +1108,7 @@ end
1101
1108
# avoid stack overflows.
1102
1109
function print_tree (io:: IO , bt:: StackFrameTree{T} , cols:: Int , fmt:: ProfileFormat , is_subsection:: Bool ) where T
1103
1110
maxes = maxstats (bt)
1104
- filenamemap = Dict {Symbol,String} ()
1111
+ filenamemap = Dict {Symbol,Tuple{ String,String} } ()
1105
1112
worklist = [(bt, 0 , 0 , " " )]
1106
1113
if ! is_subsection
1107
1114
Base. print (io, " Overhead ╎ [+additional indent] Count File:Line; Function\n " )
0 commit comments