Skip to content

Commit

Permalink
feat: support cpu_180, cpu_300 & cpu_600
Browse files Browse the repository at this point in the history
PR-URL: #112
Reviewed-BY: hyj1991 <[email protected]>
  • Loading branch information
hyj1991 authored Dec 13, 2021
1 parent 430b13e commit 395a678
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
57 changes: 40 additions & 17 deletions src/logbypass/cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@
#include "../platform/platform.h"

namespace xprofiler {
#define EXTRA_SYMBOL

#define CONCAT_SYMBOL(V) V EXTRA_SYMBOL

#define PERIOD_LIST(V) \
CONCAT_SYMBOL(V(15)) \
CONCAT_SYMBOL(V(30)) \
CONCAT_SYMBOL(V(60)) \
CONCAT_SYMBOL(V(180)) \
CONCAT_SYMBOL(V(300)) \
V(600)

#define INIT_CPU_PERIOD(period) \
static double *cpu_##period = new double[period]; \
static int cpu_##period##_array_index = 0; \
static int cpu_##period##_array_length = period; \
static int cpu_##period##_array_not_full = true;

#define INIT_CPU_AVERAGE(period) double cpu_##period##_average = 0.0;

#define ALINODE_LOG_KEY(period) "cpu_" #period ": %.2lf"

#define XPROFILER_LOG_KEY(period) "cpu_" #period ": %lf"

#define CPU_AVERAGE_VAL(period) cpu_##period##_average

#define SET_CPU_USAGE(period) \
if (cpu_##period##_array_index < cpu_##period##_array_length) { \
cpu_##period[cpu_##period##_array_index++] = cpu_now; \
Expand All @@ -34,10 +54,8 @@ namespace xprofiler {
// init cpu now
double cpu_now = 0.0;

// init cpu 15/30/60
INIT_CPU_PERIOD(15)
INIT_CPU_PERIOD(30)
INIT_CPU_PERIOD(60)
// init cpu period
PERIOD_LIST(INIT_CPU_PERIOD)

void SetNowCpuUsage() {
double cpu_now_ = GetNowCpuUsage();
Expand All @@ -46,26 +64,31 @@ void SetNowCpuUsage() {
}
cpu_now = cpu_now_;

SET_CPU_USAGE(15)
SET_CPU_USAGE(30)
SET_CPU_USAGE(60)
PERIOD_LIST(SET_CPU_USAGE)
}

void WriteCpuUsageInPeriod(bool log_format_alinode) {
double cpu_15_average = 0.0, cpu_30_average = 0.0, cpu_60_average = 0.0;
PERIOD_LIST(INIT_CPU_AVERAGE)

CALAULATE_CPU_USAGE_IN_PERIOD(15)
CALAULATE_CPU_USAGE_IN_PERIOD(30)
CALAULATE_CPU_USAGE_IN_PERIOD(60)
PERIOD_LIST(CALAULATE_CPU_USAGE_IN_PERIOD)

if (log_format_alinode)
Info(
"other",
"cpu_usage(%%) now: %.2lf, cpu_15: %.2lf, cpu_30: %.2lf, cpu_60: %.2lf",
cpu_now, cpu_15_average, cpu_30_average, cpu_60_average);
Info("other",
#undef EXTRA_SYMBOL
#define EXTRA_SYMBOL ", "
"cpu_usage(%%) now: %.2lf, " PERIOD_LIST(ALINODE_LOG_KEY),
#undef EXTRA_SYMBOL
#define EXTRA_SYMBOL ,
cpu_now, PERIOD_LIST(CPU_AVERAGE_VAL));
else
Info("cpu",
"cpu_usage(%%) cpu_now: %lf, cpu_15: %lf, cpu_30: %lf, cpu_60: %lf",
cpu_now, cpu_15_average, cpu_30_average, cpu_60_average);
#undef EXTRA_SYMBOL
#define EXTRA_SYMBOL ", "
"cpu_usage(%%) cpu_now: %lf, " PERIOD_LIST(XPROFILER_LOG_KEY),
#undef EXTRA_SYMBOL
#define EXTRA_SYMBOL ,
cpu_now, PERIOD_LIST(CPU_AVERAGE_VAL));
#undef EXTRA_SYMBOL
#define EXTRA_SYMBOL
}
} // namespace xprofiler
4 changes: 2 additions & 2 deletions test/fixtures/logbypass.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function getUvRules(list, alinode) {

// alinode log structure
const alinodeLogStructure = {
other: getCpuRules(['now', 'cpu_15', 'cpu_30', 'cpu_60'], true),
other: getCpuRules(['now', 'cpu_15', 'cpu_30', 'cpu_60', 'cpu_180', 'cpu_300', 'cpu_600'], true),
heap: getMemoryRules(memoryKeys, true),
gc: getGcRules(['gc_time_during_last_min', 'total', 'scavange_duration', 'marksweep_duration'], true),
timer: getUvRules(['total_timer', 'active_handles'], true),
Expand All @@ -74,7 +74,7 @@ const alinodeLogStructure = {

// xprofiler log structure
const xprofilerLogStructure = {
cpu: getCpuRules(['cpu_now', 'cpu_15', 'cpu_30', 'cpu_60']),
cpu: getCpuRules(['cpu_now', 'cpu_15', 'cpu_30', 'cpu_60', 'cpu_180', 'cpu_300', 'cpu_600']),
memory: getMemoryRules(memoryKeys),
gc: getGcRules(['uptime', 'total_gc_times', 'total_gc_duration', 'total_scavange_duration',
'total_marksweep_duration', 'total_incremental_marking_duration', 'gc_time_during_last_record',
Expand Down

0 comments on commit 395a678

Please sign in to comment.