<commit_before>module ProfileView

using Color, Base.Graphics

if isdefined(Main, :PROFILEVIEW_USETK)
    useTk = Main.PROFILEVIEW_USETK
else
    useTk = !isdefined(Main, :IJulia)
end
if useTk
    using Tk
    import Cairo
    include(joinpath(Pkg.dir(), "ImageView", "src", "rubberband.jl")) # for zoom
    type ZoomCanvas
        bb::BoundingBox  # in user-coordinates
        c::Canvas
    end
end
include("svgwriter.jl")

import Base: contains, isequal, show, mimewritable, writemime

include("tree.jl")
include("pvtree.jl")

using .Tree
using .PVTree

immutable TagData
    ip::Uint
    status::Int
end
const TAGNONE = TagData(uint(0), -1)

type ProfileData
    img
    lidict
    imgtags
    fontsize
end

const bkg = color("black")
const fontcolor = color("white")
const gccolor = color("red")
const colors = distinguishable_colors(13, [bkg,fontcolor,gccolor])[4:end]

function prepare(data; C = false, lidict = nothing, colorgc = true, combine = true)
    bt, counts = Profile.tree_aggregate(data)
    if isempty(counts)
        Profile.warning_empty()
        return
    end
    len = Int[length(x) for x in bt]
    keep = len .> 0
    if length(data) == Profile.maxlen_data()
        keep[end] = false
    end
    bt = bt[keep]
    counts = counts[keep]
    # Do code address lookups on all unique instruction pointers
    uip = unique(vcat(bt...))
    nuip = length(uip)
    if lidict == nothing
        lkup = [Profile.lookup(ip) for ip in uip]
        lidict = Dict(uip, lkup)
    else
        lkup = [lidict[ip] for ip in uip]
    end<commit_msg>Throw an error for empty inputs.<commit_after>module ProfileView

using Color, Base.Graphics

if isdefined(Main, :PROFILEVIEW_USETK)
    useTk = Main.PROFILEVIEW_USETK
else
    useTk = !isdefined(Main, :IJulia)
end
if useTk
    using Tk
    import Cairo
    include(joinpath(Pkg.dir(), "ImageView", "src", "rubberband.jl")) # for zoom
    type ZoomCanvas
        bb::BoundingBox  # in user-coordinates
        c::Canvas
    end
end
include("svgwriter.jl")

import Base: contains, isequal, show, mimewritable, writemime

include("tree.jl")
include("pvtree.jl")

using .Tree
using .PVTree

immutable TagData
    ip::Uint
    status::Int
end
const TAGNONE = TagData(uint(0), -1)

type ProfileData
    img
    lidict
    imgtags
    fontsize
end

const bkg = color("black")
const fontcolor = color("white")
const gccolor = color("red")
const colors = distinguishable_colors(13, [bkg,fontcolor,gccolor])[4:end]

function prepare(data; C = false, lidict = nothing, colorgc = true, combine = true)
    bt, counts = Profile.tree_aggregate(data)
    if isempty(counts)
        Profile.warning_empty()
        error("Nothing to view")
    end
    len = Int[length(x) for x in bt]
    keep = len .> 0
    if length(data) == Profile.maxlen_data()
        keep[end] = false
    end
    bt = bt[keep]
    counts = counts[keep]
    # Do code address lookups on all unique instruction pointers
    uip = unique(vcat(bt...))
    nuip = length(uip)
    if lidict == nothing
        lkup = [Profile.lookup(ip) for ip in uip]
        lidict = Dict(uip, lkup)
    else
        lkup = [lidict[ip] for ip in uip]
    end
{'fraction_non_alphanumeric': 0.11118150142540387, 'fraction_numerical': 0.003801076971808679, 'mean_word_length': 3.1066319895968793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '188559', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1090, 'n_words': 302}