Skip to content

Commit 9590fd5

Browse files
committed
Be more mindful of output file name lengths
This makes the following two changes: - open files for writing by their relative path, which will often be shorter than the absolute path (and in any case the user has more control over any path length issues if they have the option to either expand it or not _before_ calling `statprofhtml()`) - Put a cap on the output file name lengths by using a hash instead of an encoding. This means we have to use bytes2hex rather than base64 because `/` is a valid base64 character. (This was already a bug before, but I probably never ran into it because encoding only paths never results in a `/`.)
1 parent 3af6779 commit 9590fd5

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ author = ["Timo Kluck <tkluck@infty.nl>"]
44
version = "1.3.0"
55

66
[deps]
7-
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
87
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
98
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
109
FlameGraphs = "08572546-2f56-4bcf-ba4e-bab62c3a3f89"
1110
HAML = "0bc81568-2411-4001-9bf1-c899fa54f385"
1211
Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
12+
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
1313
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1414

1515
[compat]
16-
julia = "1.3"
1716
DataStructures = "0.17, 0.18"
1817
FlameGraphs = "0.1, 0.2"
1918
HAML = "0.3.1"
19+
julia = "1.3"

src/HTML.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
module HTML
22

3-
import Base64: base64encode
3+
import SHA: sha1
44

55
import Dates: format, RFC1123Format
66
import HAML: includehaml, @include, @surround, @cdatafile, @output
77

88
import ..Reports: Report, FunctionPoint, TracePoint
99

10+
# needs to be smaller than 250 on MacOS, and anecdotally, the length of a full
11+
# path needs to be at most 260 on Windows. This should give some spare room
12+
# in either case.
13+
const MAX_OUTPUT_FILE_NAME_LENGTH = 150
14+
1015
templatefile(name...) = joinpath(@__DIR__, "..", "haml", name...)
1116

1217
includehaml(@__MODULE__,
@@ -21,7 +26,8 @@ includehaml(@__MODULE__,
2126
outputfilename(::Nothing) = ""
2227
outputfilename(sourcefile::Symbol) = begin
2328
b = basename(string(sourcefile))
24-
x = base64encode(string(sourcefile))
29+
x = bytes2hex(sha1(String(sourcefile)))
30+
b = first(b, MAX_OUTPUT_FILE_NAME_LENGTH - length(x) - length("-.html"))
2531
return "$b-$x.html"
2632
end
2733

src/StatProfilerHTML.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function statprofilehtml(data::Vector{<:Unsigned} = UInt[], litrace::LineInfoDic
2222

2323
report = Report(data, litrace, from_c)
2424
sort!(report)
25-
HTML.output(report, fullpath)
25+
HTML.output(report, path)
2626

2727
@info "Wrote profiling output to file://$fullpath/index.html ."
2828
end

0 commit comments

Comments
 (0)