Skip to content

Commit

Permalink
#Centipede Rename a couple symbols in Stats
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 589843474
  • Loading branch information
ussuri authored and copybara-github committed Dec 11, 2023
1 parent 8e5701e commit 4923853
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
5 changes: 2 additions & 3 deletions centipede/centipede.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <filesystem>
#include <functional>
#include <iostream>
#include <memory>
Expand Down Expand Up @@ -199,8 +198,8 @@ void Centipede::UpdateAndMaybeLogStats(std::string_view log_type,
size_t min_log_level) {
auto [max_corpus_size, avg_corpus_size] = corpus_.MaxAndAvgSize();

stats_.unix_micros = absl::ToUnixMicros(absl::Now());
stats_.corpus_size = corpus_.NumActive();
stats_.timestamp_unix_micros = absl::ToUnixMicros(absl::Now());
stats_.active_corpus_size = corpus_.NumActive();
stats_.num_covered_pcs = fs_.CountFeatures(feature_domains::kPCs);
stats_.max_corpus_element_size = max_corpus_size;
stats_.avg_corpus_element_size = avg_corpus_size;
Expand Down
12 changes: 6 additions & 6 deletions centipede/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ namespace centipede {
// hence the use of atomics.
// These objects may also be accessed after all worker threads have joined.
struct Stats {
std::atomic<uint64_t> unix_micros;
std::atomic<uint64_t> timestamp_unix_micros;
std::atomic<uint64_t> num_executions;
std::atomic<uint64_t> num_covered_pcs;
std::atomic<uint64_t> corpus_size;
std::atomic<uint64_t> active_corpus_size;
std::atomic<uint64_t> max_corpus_element_size;
std::atomic<uint64_t> avg_corpus_element_size;

Expand All @@ -70,9 +70,9 @@ struct Stats {
Aggregation::kMinMaxAvg,
},
{
&Stats::corpus_size,
"CorpusSize",
"Corpus size",
&Stats::active_corpus_size,
"ActiveCorpusSize",
"Active corpus size",
Aggregation::kMinMaxAvg,
},
{
Expand All @@ -88,7 +88,7 @@ struct Stats {
Aggregation::kMinMaxAvg,
},
{
&Stats::unix_micros,
&Stats::timestamp_unix_micros,
"UnixMicros",
"Timestamp",
Aggregation::kMinMax,
Expand Down
36 changes: 18 additions & 18 deletions centipede/stats_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ TEST(Stats, PrintStatsToLog) {
stats_vec[2].num_covered_pcs = 25;
stats_vec[3].num_covered_pcs = 40;

stats_vec[0].corpus_size = 1000;
stats_vec[1].corpus_size = 2000;
stats_vec[2].corpus_size = 3000;
stats_vec[3].corpus_size = 4000;
stats_vec[0].active_corpus_size = 1000;
stats_vec[1].active_corpus_size = 2000;
stats_vec[2].active_corpus_size = 3000;
stats_vec[3].active_corpus_size = 4000;

for (size_t i = 0; i < 4; ++i) {
auto &stats = stats_vec[i];
stats.unix_micros = CivilTimeToUnixMicros(1970, 1, 1, 0, 0, i);
stats.timestamp_unix_micros = CivilTimeToUnixMicros(1970, 1, 1, 0, 0, i);
stats.max_corpus_element_size = 2 * i + 1;
stats.avg_corpus_element_size = i + 1;
stats.num_executions = i + 100;
Expand All @@ -99,7 +99,7 @@ TEST(Stats, PrintStatsToLog) {
"Number of executions:\n"
"Experiment A: min:\t100\tmax:\t102\tavg:\t101.0\t--\t100\t102\n"
"Experiment B: min:\t101\tmax:\t103\tavg:\t102.0\t--\t101\t103\n"
"Corpus size:\n"
"Active corpus size:\n"
"Experiment A: min:\t1000\tmax:\t3000\tavg:\t2000.0\t--\t1000\t3000\n"
"Experiment B: min:\t2000\tmax:\t4000\tavg:\t3000.0\t--\t2000\t4000\n"
"Max element size:\n"
Expand All @@ -123,10 +123,10 @@ TEST(Stats, PrintStatsToLog) {
for (auto &stats : stats_vec) {
stats.num_covered_pcs += 100;
stats.num_executions += 1000;
stats.corpus_size += 1;
stats.active_corpus_size += 1;
stats.max_corpus_element_size += 10;
stats.avg_corpus_element_size += 10;
stats.unix_micros += 1000000;
stats.timestamp_unix_micros += 1000000;
}

constexpr std::string_view kExpectedLogLines =
Expand All @@ -137,7 +137,7 @@ TEST(Stats, PrintStatsToLog) {
"Number of executions:\n"
"Experiment A: min:\t1100\tmax:\t1102\tavg:\t1101.0\t--\t1100\t1102\n"
"Experiment B: min:\t1101\tmax:\t1103\tavg:\t1102.0\t--\t1101\t1103\n"
"Corpus size:\n"
"Active corpus size:\n"
"Experiment A: min:\t1001\tmax:\t3001\tavg:\t2001.0\t--\t1001\t3001\n"
"Experiment B: min:\t2001\tmax:\t4001\tavg:\t3001.0\t--\t2001\t4001\n"
"Max element size:\n"
Expand All @@ -163,16 +163,16 @@ TEST(Stats, DumpStatsToCsvFile) {

std::vector<Stats> stats_vec(4);
stats_vec[0].num_covered_pcs = 10;
stats_vec[0].corpus_size = 1000;
stats_vec[0].active_corpus_size = 1000;
stats_vec[1].num_covered_pcs = 15;
stats_vec[1].corpus_size = 2000;
stats_vec[1].active_corpus_size = 2000;
stats_vec[2].num_covered_pcs = 25;
stats_vec[2].corpus_size = 3000;
stats_vec[2].active_corpus_size = 3000;
stats_vec[3].num_covered_pcs = 40;
stats_vec[3].corpus_size = 4000;
stats_vec[3].active_corpus_size = 4000;
for (size_t i = 0; i < 4; ++i) {
auto &stats = stats_vec[i];
stats.unix_micros = i + 1000000;
stats.timestamp_unix_micros = i + 1000000;
stats.max_corpus_element_size = 2 * i + 1;
stats.avg_corpus_element_size = i + 1;
stats.num_executions = i + 100;
Expand All @@ -196,10 +196,10 @@ TEST(Stats, DumpStatsToCsvFile) {
stats_csv_appender.ReportCurrStats();

for (auto &stats : stats_vec) {
stats.unix_micros += 1;
stats.timestamp_unix_micros += 1;
stats.num_executions += 1;
stats.num_covered_pcs += 1;
stats.corpus_size += 1;
stats.active_corpus_size += 1;
stats.max_corpus_element_size += 1;
stats.avg_corpus_element_size += 1;
}
Expand All @@ -212,11 +212,11 @@ TEST(Stats, DumpStatsToCsvFile) {
workdir / "fuzzing-stats-.000000.ExperimentB.csv",
};
const std::vector<std::string_view> kExpectedCsvContents = {
R"(NumCoveredPcs_Min,NumCoveredPcs_Max,NumCoveredPcs_Avg,NumExecs_Min,NumExecs_Max,NumExecs_Avg,CorpusSize_Min,CorpusSize_Max,CorpusSize_Avg,MaxEltSize_Min,MaxEltSize_Max,MaxEltSize_Avg,AvgEltSize_Min,AvgEltSize_Max,AvgEltSize_Avg,UnixMicros_Min,UnixMicros_Max,
R"(NumCoveredPcs_Min,NumCoveredPcs_Max,NumCoveredPcs_Avg,NumExecs_Min,NumExecs_Max,NumExecs_Avg,ActiveCorpusSize_Min,ActiveCorpusSize_Max,ActiveCorpusSize_Avg,MaxEltSize_Min,MaxEltSize_Max,MaxEltSize_Avg,AvgEltSize_Min,AvgEltSize_Max,AvgEltSize_Avg,UnixMicros_Min,UnixMicros_Max,
10,25,17.5,100,102,101.0,1000,3000,2000.0,1,5,3.0,1,3,2.0,1000000,1000002,
11,26,18.5,101,103,102.0,1001,3001,2001.0,2,6,4.0,2,4,3.0,1000001,1000003,
)",
R"(NumCoveredPcs_Min,NumCoveredPcs_Max,NumCoveredPcs_Avg,NumExecs_Min,NumExecs_Max,NumExecs_Avg,CorpusSize_Min,CorpusSize_Max,CorpusSize_Avg,MaxEltSize_Min,MaxEltSize_Max,MaxEltSize_Avg,AvgEltSize_Min,AvgEltSize_Max,AvgEltSize_Avg,UnixMicros_Min,UnixMicros_Max,
R"(NumCoveredPcs_Min,NumCoveredPcs_Max,NumCoveredPcs_Avg,NumExecs_Min,NumExecs_Max,NumExecs_Avg,ActiveCorpusSize_Min,ActiveCorpusSize_Max,ActiveCorpusSize_Avg,MaxEltSize_Min,MaxEltSize_Max,MaxEltSize_Avg,AvgEltSize_Min,AvgEltSize_Max,AvgEltSize_Avg,UnixMicros_Min,UnixMicros_Max,
15,40,27.5,101,103,102.0,2000,4000,3000.0,3,7,5.0,2,4,3.0,1000001,1000003,
16,41,28.5,102,104,103.0,2001,4001,3001.0,4,8,6.0,3,5,4.0,1000002,1000004,
)",
Expand Down

0 comments on commit 4923853

Please sign in to comment.