Skip to content

Commit a5b3dd7

Browse files
committed
Refactor logging functions and reduce includes
1 parent db1212e commit a5b3dd7

File tree

2 files changed

+33
-39
lines changed

2 files changed

+33
-39
lines changed

profiling/energy-profiler/kp_energy_profiler.cpp

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616

1717
#include <algorithm>
1818
#include <chrono>
19-
#include <cstdarg>
20-
#include <cstdint>
21-
#include <cstdio>
22-
#include <exception>
23-
#include <cstdlib>
2419
#include <iostream>
2520
#include <memory>
2621
#include <mutex>
@@ -48,12 +43,9 @@ uint64_t generate_new_region_id() {
4843
}
4944

5045
// Helper function for verbose logging
51-
void log_verbose(const char* format, ...) {
46+
void log_verbose(const std::string& message) {
5247
if (EnergyProfilerState::get_instance().get_verbose_enabled()) {
53-
va_list args;
54-
va_start(args, format);
55-
vprintf(format, args);
56-
va_end(args);
48+
std::cout << message << std::endl;
5749
}
5850
}
5951

@@ -174,28 +166,26 @@ void kokkosp_init_library(const int loadSeq, const uint64_t interfaceVer,
174166
KokkosTools::EnergyProfiler::EnergyProfilerState::get_instance()
175167
.set_verbose_enabled(true);
176168
}
177-
printf(
178-
"Kokkos Energy Profiler: Initializing with load sequence %d and "
179-
"interface version %lu\n",
180-
loadSeq, interfaceVer);
181-
printf("Kokkos Energy Profiler: Library initialized\n");
169+
std::cout << "Kokkos Energy Profiler: Initializing with load sequence "
170+
<< loadSeq << " and interface version " << interfaceVer
171+
<< std::endl;
172+
std::cout << "Kokkos Energy Profiler: Library initialized" << std::endl;
182173

183174
// Initialize power sampling (completely independent of timing)
184175
KokkosTools::EnergyProfiler::g_power_sampler.reset(
185176
new KokkosTools::EnergyProfiler::PowerSampler());
186177
if (KokkosTools::EnergyProfiler::g_power_sampler->initialize()) {
187178
KokkosTools::EnergyProfiler::g_power_sampler->start_sampling();
188-
printf("Kokkos Energy Profiler: Power sampling started\n");
179+
std::cout << "Kokkos Energy Profiler: Power sampling started" << std::endl;
189180
} else {
190-
printf("Kokkos Energy Profiler: Power sampling initialization failed\n");
181+
std::cout << "Kokkos Energy Profiler: Power sampling initialization failed" << std::endl;
191182
}
192183
}
193184

194185
// Library finalize
195186
void kokkosp_finalize_library() {
196-
printf("Kokkos Energy Profiler: Finalizing library\n");
187+
std::cout << "Kokkos Energy Profiler: Finalizing library" << std::endl;
197188

198-
// Export timing data
199189
std::string prefix = KokkosTools::EnergyProfiler::generate_prefix();
200190
auto all_timings = KokkosTools::EnergyProfiler::get_all_timings();
201191
KokkosTools::EnergyProfiler::print_all_timings_summary(
@@ -220,7 +210,7 @@ void kokkosp_finalize_library() {
220210
KokkosTools::EnergyProfiler::g_power_sampler.reset();
221211
}
222212

223-
printf("Kokkos Energy Profiler: Library finalized\n");
213+
std::cout << "Kokkos Energy Profiler: Library finalized" << std::endl;
224214
}
225215

226216
// Begin parallel_for
@@ -238,9 +228,9 @@ void kokkosp_begin_parallel_for(const char* name, const uint32_t devID,
238228
KokkosTools::EnergyProfiler::start_region(
239229
name, KokkosTools::EnergyProfiler::RegionType::ParallelFor, *kID);
240230
KokkosTools::EnergyProfiler::log_verbose(
241-
"Kokkos Energy Profiler: Started parallel_for '%s' on device %u with ID "
242-
"%lu\n",
243-
name, devID, *kID);
231+
std::string("Kokkos Energy Profiler: Started parallel_for '") + name +
232+
"' on device " + std::to_string(devID) + " with ID " +
233+
std::to_string(*kID));
244234
}
245235

246236
// End parallel_for
@@ -251,7 +241,8 @@ void kokkosp_end_parallel_for(const uint64_t kID) {
251241
}
252242
KokkosTools::EnergyProfiler::end_region_with_id(kID);
253243
KokkosTools::EnergyProfiler::log_verbose(
254-
"Kokkos Energy Profiler: Ended parallel_for with ID %lu\n", kID);
244+
std::string("Kokkos Energy Profiler: Ended parallel_for with ID ") +
245+
std::to_string(kID));
255246
}
256247

257248
// Begin parallel_scan
@@ -267,9 +258,9 @@ void kokkosp_begin_parallel_scan(const char* name, const uint32_t devID,
267258
KokkosTools::EnergyProfiler::start_region(
268259
name, KokkosTools::EnergyProfiler::RegionType::ParallelScan, *kID);
269260
KokkosTools::EnergyProfiler::log_verbose(
270-
"Kokkos Energy Profiler: Started parallel_scan '%s' on device %u with ID "
271-
"%lu\n",
272-
name, devID, *kID);
261+
std::string("Kokkos Energy Profiler: Started parallel_scan '") + name +
262+
"' on device " + std::to_string(devID) + " with ID " +
263+
std::to_string(*kID));
273264
}
274265

275266
// End parallel_scan
@@ -280,7 +271,8 @@ void kokkosp_end_parallel_scan(const uint64_t kID) {
280271
}
281272
KokkosTools::EnergyProfiler::end_region_with_id(kID);
282273
KokkosTools::EnergyProfiler::log_verbose(
283-
"Kokkos Energy Profiler: Ended parallel_scan with ID %lu\n", kID);
274+
std::string("Kokkos Energy Profiler: Ended parallel_scan with ID ") +
275+
std::to_string(kID));
284276
}
285277

286278
// Begin parallel_reduce
@@ -296,9 +288,9 @@ void kokkosp_begin_parallel_reduce(const char* name, const uint32_t devID,
296288
KokkosTools::EnergyProfiler::start_region(
297289
name, KokkosTools::EnergyProfiler::RegionType::ParallelReduce, *kID);
298290
KokkosTools::EnergyProfiler::log_verbose(
299-
"Kokkos Energy Profiler: Started parallel_reduce '%s' on device %u with "
300-
"ID %lu\n",
301-
name, devID, *kID);
291+
std::string("Kokkos Energy Profiler: Started parallel_reduce '") + name +
292+
"' on device " + std::to_string(devID) + " with ID " +
293+
std::to_string(*kID));
302294
}
303295

304296
// End parallel_reduce
@@ -309,7 +301,8 @@ void kokkosp_end_parallel_reduce(const uint64_t kID) {
309301
}
310302
KokkosTools::EnergyProfiler::end_region_with_id(kID);
311303
KokkosTools::EnergyProfiler::log_verbose(
312-
"Kokkos Energy Profiler: Ended parallel_reduce with ID %lu\n", kID);
304+
std::string("Kokkos Energy Profiler: Ended parallel_reduce with ID ") +
305+
std::to_string(kID));
313306
}
314307

315308
// Push user region
@@ -322,15 +315,16 @@ void kokkosp_push_profile_region(char const* regionName) {
322315
KokkosTools::EnergyProfiler::start_region(
323316
regionName, KokkosTools::EnergyProfiler::RegionType::UserRegion, new_id);
324317
KokkosTools::EnergyProfiler::log_verbose(
325-
"Kokkos Energy Profiler: Pushed profile region '%s'\n", regionName);
318+
std::string("Kokkos Energy Profiler: Pushed profile region '") +
319+
regionName + "'");
326320
}
327321

328322
// Pop user region
329323
void kokkosp_pop_profile_region() {
330324
KokkosTools::EnergyProfiler::end_region_by_type(
331325
KokkosTools::EnergyProfiler::RegionType::UserRegion);
332326
KokkosTools::EnergyProfiler::log_verbose(
333-
"Kokkos Energy Profiler: Popped profile region\n");
327+
"Kokkos Energy Profiler: Popped profile region");
334328
}
335329

336330
// Begin deep copy
@@ -346,17 +340,17 @@ void kokkosp_begin_deep_copy(Kokkos::Tools::SpaceHandle, const char* dst_name,
346340
KokkosTools::EnergyProfiler::start_region(
347341
name, KokkosTools::EnergyProfiler::RegionType::DeepCopy, new_id);
348342
KokkosTools::EnergyProfiler::log_verbose(
349-
"Kokkos Energy Profiler: Started deep copy from '%s' to '%s' (size: %lu "
350-
"bytes)\n",
351-
src_name, dst_name, size);
343+
std::string("Kokkos Energy Profiler: Started deep copy from '") +
344+
src_name + "' to '" + dst_name + "' (size: " + std::to_string(size) +
345+
" bytes)");
352346
}
353347

354348
// End deep copy
355349
void kokkosp_end_deep_copy() {
356350
KokkosTools::EnergyProfiler::end_region_by_type(
357351
KokkosTools::EnergyProfiler::RegionType::DeepCopy);
358352
KokkosTools::EnergyProfiler::log_verbose(
359-
"Kokkos Energy Profiler: Ended deep copy\n");
353+
"Kokkos Energy Profiler: Ended deep copy");
360354
}
361355

362356
} // extern "C"

profiling/energy-profiler/timing_utils.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void end_region_with_id(uint64_t expected_id);
9090
uint64_t generate_new_region_id();
9191
bool is_verbose_enabled();
9292
void set_verbose_enabled(bool enabled);
93-
void log_verbose(const char* format, ...);
93+
void log_verbose(const std::string& message);
9494
std::vector<TimingInfo> get_all_timings();
9595

9696
// Filename prefix generation

0 commit comments

Comments
 (0)