Skip to content

Commit

Permalink
Merge branch 'master' of github.com:JuliaLang/julia into jb/newvars
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jul 31, 2013
2 parents d02f613 + b6b4f02 commit f811533
Show file tree
Hide file tree
Showing 6 changed files with 269 additions and 83 deletions.
42 changes: 19 additions & 23 deletions base/pkg2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,36 +76,32 @@ clone(url::String, pkg::String=urlpkg(url); opts::Cmd=``) = Dir.cd() do
resolve()
end

checkout(pkg::String, branch::String="master"; force::Bool=false) = Dir.cd() do
ispath(pkg, ".git") || error("$pkg is not a git repo")
function checkout(pkg::String, what::String, force::Bool)
Git.transact(dir=pkg) do
info("Checking out $pkg $branch...")
if force
Git.run(`checkout -q -f $branch`, dir=pkg)
Git.run(`checkout -q -f $what`, dir=pkg)
else
Git.dirty(dir=pkg) && error("$pkg is dirty, bailing")
Git.run(`checkout -q $branch`, dir=pkg)
Git.run(`checkout -q $what`, dir=pkg)
end
resolve()
end
end

checkout(pkg::String, branch::String="master"; force::Bool=false) = Dir.cd() do
ispath(pkg,".git") || error("$pkg is not a git repo")
info("Checking out $pkg $branch...")
checkout(pkg,branch,force)
end

release(pkg::String; force::Bool=false) = Dir.cd() do
ispath(pkg, ".git") || error("$pkg is not a git repo")
ispath(pkg,".git") || error("$pkg is not a git repo")
avail = Dir.cd(Read.available)
haskey(avail,pkg) || error("$pkg is not registered")
ver = max(keys(avail[pkg]))
sha1 = avail[pkg][ver].sha1
Git.transact(dir=pkg) do
info("Releasing $pkg...")
if force
Git.run(`checkout -q -f $sha1`, dir=pkg)
else
Git.dirty(dir=pkg) && error("$pkg is dirty, bailing")
Git.run(`checkout -q $sha1`, dir=pkg)
end
resolve()
end
info("Releasing $pkg...")
checkout(pkg,sha1,force)
end

update() = Dir.cd() do
Expand Down Expand Up @@ -158,20 +154,20 @@ resolve(
reqs = Query.requirements(reqs,fixed)
deps = Query.dependencies(avail,fixed)

incompatible = {}
for pkg in keys(reqs)
haskey(deps, pkg) ||
error("$pkg has no version compatible with fixed requirements")
haskey(deps,pkg) || push!(incompatible,pkg)
end
isempty(incompatible) ||
error("The following packages are incompatible with fixed requirements: ",
join(incompatible, ", ", " and "))

deps = Query.prune_dependencies(reqs,deps)

want = Resolve.resolve(reqs,deps)

# compare what is installed with what should be
changes = Query.diff(have, want, avail, fixed)
if isempty(changes)
return info("No packages to install, update or remove.")
end
isempty(changes) && return info("No packages to install, update or remove.")

# prefetch phase isolates network activity, nothing to roll back
missing = {}
Expand All @@ -184,7 +180,7 @@ resolve(
Cache.prefetch(pkg, Read.url(pkg), vers)))
end
if !isempty(missing)
msg = "unfound package versions (possible metadata misconfiguration):"
msg = "missing package versions (possible metadata misconfiguration):"
for (pkg,ver,sha1) in missing
msg *= " $pkg v$ver [$sha1[1:10]]\n"
end
Expand Down
20 changes: 9 additions & 11 deletions base/pkg2/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,31 @@ end
typealias PackageState Union(Nothing,VersionNumber)

function diff(have::Dict, want::Dict, avail::Dict, fixed::Dict)
changeslist = Array((ByteString,(PackageState,PackageState)),0)
changes = Array((ByteString,(PackageState,PackageState)),0)
removed = Array((ByteString,(PackageState,PackageState)),0)

for pkg in collect(union(keys(have),keys(want)))
h, w = haskey(have,pkg), haskey(want,pkg)
if h && w
if have[pkg] != want[pkg]
push!(changeslist, (pkg,(have[pkg], want[pkg])))
push!(changes, (pkg,(have[pkg], want[pkg])))
end
elseif h
push!(removed, (pkg,(have[pkg],nothing)))
elseif w
push!(changeslist, (pkg,(nothing,want[pkg])))
push!(changes, (pkg,(nothing,want[pkg])))
end
end

# Sort packages topologically
sort!(changeslist, lt=function(a,b)
sort!(changes, lt=function(a,b)
((a,vera),(b,verb)) = (a,b)
c = contains(Pkg2.Read.alldependencies(a,avail,want,fixed),b)
nonordered = (!c && !contains(Pkg2.Read.alldependencies(b,avail,want,fixed),a))
nonordered ? a < b : c
unnordered = (!c && !contains(Pkg2.Read.alldependencies(b,avail,want,fixed),a))
unnordered ? a < b : c
end)

append!(changeslist, removed)

changeslist
append!(changes, removed)
end

# Reduce the number of versions by creating equivalence classes, and retaining
Expand All @@ -79,7 +77,6 @@ end
# 2) They have the same dependencies
# Also, if there are explicitly required packages, dicards all versions outside
# the allowed range (checking for impossible ranges while at it).
prune_versions(deps::Dict{ByteString,Dict{VersionNumber,Available}}) = prune_versions((ByteString=>VersionSet)[], deps)
function prune_versions(reqs::Requires, deps::Dict{ByteString,Dict{VersionNumber,Available}})

np = length(deps)
Expand Down Expand Up @@ -258,6 +255,8 @@ function prune_versions(reqs::Requires, deps::Dict{ByteString,Dict{VersionNumber

return new_deps, eq_classes
end
prune_versions(deps::Dict{ByteString,Dict{VersionNumber,Available}}) =
prune_versions((ByteString=>VersionSet)[], deps)

# Build a subgraph incuding only the (direct and indirect) dependencies
# of a given package set
Expand Down Expand Up @@ -333,5 +332,4 @@ function prune_dependencies(reqs::Requires, deps::Dict{ByteString,Dict{VersionNu
return deps
end


end # module
99 changes: 71 additions & 28 deletions base/profile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ end
####
#### User-level functions
####
function init(nsamples::Integer, delay::Float64)
status = ccall(:profile_init, Cint, (Csize_t, Uint64), nsamples, iround(10^9*delay))
function init(n::Integer, delay::Float64)
status = ccall(:profile_init, Cint, (Csize_t, Uint64), n, iround(10^9*delay))
if status == -1
error("Could not allocate space for ", nsamples, " profiling samples")
error("Could not allocate space for ", n, " instruction pointers")
end
end

clear() = ccall(:profile_clear_data, Void, ())

function print(io::IO = STDOUT, data = fetch(); format = :tree, C = false, combine = true, cols = tty_cols())
function print{T<:Unsigned}(io::IO = STDOUT, data::Vector{T} = fetch(); format = :tree, C = false, combine = true, cols = tty_cols())
if format == :tree
tree(io, data, C, combine, cols)
elseif format == :flat
Expand All @@ -39,7 +39,25 @@ function print(io::IO = STDOUT, data = fetch(); format = :tree, C = false, combi
error("Output format ", format, " not recognized")
end
end
print{T<:Unsigned}(data::Vector{T} = fetch(); kwargs...) = print(STDOUT, data; kwargs...)

function print{T<:Unsigned}(io::IO, data::Vector{T}, lidict::Dict; format = :tree, combine = true, cols = tty_cols())
if format == :tree
tree(io, data, lidict, combine, cols)
elseif format == :flat
flat(io, data, lidict, combine, cols)
else
error("Output format ", format, " not recognized")
end
end
print{T<:Unsigned}(data::Vector{T}, lidict::Dict; kwargs...) = print(STDOUT, data, lidict; kwargs...)

function retrieve(;C = false)
data = fetch()
uip = unique(data)
lidict = Dict(uip, [lookup(ip, C) for ip in uip])
return copy(data), lidict
end

####
#### Internal interface
Expand Down Expand Up @@ -97,8 +115,8 @@ const btskip = 2

## Print as a flat list
# Counts the number of times each line appears, at any nesting level
function parse_flat(data::Vector{Uint}, doCframes::Bool)
linecount = (Uint=>Int)[]
function count_flat{T<:Unsigned}(data::Vector{T})
linecount = (T=>Int)[]
toskip = btskip
for ip in data
if toskip > 0
Expand All @@ -111,17 +129,18 @@ function parse_flat(data::Vector{Uint}, doCframes::Bool)
end
linecount[ip] = get(linecount, ip, 0)+1
end
buf = Array(Uint, 0)
iplist = Array(T, 0)
n = Array(Int, 0)
for (k,v) in linecount
push!(buf, k)
push!(iplist, k)
push!(n, v)
end
return iplist, n
end

function parse_flat(iplist, n, lidict)
# Convert instruction pointers to names & line numbers
lilist = Array(LineInfo, length(buf))
for i = 1:length(buf)
lilist[i] = lookup(buf[i], doCframes)
end
lilist = [lidict[ip] for ip in iplist]
# Keep only the interpretable ones
# The ones with no line number might appear multiple times in a single
# backtrace, giving the wrong impression about the total number of backtraces.
Expand All @@ -132,12 +151,28 @@ function parse_flat(data::Vector{Uint}, doCframes::Bool)
lilist, n
end

function flat(io::IO, data::Vector{Uint}, doCframes::Bool, combine::Bool, cols::Integer)
lilist, n = parse_flat(data, doCframes)
function flat{T<:Unsigned}(io::IO, data::Vector{T}, doCframes::Bool, combine::Bool, cols::Integer)
iplist, n = count_flat(data)
if isempty(n)
warning_empty()
return
end
lidict = Dict(iplist, [lookup(ip, doCframes) for ip in iplist])
lilist, n = parse_flat(iplist, n, lidict)
print_flat(io, lilist, n, combine, cols)
end

function flat{T<:Unsigned}(io::IO, data::Vector{T}, lidict::Dict, combine::Bool, cols::Integer)
iplist, n = count_flat(data)
if isempty(n)
warning_empty()
return
end
lilist, n = parse_flat(iplist, n, lidict)
print_flat(io, lilist, n, combine, cols)
end

function print_flat(io::IO, lilist::Vector{LineInfo}, n::Vector{Int}, combine::Bool, cols::Integer)
p = liperm(lilist)
lilist = lilist[p]
n = n[p]
Expand Down Expand Up @@ -182,16 +217,16 @@ end

## A tree representation
# Identify and counts repetitions of all unique backtraces
function tree_aggregate(data::Array{Uint})
function tree_aggregate{T<:Unsigned}(data::Vector{T})
iz = find(data .== 0) # find the breaks between backtraces
treecount = (Vector{Uint}=>Int)[]
treecount = (Vector{T}=>Int)[]
istart = 1+btskip
for iend in iz
tmp = data[iend-1:-1:istart]
treecount[tmp] = get(treecount, tmp, 0)+1
istart = iend+1+btskip
end
bt = Array(Vector{Uint}, 0)
bt = Array(Vector{T}, 0)
counts = Array(Int, 0)
for (k,v) in treecount
push!(bt, k)
Expand Down Expand Up @@ -239,14 +274,14 @@ function tree_format(lilist::Vector{LineInfo}, counts::Vector{Int}, level::Int,
end

# Print a "branch" starting at a particular level. This gets called recursively.
function tree(io::IO, bt::Vector{Vector{Uint}}, counts::Vector{Int}, level::Int, doCframes::Bool, combine::Bool, cols::Integer)
function tree{T<:Unsigned}(io::IO, bt::Vector{Vector{T}}, counts::Vector{Int}, lidict::Dict, level::Int, combine::Bool, cols::Integer)
# Organize backtraces into groups that are identical up to this level
if combine
# Combine based on the line information
d = (LineInfo=>Vector{Int})[]
for i = 1:length(bt)
ip = bt[i][level+1]
key = lookup(ip, doCframes)
key = lidict[ip]
indx = Base.ht_keyindex(d, key)
if indx == -1
d[key] = [i]
Expand All @@ -268,7 +303,7 @@ function tree(io::IO, bt::Vector{Vector{Uint}}, counts::Vector{Int}, level::Int,
end
else
# Combine based on the instruction pointer
d = (Uint=>Vector{Int})[]
d = (T=>Vector{Int})[]
for i = 1:length(bt)
key = bt[i][level+1]
indx = Base.ht_keyindex(d, key)
Expand All @@ -285,17 +320,19 @@ function tree(io::IO, bt::Vector{Vector{Uint}}, counts::Vector{Int}, level::Int,
n = Array(Int, dlen)
i = 1
for (key, v) in d
lilist[i] = lookup(key, doCframes)
lilist[i] = lidict[key]
group[i] = v
n[i] = sum(counts[v])
i += 1
end
end
# Order the line information
p = liperm(lilist)
lilist = lilist[p]
group = group[p]
n = n[p]
if length(lilist) > 1
p = liperm(lilist)
lilist = lilist[p]
group = group[p]
n = n[p]
end
# Generate the string for each line
strs = tree_format(lilist, n, level, cols)
# Recurse to the next level
Expand All @@ -308,12 +345,18 @@ function tree(io::IO, bt::Vector{Vector{Uint}}, counts::Vector{Int}, level::Int,
keep = len[idx] .> level+1
if any(keep)
idx = idx[keep]
tree(io, bt[idx], counts[idx], level+1, doCframes, combine, cols)
tree(io, bt[idx], counts[idx], lidict, level+1, combine, cols)
end
end
end

function tree(io::IO, data::Vector{Uint}, doCframes::Bool, combine::Bool, cols::Integer)
function tree{T<:Unsigned}(io::IO, data::Vector{T}, doCframes::Bool, combine::Bool, cols::Integer)
uip = unique(data)
lidict = Dict(uip, [lookup(ip, doCframes) for ip in uip])
tree(io, data, lidict, combine, cols)
end

function tree{T<:Unsigned}(io::IO, data::Vector{T}, lidict::Dict, combine::Bool, cols::Integer)
bt, counts = tree_aggregate(data)
if isempty(counts)
warning_empty()
Expand All @@ -322,7 +365,7 @@ function tree(io::IO, data::Vector{Uint}, doCframes::Bool, combine::Bool, cols::
level = 0
len = Int[length(x) for x in bt]
keep = len .> 0
tree(io, bt[keep], counts[keep], level, doCframes, combine, cols)
tree(io, bt[keep], counts[keep], lidict, level, combine, cols)
end

# Utilities
Expand Down
Loading

0 comments on commit f811533

Please sign in to comment.