Skip to content

Commit cf48faf

Browse files
committed
Add preference system to change library
1 parent e491f6b commit cf48faf

File tree

3 files changed

+236
-136
lines changed

3 files changed

+236
-136
lines changed

Project.toml

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ version = "0.2.0"
55

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

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

12-
[extension]
13-
ExtraeDistributedExt = "Distributed"
14-
1514
[compat]
1615
Extrae_jll = "4.2.0"
16+
Libdl = "1"
17+
Preferences = "1"
1718
julia = "1.9"
19+
20+
[extension]
21+
ExtraeDistributedExt = "Distributed"

src/Extrae.jl

+68-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
module Extrae
22

33
using Extrae_jll
4-
5-
include("FFI.jl")
6-
include("API.jl")
7-
include("Macros.jl")
4+
using Libdl
5+
using Preferences
86

97
export version,
108
init,
@@ -29,4 +27,70 @@ function __init__()
2927
return nothing
3028
end
3129

30+
const libextrae = @load_preference("libextrae", Extrae_jll.libseqtrace)
31+
32+
function use_system_binary(;
33+
library_names=[
34+
"libseqtrace",
35+
"libpttrace",
36+
"libmpitrace",
37+
"libptmpitrace",
38+
"libcudatrace",
39+
"libptcudatrace",
40+
"libcudampitrace",
41+
"libptcudampitrace",
42+
],
43+
extra_paths=String[],
44+
export_prefs=false,
45+
force=true,
46+
)
47+
libextrae = find_library(library_names, extra_paths)
48+
if libextrae == ""
49+
error("""
50+
Extrae library could not be found with the following name(s):
51+
$(library_names)
52+
in the following extra directories (in addition to the default ones):
53+
$(extra_paths)
54+
If you want to try different name(s) for the Extrae library, use
55+
Extrae.use_system_binary(; library_names=[...])""")
56+
end
57+
58+
set_preferences!(Extrae, "libextrae" => libextrae; export_prefs, force)
59+
60+
if libextrae != Extrae.libextrae
61+
@info "Extrae preferences changed" libextrae
62+
error("You will need to restart Julia for the changes to take effect")
63+
end
64+
end
65+
66+
function use_jll_binary(binary; export_prefs=false, force=true)
67+
known_binaries = (
68+
:libseqtrace,
69+
:libpttrace,
70+
:libmpitrace,
71+
:libptmpitrace,
72+
:libcudatrace,
73+
:libptcudatrace,
74+
:libcudampitrace,
75+
:libptcudampitrace,
76+
)
77+
binary in known_binaries || error("""
78+
Unknown jll: $binary
79+
Accepted options are:
80+
$(join(string.(known_binaries), ", "))""")
81+
82+
libextrae = getproperty(Extrae_jll, binary)
83+
84+
set_preferences!(Extrae, "libextrae" => libextrae; export_prefs, force)
85+
86+
if libextrae != Extrae.libextrae
87+
@info "Extrae preferences changed" libextrae
88+
error("You will need to restart Julia for the changes to take effect")
89+
end
90+
end
91+
92+
include("FFI.jl")
93+
include("API.jl")
94+
include("Macros.jl")
95+
3296
end

0 commit comments

Comments
 (0)