1+ load ("@bazel_skylib//rules:common_settings.bzl" , "string_flag" )
2+ load (
3+     "@gz//bazel/lint:lint.bzl" ,
4+     "add_lint_tests" ,
5+ )
16load (
27    "@gz//bazel/skylark:build_defs.bzl" ,
38    "GZ_FEATURES" ,
712    "gz_export_header" ,
813    "gz_include_header" ,
914)
10- load (
11-     "@gz//bazel/lint:lint.bzl" ,
12-     "add_lint_tests" ,
13- )
1415
1516package (
1617    default_applicable_licenses  =  [GZ_ROOT  +  "common:license" ],
@@ -46,22 +47,18 @@ cmake_configure_file(
4647    visibility  =  ["//visibility:private" ],
4748)
4849
49- public_headers_no_gen  =  [
50-     "include/gz/common/Profiler.hh" ,
51- ]
52- 
53- sources  =  [
54-     "src/Profiler.cc" ,
55-     "src/RemoteryProfilerImpl.cc" ,
56- ]
57- 
5850gz_export_header (
5951    name  =  "include/gz/common/profiler/Export.hh" ,
6052    export_base  =  "GZ_COMMON_PROFILER" ,
6153    lib_name  =  "gz-common-profiler" ,
6254    visibility  =  ["//visibility:private" ],
6355)
6456
57+ public_headers_no_gen  =  [
58+     "include/gz/common/Profiler.hh" ,
59+     "include/gz/common/ProfilerImpl.hh" ,
60+ ]
61+ 
6562gz_include_header (
6663    name  =  "profiler_hh_genrule" ,
6764    out  =  "include/gz/common/profiler.hh" ,
@@ -70,17 +67,6 @@ gz_include_header(
7067    ],
7168)
7269
73- public_headers  =  public_headers_no_gen  +  [
74-     "include/gz/common/profiler/Export.hh" ,
75-     "include/gz/common/profiler.hh" ,
76- ]
77- 
78- private_headers  =  [
79-     "src/ProfilerImpl.hh" ,
80-     "src/RemoteryProfilerImpl.hh" ,
81-     "include/RemoteryConfig.h" ,
82- ]
83- 
8470cc_library (
8571    name  =  "remotery" ,
8672    srcs  =  ["src/Remotery/lib/Remotery.c" ],
@@ -89,44 +75,106 @@ cc_library(
8975)
9076
9177cc_library (
92-     name  =  "profiler" ,
93-     srcs  =  sources ,
94-     hdrs  =  public_headers  +  private_headers ,
95-     defines  =  [
96-         "GZ_PROFILER_ENABLE=1" ,
97-         "GZ_PROFILER_REMOTERY=1" ,
78+     name  =  "ProfilerImplInterface" ,
79+     hdrs  =  [
80+         "include/gz/common/ProfilerImpl.hh" ,
81+         "include/gz/common/profiler/Export.hh" ,
82+     ],
83+     includes  =  ["include" ],
84+     visibility  =  GZ_VISIBILITY ,
85+ )
86+ 
87+ cc_library (
88+     name  =  "RemoteryProfilerImpl" ,
89+     srcs  =  ["src/RemoteryProfilerImpl.cc" ],
90+     hdrs  =  [
91+         "include/RemoteryConfig.h" ,
92+         "src/RemoteryProfilerImpl.hh" ,
9893    ],
9994    includes  =  ["include" ],
10095    visibility  =  GZ_VISIBILITY ,
10196    deps  =  [
10297        GZ_ROOT  +  "common" ,
98+         ":ProfilerImplInterface" ,
10399        ":remotery" ,
104100    ],
105101)
106102
107- cc_test (
108-     name  =  "Profiler_Disabled_TEST" ,
109-     srcs  =  ["src/Profiler_Disabled_TEST.cc" ],
110-     copts  =  ["-Wno-macro-redefined" ],
111-     defines  =  [
112-         "GZ_PROFILER_ENABLE=0" ,
113-         "GZ_PROFILER_REMOTERY=0" ,
114-     ],
115-     deps  =  [
116-         ":profiler" ,
117-         "@gtest" ,
118-         "@gtest//:gtest_main" ,
103+ # Build flag to control how the Gz Profiler is configured. 
104+ # --//profiler:config="disabled" (default): Profiler will be disabled. 
105+ # --//profiler:config="remotery": Profiler will be enabled and the Remotery 
106+ #   profiler implemenation will be used. 
107+ # --//profiler:config="custom": Profiler will be enabled and a custom profiler 
108+ #   implementation can be set to be used. See Profiler class for details. 
109+ # 
110+ # Note to maintainers: This setup is different from what is used in CMake where 
111+ # the config is split into two parts to control whether Remotery is used or not 
112+ # separately from whether the profiler is enabled or disabled. 
113+ string_flag (
114+     name  =  "config" ,
115+     build_setting_default  =  "disabled" ,
116+     values  =  [
117+         "disabled" ,
118+         "remotery" ,
119+         "custom" ,
119120    ],
120121)
121122
122- cc_test (
123-     name  =  "Profiler_Remotery_TEST" ,
124-     srcs  =  ["src/Profiler_Remotery_TEST.cc" ],
123+ config_setting (
124+     name  =  "disabled" ,
125+     flag_values  =  {
126+         ":config" : "disabled" ,
127+     },
128+ )
129+ 
130+ config_setting (
131+     name  =  "use_remotery" ,
132+     flag_values  =  {
133+         ":config" : "remotery" ,
134+     },
135+ )
136+ 
137+ config_setting (
138+     name  =  "use_custom" ,
139+     flag_values  =  {
140+         ":config" : "custom" ,
141+     },
142+ )
143+ 
144+ public_headers  =  public_headers_no_gen  +  [
145+     "include/gz/common/profiler.hh" ,
146+     "include/gz/common/profiler/Export.hh" ,
147+ ]
148+ 
149+ sources  =  ["src/Profiler.cc" ]
150+ 
151+ cc_library (
152+     name  =  "profiler" ,
153+     srcs  =  sources ,
154+     hdrs  =  public_headers ,
155+     defines  =  select ({
156+         "disabled" : [
157+             "GZ_PROFILER_ENABLE=0" ,
158+             "GZ_PROFILER_REMOTERY=0" ,
159+         ],
160+         "use_remotery" : [
161+             "GZ_PROFILER_ENABLE=1" ,
162+             "GZ_PROFILER_REMOTERY=1" ,
163+         ],
164+         "use_custom" : [
165+             "GZ_PROFILER_ENABLE=1" ,
166+             "GZ_PROFILER_REMOTERY=0" ,
167+         ],
168+     }),
169+     includes  =  ["include" ],
170+     visibility  =  GZ_VISIBILITY ,
125171    deps  =  [
126-         ":profiler" ,
127-         "@gtest" ,
128-         "@gtest//:gtest_main" ,
129-     ],
172+         GZ_ROOT  +  "common" ,
173+         ":ProfilerImplInterface" ,
174+     ] +  select ({
175+         "use_remotery" : [":RemoteryProfilerImpl" ],
176+         "//conditions:default" : [],
177+     }),
130178)
131179
132180add_lint_tests ()
0 commit comments