Skip to content

Commit

Permalink
Format files using DocumentFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff authored Sep 14, 2022
1 parent 3f4e7b7 commit 80adc72
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 37 deletions.
70 changes: 35 additions & 35 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ is a callee and the `positionTicks` represents the location.
mutable struct ProfileNode
id::Int64
callFrame::CallFrame
hitCount::Int64
hitCount::Int64
children::Vector{Int64}
positionTicks::Vector{PositionTickInfo}
end

function enter!(node::ProfileNode, line)
idx = findfirst(tick->tick.line == line, node.positionTicks)
idx = findfirst(tick -> tick.line == line, node.positionTicks)
if idx === nothing
push!(node.positionTicks, PositionTickInfo(line, 1))
else
Expand All @@ -53,11 +53,11 @@ Fetches the collected `Profile` data.
- `period::UInt64`: The sampling period in nanoseconds [optional].
"""

function CPUProfile(data::Union{Nothing, Vector{UInt}} = nothing,
period::Union{Nothing, UInt64} = nothing; from_c = false)
function CPUProfile(data::Union{Nothing,Vector{UInt}}=nothing,
period::Union{Nothing,UInt64}=nothing; from_c=false)
if data === nothing
data = if isdefined(Profile, :has_meta)
copy(Profile.fetch(include_meta = false))
copy(Profile.fetch(include_meta=false))
else
copy(Profile.fetch())
end
Expand All @@ -71,7 +71,7 @@ function CPUProfile(data::Union{Nothing, Vector{UInt}} = nothing,

period = period ÷ 1000 # ns to ms

methods = Dict{Tuple{String, Int64}, CallFrame}()
methods = Dict{Tuple{String,Int64},CallFrame}()
function get_callframe!(url, start_line, name, file)
get!(methods, (url, start_line)) do
CallFrame(name, file, url, start_line, 0)
Expand All @@ -85,8 +85,8 @@ function CPUProfile(data::Union{Nothing, Vector{UInt}} = nothing,
return node
end

samples = Int64[] # Ids of samples leaf.
toplevel = Set{Int64}() # Ids of samples top nodes.
samples = Int64[] # Ids of samples leaf.
toplevel = Set{Int64}() # Ids of samples top nodes.
timeDeltas = Int64[] # Time intervals between adjacent samples in microseconds. The first delta is relative to the profile startTime.

# start decoding backtraces
Expand Down Expand Up @@ -138,9 +138,9 @@ function CPUProfile(data::Union{Nothing, Vector{UInt}} = nothing,
# TODO: stackframes.jl describes this as a top-level frame
linfo = frame.linfo.parent::Core.MethodInstance
end
meth = linfo.def
file = string(meth.file)
name = string(meth.module, ".", meth.name)
meth = linfo.def
file = string(meth.file)
name = string(meth.module, ".", meth.name)
start_line = convert(Int64, meth.line)
end
# TODO: Deal with unkown or unresolved functions
Expand Down Expand Up @@ -192,11 +192,11 @@ function CPUProfile(data::Union{Nothing, Vector{UInt}} = nothing,
start_time = 0
timeDeltas[1] = 0
@assert length(timeDeltas) == length(samples)
return CPUProfile(nodes, start_time, start_time + sum(timeDeltas), samples, timeDeltas)
return CPUProfile(nodes, start_time, start_time + sum(timeDeltas), samples, timeDeltas)
end

function save_cpuprofile(io::IO, data::Union{Nothing, Vector{UInt}} = nothing,
period::Union{Nothing, UInt64} = nothing; kwargs...)
function save_cpuprofile(io::IO, data::Union{Nothing,Vector{UInt}}=nothing,
period::Union{Nothing,UInt64}=nothing; kwargs...)

profile = CPUProfile(data, period; kwargs...)
write(io, '{')
Expand All @@ -212,25 +212,25 @@ function save_cpuprofile(io::IO, data::Union{Nothing, Vector{UInt}} = nothing,
JSON.print(io, "callFrame")
write(io, ':')
write(io, '{')
JSON.print(io, "functionName")
write(io, ':')
JSON.print(io, node.callFrame.functionName)
write(io, ',')
JSON.print(io, "scriptId")
write(io, ':')
JSON.print(io, node.callFrame.scriptId)
write(io, ',')
JSON.print(io, "url")
write(io, ':')
JSON.print(io, node.callFrame.url)
write(io, ',')
JSON.print(io, "lineNumber")
write(io, ':')
JSON.print(io, node.callFrame.lineNumber)
write(io, ',')
JSON.print(io, "columnNumber")
write(io, ':')
JSON.print(io, node.callFrame.columnNumber)
JSON.print(io, "functionName")
write(io, ':')
JSON.print(io, node.callFrame.functionName)
write(io, ',')
JSON.print(io, "scriptId")
write(io, ':')
JSON.print(io, node.callFrame.scriptId)
write(io, ',')
JSON.print(io, "url")
write(io, ':')
JSON.print(io, node.callFrame.url)
write(io, ',')
JSON.print(io, "lineNumber")
write(io, ':')
JSON.print(io, node.callFrame.lineNumber)
write(io, ',')
JSON.print(io, "columnNumber")
write(io, ':')
JSON.print(io, node.callFrame.columnNumber)
write(io, '}')
write(io, ',')
JSON.print(io, "hitCount")
Expand Down Expand Up @@ -281,8 +281,8 @@ function save_cpuprofile(io::IO, data::Union{Nothing, Vector{UInt}} = nothing,
nothing
end

function save_cpuprofile(filename::AbstractString, data::Union{Nothing, Vector{UInt}} = nothing,
period::Union{Nothing, UInt64} = nothing; kwargs...)
function save_cpuprofile(filename::AbstractString, data::Union{Nothing,Vector{UInt}}=nothing,
period::Union{Nothing,UInt64}=nothing; kwargs...)

open(filename, "w") do io
save_cpuprofile(io, data, period; kwargs...)
Expand Down
3 changes: 1 addition & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Test

@testset "ChromeProfileFormat" begin
end
@testset "ChromeProfileFormat" begin end

0 comments on commit 80adc72

Please sign in to comment.