Skip to content

Commit

Permalink
Add preference system to change library
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Jul 2, 2024
1 parent e491f6b commit cf48faf
Show file tree
Hide file tree
Showing 3 changed files with 236 additions and 136 deletions.
10 changes: 7 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ version = "0.2.0"

[deps]
Extrae_jll = "2b2c4be0-e38c-5918-b8b4-9a308845a1e9"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"

[weakdeps]
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"

[extension]
ExtraeDistributedExt = "Distributed"

[compat]
Extrae_jll = "4.2.0"
Libdl = "1"
Preferences = "1"
julia = "1.9"

[extension]
ExtraeDistributedExt = "Distributed"
72 changes: 68 additions & 4 deletions src/Extrae.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
module Extrae

using Extrae_jll

include("FFI.jl")
include("API.jl")
include("Macros.jl")
using Libdl
using Preferences

export version,
init,
Expand All @@ -29,4 +27,70 @@ function __init__()
return nothing
end

const libextrae = @load_preference("libextrae", Extrae_jll.libseqtrace)

function use_system_binary(;
library_names=[
"libseqtrace",
"libpttrace",
"libmpitrace",
"libptmpitrace",
"libcudatrace",
"libptcudatrace",
"libcudampitrace",
"libptcudampitrace",
],
extra_paths=String[],
export_prefs=false,
force=true,
)
libextrae = find_library(library_names, extra_paths)
if libextrae == ""
error("""
Extrae library could not be found with the following name(s):
$(library_names)
in the following extra directories (in addition to the default ones):
$(extra_paths)
If you want to try different name(s) for the Extrae library, use
Extrae.use_system_binary(; library_names=[...])""")
end

set_preferences!(Extrae, "libextrae" => libextrae; export_prefs, force)

if libextrae != Extrae.libextrae
@info "Extrae preferences changed" libextrae
error("You will need to restart Julia for the changes to take effect")
end
end

function use_jll_binary(binary; export_prefs=false, force=true)
known_binaries = (
:libseqtrace,
:libpttrace,
:libmpitrace,
:libptmpitrace,
:libcudatrace,
:libptcudatrace,
:libcudampitrace,
:libptcudampitrace,
)
binary in known_binaries || error("""
Unknown jll: $binary
Accepted options are:
$(join(string.(known_binaries), ", "))""")

libextrae = getproperty(Extrae_jll, binary)

set_preferences!(Extrae, "libextrae" => libextrae; export_prefs, force)

if libextrae != Extrae.libextrae
@info "Extrae preferences changed" libextrae
error("You will need to restart Julia for the changes to take effect")
end
end

include("FFI.jl")
include("API.jl")
include("Macros.jl")

end
Loading

0 comments on commit cf48faf

Please sign in to comment.