diff --git a/lct/api/lct.h b/lct/api/lct.h index d62712b0..96a72a5b 100644 --- a/lct/api/lct.h +++ b/lct/api/lct.h @@ -7,6 +7,7 @@ extern "C" { #include #include +#include #include "lct_config.h" @@ -24,8 +25,7 @@ LCT_API void LCT_set_rank(int rank); LCT_API int LCT_get_rank(); // hostname -#define LCT_HOSTNAME_MAX_LENGTH 128 -extern char LCT_hostname[LCT_HOSTNAME_MAX_LENGTH]; +extern char LCT_hostname[HOST_NAME_MAX + 1]; // time typedef uint64_t LCT_time_t; diff --git a/lct/lct.cpp b/lct/lct.cpp index e19a091b..5281286f 100644 --- a/lct/lct.cpp +++ b/lct/lct.cpp @@ -4,7 +4,7 @@ LCT_API LCT_log_ctx_t LCT_log_ctx_default = nullptr; LCT_API int LCT_rank = -1; -LCT_API char LCT_hostname[LCT_HOSTNAME_MAX_LENGTH] = "uninitialized"; +LCT_API char LCT_hostname[HOST_NAME_MAX + 1] = "uninitialized"; namespace lct { @@ -17,7 +17,8 @@ void init() return; // initialize hostname - gethostname(LCT_hostname, LCT_HOSTNAME_MAX_LENGTH); + memset(LCT_hostname, 0, HOST_NAME_MAX + 1); + gethostname(LCT_hostname, HOST_NAME_MAX); // initialize LCT_log_ctx_default const char* const log_levels[] = { diff --git a/lct/pcounter/pcounter.cpp b/lct/pcounter/pcounter.cpp index 9e4730bd..ab7b186f 100644 --- a/lct/pcounter/pcounter.cpp +++ b/lct/pcounter/pcounter.cpp @@ -198,6 +198,7 @@ struct ctx_t { explicit ctx_t(const char* name_) : dump_ofile(nullptr), dump_record_on_the_fly(false), + dump_record_on_the_fly_lw(false), name(name_), id(next_id++), record_thread(nullptr), @@ -218,6 +219,11 @@ struct ctx_t { dump_ofilename = "lct_pcounter.%.out"; dump_record_on_the_fly = true; record_interval = 1000000; + } else if (mode_str == "on-the-fly-lw") { + dump_ofilename = "lct_pcounter.%.out"; + dump_record_on_the_fly = true; + dump_record_on_the_fly_lw = true; + record_interval = 1000000; } } // Output file to dump @@ -257,6 +263,10 @@ struct ctx_t { if (getenv("LCT_PCOUNTER_DUMP_ON_THE_FLY")) { dump_record_on_the_fly = true; } + if (getenv("LCT_PCOUNTER_DUMP_ON_THE_FLY_LW")) { + dump_record_on_the_fly = true; + dump_record_on_the_fly_lw = true; + } // For now, we just assume there will only be a single thread initializing. if (start_time == -1) { start_time = LCT_now(); @@ -329,7 +339,7 @@ struct ctx_t { bool expected = true; if (do_record.compare_exchange_weak(expected, false)) { record(); - if (dump_record_on_the_fly) dump(dump_ofile); + if (dump_record_on_the_fly_lw) dump(dump_ofile); } } } @@ -430,6 +440,7 @@ struct ctx_t { FILE* dump_ofile; bool dump_record_on_the_fly; + bool dump_record_on_the_fly_lw; std::vector counter_names; std::vector trend_names; std::vector timer_names; @@ -452,7 +463,12 @@ struct ctx_t { void record_thread_fn(ctx_t* ctx, uint64_t record_interval) { while (ctx->keep_recording) { - ctx->do_record = true; + if (ctx->dump_record_on_the_fly_lw) + ctx->do_record = true; + else if (ctx->dump_record_on_the_fly) { + ctx->record(); + ctx->dump(ctx->dump_ofile); + } usleep(record_interval); } }