Skip to content

Commit 87fe054

Browse files
committed
In RunStats merge, if one input has accumulate enabled and the other does not, the accumulated value of the one without will be reconstructed from the mean and count
GlobalAnomalyStats function profile now accumulates total runtime for each function over all ranks/threads. Modified unit tests to adapt to this change.
1 parent 21b5f77 commit 87fe054

5 files changed

Lines changed: 58 additions & 12 deletions

File tree

src/pserver/AggregateFuncStats.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ using namespace chimbuko;
44

55
AggregateFuncStats::AggregateFuncStats(int pid, int fid, const std::string &func): m_pid(pid), m_fid(fid), m_func(func){
66
m_func_anomaly.set_do_accumulate(true); //accumulate number of anomalies as 'accumulate' field
7+
m_inclusive.set_do_accumulate(true); //also accumulate total runtimes over all rank, thread
8+
m_exclusive.set_do_accumulate(true);
79
}
810

911
void AggregateFuncStats::add(unsigned long n_anomaly, const RunStats& inclusive, const RunStats& exclusive){

src/util/RunStats.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,11 @@ RunStats chimbuko::operator+(const RunStats &a, const RunStats &b)
199199
bool do_accumulate = false;
200200
if (a.m_do_accumulate || b.m_do_accumulate)
201201
{
202-
sum_acc = a.m_state.acc + b.m_state.acc;
203-
do_accumulate = true;
202+
double a_acc = a.m_do_accumulate ? a.m_state.acc : a.m_state.eta * a.m_state.count; //reconstruct sum
203+
double b_acc = b.m_do_accumulate ? b.m_state.acc : b.m_state.eta * b.m_state.count;
204+
sum_acc = a_acc + b_acc;
205+
//sum_acc = a.m_state.acc + b.m_state.acc;
206+
do_accumulate = true;
204207
}
205208

206209
RunStats combined(do_accumulate);

test/test_param.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ TEST(GlobalAnomalyStatsTest, AnomalyStatTest2)
289289
EXPECT_EQ(0, param.collect_func_data().size());
290290

291291
std::unordered_map<unsigned long, RunStats> g_inclusive, g_exclusive;
292-
RunStats l_inclusive, l_exclusive;
292+
RunStats l_inclusive(true), l_exclusive(true); //accumulate total runtimes
293293

294294
l_inclusive.clear();
295295
l_inclusive.push(10); l_inclusive.push(10.5); l_inclusive.push(9.5);

test/unit_tests/pserver/AggregateFuncStats.cpp

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ using namespace chimbuko;
99

1010
TEST(TestAggregateFuncStats, AggregationAndJSON){
1111
//Generate some stats representing the inclusive and exclusive runtimes collected over 2 different io steps
12-
RunStats incl1, incl2, excl1, excl2;
12+
RunStats incl1(true), incl2(true), excl1(true), excl2(true); //total runtimes should aggregate
13+
RunStats incl1_noac(false), incl2_noac(false), excl1_noac(false), excl2_noac(false); //versions which don't accumulate so we can test that AggregateFuncStats forces accumulate despite input settings
1314

1415
std::mt19937 gen(1234);
1516
std::normal_distribution<> dexcl(100,20);
1617
std::normal_distribution<> dincl_add(200,100);
1718

19+
double tsum_incl = 0, tsum_excl = 0;
20+
1821
for(int i=0;i<100;i++){
1922
double e1 = dexcl(gen);
2023
double i1 = e1 + dincl_add(gen);
@@ -27,6 +30,15 @@ TEST(TestAggregateFuncStats, AggregationAndJSON){
2730

2831
incl2.push(i2);
2932
excl2.push(e2);
33+
34+
incl1_noac.push(i1);
35+
excl1_noac.push(e1);
36+
37+
incl2_noac.push(i2);
38+
excl2_noac.push(e2);
39+
40+
tsum_incl += i1 + i2;
41+
tsum_excl += e1 + e2;
3042
}
3143

3244
int pid = 99;
@@ -37,26 +49,55 @@ TEST(TestAggregateFuncStats, AggregationAndJSON){
3749
int nanom2 = 44; //anoms on second step
3850

3951
AggregateFuncStats fstats(pid,fid,fname);
40-
fstats.add(nanom1, incl1, excl1);
41-
fstats.add(nanom2, incl2, excl2);
52+
fstats.add(nanom1, incl1_noac, excl1_noac);
53+
fstats.add(nanom2, incl2_noac, excl2_noac);
54+
55+
nlohmann::json fstats_j = fstats.get_json();
56+
//std::cout << fstats_j.dump(4) << std::endl;
4257

4358
EXPECT_EQ(fstats.get_func(), fname);
4459
EXPECT_EQ(fstats.get_func_anomaly().count(), 2);
4560
EXPECT_EQ(fstats.get_func_anomaly().accumulate(), nanom1 + nanom2);
4661

4762
RunStats incl_sum = incl1 + incl2;
4863
RunStats excl_sum = excl1 + excl2;
49-
EXPECT_EQ(fstats.get_inclusive().get_stat_values(), incl_sum.get_stat_values());
50-
EXPECT_EQ(fstats.get_exclusive().get_stat_values(), excl_sum.get_stat_values());
64+
EXPECT_NEAR(incl_sum.accumulate(), tsum_incl, 1e-8);
65+
EXPECT_NEAR(excl_sum.accumulate(), tsum_excl, 1e-8);
66+
67+
RunStats::RunStatsValues incl_got = fstats.get_inclusive().get_stat_values();
68+
RunStats::RunStatsValues incl_expect = incl_sum.get_stat_values();
69+
70+
#define RR(A) EXPECT_NEAR(incl_got.A, incl_expect.A, 1e-8)
71+
RR(count);
72+
RR(accumulate);
73+
RR(minimum);
74+
RR(maximum);
75+
RR(mean);
76+
RR(stddev);
77+
RR(skewness);
78+
RR(kurtosis);
79+
#undef RR
80+
81+
RunStats::RunStatsValues excl_got = fstats.get_exclusive().get_stat_values();
82+
RunStats::RunStatsValues excl_expect = excl_sum.get_stat_values();
83+
84+
#define RR(A) EXPECT_NEAR(excl_got.A, excl_expect.A, 1e-8)
85+
RR(count);
86+
RR(accumulate);
87+
RR(minimum);
88+
RR(maximum);
89+
RR(mean);
90+
RR(stddev);
91+
RR(skewness);
92+
RR(kurtosis);
93+
#undef RR
94+
5195

52-
nlohmann::json fstats_j = fstats.get_json();
5396
EXPECT_EQ(fstats_j["app"], pid);
5497
EXPECT_EQ(fstats_j["fid"], fid);
5598
EXPECT_EQ(fstats_j["name"], fname);
5699
EXPECT_EQ(fstats_j["stats"]["count"], 2);
57100
EXPECT_EQ(fstats_j["stats"]["accumulate"], nanom1+nanom2);
58-
EXPECT_EQ(fstats_j["inclusive"], incl_sum.get_json());
59-
EXPECT_EQ(fstats_j["exclusive"], excl_sum.get_json());
60101
}
61102

62103

test/unit_tests/pserver/GlobalAnomalyStats.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ TEST(TestGlobalAnomalyStats, UpdateFuncStat){
1111
GlobalAnomalyStats stats;
1212

1313
//Generate some stats representing the inclusive and exclusive runtimes collected over 2 different io steps
14-
RunStats incl1, incl2, excl1, excl2;
14+
RunStats incl1(true), incl2(true), excl1(true), excl2(true); //accumulate total time over all ranks
1515

1616
std::mt19937 gen(1234);
1717
std::normal_distribution<> dexcl(100,20);

0 commit comments

Comments
 (0)