Optimize the output of log and stat
This commit is contained in:
@@ -63,6 +63,17 @@ static int all_session_have_freed(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int all_stat_have_output(void)
|
||||
{
|
||||
static int count = 0;
|
||||
if (runtime->stat_last_output_ts == stellar_get_monotonic_time_msec())
|
||||
{
|
||||
count++;
|
||||
}
|
||||
|
||||
return count == 2;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
stellar_update_time_cache();
|
||||
@@ -138,8 +149,9 @@ int main(int argc, char **argv)
|
||||
usleep(1000); // 1ms
|
||||
|
||||
// Only available in dump file mode, automatically exits when all sessions have been released
|
||||
if (packet_io_wait_exit(runtime->packet_io) && all_session_have_freed())
|
||||
if (packet_io_wait_exit(runtime->packet_io) && all_session_have_freed() && all_stat_have_output())
|
||||
{
|
||||
STELLAR_LOG_STATE("all sessions have been released and all stat have been output, notify threads to exit !!!");
|
||||
ATOMIC_SET(&runtime->need_exit, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +113,8 @@ struct stat_id
|
||||
|
||||
struct stellar_stat
|
||||
{
|
||||
char output_file[2048];
|
||||
|
||||
// thread stat
|
||||
uint16_t nr_thread;
|
||||
int flag[MAX_THREAD_NUM]; // IS_FREE or IS_BUSY
|
||||
@@ -134,12 +136,20 @@ struct stellar_stat
|
||||
// /opt/MESA/bin/fieldstat_exporter.py local -j log/stellar_fs4.json -e -l --clear-screen
|
||||
struct stellar_stat *stellar_stat_new(uint16_t nr_thread)
|
||||
{
|
||||
char cwd[1024] = {0};
|
||||
struct stellar_stat *stat = (struct stellar_stat *)calloc(1, sizeof(struct stellar_stat));
|
||||
if (stat == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (getcwd(cwd, sizeof(cwd)) == NULL)
|
||||
{
|
||||
STAT_LOG_ERROR("failed to get current working directory: %s", strerror(errno));
|
||||
goto error_out;
|
||||
}
|
||||
snprintf(stat->output_file, sizeof(stat->output_file), "%s/log/stellar_fs4.json", cwd);
|
||||
|
||||
stat->fs = fieldstat_easy_new(1, "stellar", NULL, 0);
|
||||
if (stat->fs == NULL)
|
||||
{
|
||||
@@ -448,10 +458,10 @@ void stellar_stat_output(struct stellar_stat *stat)
|
||||
fieldstat_easy_output(stat->fs, &buff, &len);
|
||||
if (buff)
|
||||
{
|
||||
FILE *fp = fopen("/opt/tsg/stellar/log/stellar_fs4.json", "w+");
|
||||
FILE *fp = fopen(stat->output_file, "w+");
|
||||
if (fp == NULL)
|
||||
{
|
||||
STAT_LOG_ERROR("failed to open file: %s, %s", "/opt/tsg/stellar/log/stellar_fs4.json", strerror(errno));
|
||||
STAT_LOG_ERROR("failed to open file: %s, %s", stat->output_file, strerror(errno));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user