Skip to content

Commit

Permalink
improve LCT hostname setup
Browse files Browse the repository at this point in the history
  • Loading branch information
JiakunYan committed Dec 21, 2023
1 parent aeb5bc6 commit 96241d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lct/api/lct.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ extern "C" {

#include <stdint.h>
#include <stdio.h>
#include <climits>

#include "lct_config.h"

Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions lct/lct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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[] = {
Expand Down
20 changes: 18 additions & 2 deletions lct/pcounter/pcounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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<std::string> counter_names;
std::vector<std::string> trend_names;
std::vector<std::string> timer_names;
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 96241d1

Please sign in to comment.