Skip to content

Commit e3eec83

Browse files
committed
-- run clang-format on all source files
1 parent 1c88546 commit e3eec83

File tree

523 files changed

+11543
-11394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

523 files changed

+11543
-11394
lines changed

Demos/Benchmark/BenchmarkDemo.cpp

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void PrintUsage(const std::string& executableName)
7979
struct BenchmarkConfig
8080
{
8181
uint32_t numberOfSimulationRuns = 4;
82-
std::chrono::seconds simulationDuration = 1s;
82+
std::chrono::seconds simulationDuration = 1s;
8383
uint32_t numberOfParticipants = 2;
8484
uint32_t messageCount = 50;
8585
uint32_t messageSizeInBytes = 1000;
@@ -94,12 +94,8 @@ bool Parse(int argc, char** argv, BenchmarkConfig& config)
9494
std::vector<std::string> args;
9595
std::copy((argv + 1), (argv + argc), std::back_inserter(args));
9696

97-
auto asNum = [](const auto& str) {
98-
return static_cast<uint32_t>(std::stoul(str));
99-
};
100-
auto asStr = [](auto& a) {
101-
return std::string{a};
102-
};
97+
auto asNum = [](const auto& str) { return static_cast<uint32_t>(std::stoul(str)); };
98+
auto asStr = [](auto& a) { return std::string{a}; };
10399

104100
// test and remove the flag from args, returns true if flag was present
105101
auto consumeFlag = [&args](const auto& namedOption) {
@@ -204,7 +200,9 @@ bool Parse(int argc, char** argv, BenchmarkConfig& config)
204200
case 2:
205201
config.simulationDuration = std::chrono::seconds(asNum(args.at(1)));
206202
// [[fallthrough]]
207-
case 1: config.numberOfSimulationRuns = asNum(args.at(0)); break;
203+
case 1:
204+
config.numberOfSimulationRuns = asNum(args.at(0));
205+
break;
208206
default:
209207
if (haveUserOptions)
210208
{
@@ -263,7 +261,7 @@ uint32_t relateParticipant(uint32_t idx, uint32_t numberOfParticipants)
263261
}
264262
else
265263
{
266-
return idx+1;
264+
return idx + 1;
267265
}
268266
}
269267

@@ -293,7 +291,7 @@ void ParticipantsThread(std::shared_ptr<SilKit::Config::IParticipantConfiguratio
293291
const std::string topicSub =
294292
"Topic" + std::to_string(relateParticipant(participantIndex, benchmark.numberOfParticipants));
295293
SilKit::Services::PubSub::PubSubSpec dataSpec{topicPub, {}};
296-
SilKit::Services::PubSub::PubSubSpec matchingDataSpec{topicSub, {}};
294+
SilKit::Services::PubSub::PubSubSpec matchingDataSpec{topicSub, {}};
297295
auto publisher = participant->CreateDataPublisher("PubCtrl1", dataSpec, 0);
298296
participant->CreateDataSubscriber("SubCtrl1", matchingDataSpec, [&messageCounter](auto*, auto&) {
299297
// this is handled in I/O thread, so no data races on counter.
@@ -303,24 +301,24 @@ void ParticipantsThread(std::shared_ptr<SilKit::Config::IParticipantConfiguratio
303301
const auto isVerbose = participantIndex == 0;
304302
timeSyncService->SetSimulationStepHandler(
305303
[=, &publisher](std::chrono::nanoseconds now, const auto /*duration*/) {
306-
if (now > benchmark.simulationDuration)
307-
{
308-
lifecycleService->Stop("Simulation done");
309-
}
304+
if (now > benchmark.simulationDuration)
305+
{
306+
lifecycleService->Stop("Simulation done");
307+
}
310308

311-
if (isVerbose)
312-
{
313-
const auto simulationDurationInNs =
314-
std::chrono::duration_cast<std::chrono::nanoseconds>(benchmark.simulationDuration);
315-
const auto durationOfOneSimulationPercentile = simulationDurationInNs / 20;
309+
if (isVerbose)
310+
{
311+
const auto simulationDurationInNs =
312+
std::chrono::duration_cast<std::chrono::nanoseconds>(benchmark.simulationDuration);
313+
const auto durationOfOneSimulationPercentile = simulationDurationInNs / 20;
316314

317-
if (now % durationOfOneSimulationPercentile < stepSize)
318-
{
319-
std::cout << ".";
320-
}
315+
if (now % durationOfOneSimulationPercentile < stepSize)
316+
{
317+
std::cout << ".";
321318
}
322-
PublishMessages(publisher, benchmark.messageCount, benchmark.messageSizeInBytes);
323-
},
319+
}
320+
PublishMessages(publisher, benchmark.messageCount, benchmark.messageSizeInBytes);
321+
},
324322
stepSize);
325323

326324
auto lifecycleFuture = lifecycleService->StartLifecycle();
@@ -408,7 +406,7 @@ int main(int argc, char** argv)
408406
registry->StartListening(benchmark.registryUri);
409407

410408
std::vector<size_t> messageCounts;
411-
std::vector<std::chrono::nanoseconds> measuredRealDurations;
409+
std::vector<std::chrono::nanoseconds> measuredRealDurations;
412410

413411
for (uint32_t simulationRun = 1; simulationRun <= benchmark.numberOfSimulationRuns; simulationRun++)
414412
{
@@ -451,15 +449,13 @@ int main(int argc, char** argv)
451449
auto endTimestamp = std::chrono::high_resolution_clock::now();
452450
measuredRealDurations.emplace_back(endTimestamp - startTimestamp);
453451
auto totalCount = std::accumulate(counters.begin(), counters.end(), size_t{0});
454-
messageCounts.emplace_back(totalCount);
452+
messageCounts.emplace_back(totalCount);
455453
std::cout << " " << measuredRealDurations.back() << std::endl;
456454
}
457455

458456
std::vector<double> measuredRealDurationsSeconds(measuredRealDurations.size());
459457
std::transform(measuredRealDurations.begin(), measuredRealDurations.end(), measuredRealDurationsSeconds.begin(),
460-
[](auto d) {
461-
return static_cast<double>(d.count() / 1e9);
462-
});
458+
[](auto d) { return static_cast<double>(d.count() / 1e9); });
463459

464460
const auto averageDuration = mean_and_error(measuredRealDurationsSeconds);
465461

Demos/Benchmark/LatencyDemo.cpp

Lines changed: 54 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,8 @@ bool Parse(int argc, char** argv, BenchmarkConfig& config)
8585
std::vector<std::string> args;
8686
std::copy((argv + 1), (argv + argc), std::back_inserter(args));
8787

88-
auto asNum = [](const auto& str) {
89-
return static_cast<uint32_t>(std::stoul(str));
90-
};
91-
auto asStr = [](auto& a) {
92-
return std::string{a};
93-
};
88+
auto asNum = [](const auto& str) { return static_cast<uint32_t>(std::stoul(str)); };
89+
auto asStr = [](auto& a) { return std::string{a}; };
9490

9591
// test and remove the flag from args, returns true if flag was present
9692
auto consumeFlag = [&args](const auto& namedOption) {
@@ -188,7 +184,9 @@ bool Parse(int argc, char** argv, BenchmarkConfig& config)
188184
case 2:
189185
config.messageSizeInBytes = asNum(args.at(1));
190186
// [[fallthrough]]
191-
case 1: config.messageCount = asNum(args.at(0)); break;
187+
case 1:
188+
config.messageCount = asNum(args.at(0));
189+
break;
192190
default:
193191
if (haveUserOptions)
194192
{
@@ -245,7 +243,8 @@ void PrintParameters(BenchmarkConfig benchmark)
245243
<< std::endl
246244
<< "Running simulations with the following parameters:" << std::endl
247245
<< std::endl
248-
<< std::left << std::setw(38) << "- Is Receiver: " << (benchmark.isReceiver ? "True" : "False") << std::endl
246+
<< std::left << std::setw(38) << "- Is Receiver: " << (benchmark.isReceiver ? "True" : "False")
247+
<< std::endl
249248
<< std::left << std::setw(38) << "- Total message count: " << benchmark.messageCount << std::endl
250249
<< std::left << std::setw(38) << "- Message size (bytes): " << benchmark.messageSizeInBytes << std::endl
251250
<< std::left << std::setw(38) << "- Registry URI: " << benchmark.registryUri << std::endl
@@ -315,38 +314,39 @@ int main(int argc, char** argv)
315314
std::string topicPub = benchmark.isReceiver ? "Pong" : "Ping";
316315
std::string topicSub = benchmark.isReceiver ? "Ping" : "Pong";
317316
auto publisher = participant->CreateDataPublisher("PubCtrl1", {topicPub, {}}, 1);
318-
participant->CreateDataSubscriber(
319-
"SubCtrl1", {topicSub, {}},
320-
[data, publisher, benchmark, &sendCount, &allSent, &allSentPromise,
317+
participant->CreateDataSubscriber("SubCtrl1", {topicSub, {}},
318+
[data, publisher, benchmark, &sendCount, &allSent, &allSentPromise,
321319

322-
&measuredRoundtrips, &sendTime, &startTimestamp](auto*, auto&) {
323-
if (!allSent)
320+
&measuredRoundtrips, &sendTime, &startTimestamp](auto*, auto&) {
321+
if (!allSent)
322+
{
323+
if (!benchmark.isReceiver)
324324
{
325-
if (!benchmark.isReceiver)
325+
if (sendCount == 0)
326326
{
327-
if (sendCount == 0)
328-
{
329-
startTimestamp = std::chrono::high_resolution_clock::now(); // Initial receive: Start runtime measurement
330-
}
331-
else
332-
{
333-
measuredRoundtrips.push_back(std::chrono::high_resolution_clock::now() - sendTime);
334-
}
335-
sendTime = std::chrono::high_resolution_clock::now();
327+
startTimestamp =
328+
std::chrono::high_resolution_clock::now(); // Initial receive: Start runtime measurement
336329
}
337-
publisher->Publish(data);
338-
sendCount++;
339-
if (benchmark.isReceiver && (benchmark.messageCount <= 20 || sendCount % (benchmark.messageCount / 20) == 0))
330+
else
340331
{
341-
std::cout << ".";
342-
}
343-
if (sendCount >= benchmark.messageCount+1) // Initial publish has no timing, use +1
344-
{
345-
allSentPromise.set_value();
346-
allSent = true;
332+
measuredRoundtrips.push_back(std::chrono::high_resolution_clock::now() - sendTime);
347333
}
334+
sendTime = std::chrono::high_resolution_clock::now();
335+
}
336+
publisher->Publish(data);
337+
sendCount++;
338+
if (benchmark.isReceiver
339+
&& (benchmark.messageCount <= 20 || sendCount % (benchmark.messageCount / 20) == 0))
340+
{
341+
std::cout << ".";
348342
}
349-
});
343+
if (sendCount >= benchmark.messageCount + 1) // Initial publish has no timing, use +1
344+
{
345+
allSentPromise.set_value();
346+
allSent = true;
347+
}
348+
}
349+
});
350350

351351
if (!benchmark.isReceiver) // Initial publish without timing
352352
{
@@ -371,13 +371,13 @@ int main(int argc, char** argv)
371371
allDonePublisher->Publish(std::vector<uint8_t>{0});
372372
}
373373
participant->CreateDataSubscriber("SubCtrl2", {topicSubAllDone, {}},
374-
[&syncParticipants, benchmark, allDonePublisher](auto*, auto&) {
375-
if (!benchmark.isReceiver)
376-
{
377-
allDonePublisher->Publish(std::vector<uint8_t>{0});
378-
}
379-
syncParticipants.set_value();
380-
});
374+
[&syncParticipants, benchmark, allDonePublisher](auto*, auto&) {
375+
if (!benchmark.isReceiver)
376+
{
377+
allDonePublisher->Publish(std::vector<uint8_t>{0});
378+
}
379+
syncParticipants.set_value();
380+
});
381381
auto syncParticipantsFuture = syncParticipants.get_future();
382382
syncParticipantsFuture.wait();
383383
std::cout << "... done." << std::endl;
@@ -394,8 +394,9 @@ int main(int argc, char** argv)
394394
std::vector<double> measuredLatencySeconds(measuredRoundtrips.size());
395395
std::transform(measuredRoundtrips.begin(), measuredRoundtrips.end(), measuredLatencySeconds.begin(),
396396
[](auto d) {
397-
return static_cast<double>(d.count() / 1.e3 * 0.5); // Convert to microseconds, factor 0.5 for latency from roundtrip
398-
});
397+
return static_cast<double>(d.count() / 1.e3
398+
* 0.5); // Convert to microseconds, factor 0.5 for latency from roundtrip
399+
});
399400

400401
const auto averageLatency = mean_and_error(measuredLatencySeconds);
401402
std::ostringstream averageLatencyWithUnit;
@@ -417,16 +418,20 @@ int main(int argc, char** argv)
417418
durationWithUnit.precision(3);
418419
durationWithUnit << durationSeconds << " s";
419420

420-
std::cout << std::setw(38) << "- Realtime duration (runtime): " << std::setw(6) << durationWithUnit.str() << std::endl
421-
<< std::setw(38) << "- Throughput (data size/runtime): " << std::setw(6) << throughputWithUnit.str() << std::endl
422-
<< std::setw(38) << "- Latency: " << std::setw(6) << averageLatencyWithUnit.str() << " +/- " << averageLatency.second << std::endl
421+
std::cout << std::setw(38) << "- Realtime duration (runtime): " << std::setw(6) << durationWithUnit.str()
422+
<< std::endl
423+
<< std::setw(38) << "- Throughput (data size/runtime): " << std::setw(6) << throughputWithUnit.str()
424+
<< std::endl
425+
<< std::setw(38) << "- Latency: " << std::setw(6) << averageLatencyWithUnit.str() << " +/- "
426+
<< averageLatency.second << std::endl
423427
<< std::endl;
424428

425429
if (benchmark.writeCsv != "")
426430
{
427431
std::stringstream csvHeader;
428432
csvHeader << "# SilKitBenchmarkDemo, SIL Kit Version " << SilKit::Version::String();
429-
const auto csvColumns = "messageSize; messageCount; runtime(s); throughput(MiB/s); latency(us); latency_err";
433+
const auto csvColumns =
434+
"messageSize; messageCount; runtime(s); throughput(MiB/s); latency(us); latency_err";
430435
std::fstream csvFile;
431436
csvFile.open(benchmark.writeCsv, std::ios_base::in | std::ios_base::out); // Try to open
432437
bool csvValid{true};
@@ -453,10 +458,9 @@ int main(int argc, char** argv)
453458
{
454459
// Append data
455460
csvFile.seekp(0, std::ios_base::end);
456-
csvFile << benchmark.messageSizeInBytes << ";" << benchmark.messageCount << ";"
457-
<< durationSeconds << ";"
458-
<< throughput << ";"
459-
<< averageLatency.first << ";" << averageLatency.second << std::endl;
461+
csvFile << benchmark.messageSizeInBytes << ";" << benchmark.messageCount << ";" << durationSeconds
462+
<< ";" << throughput << ";" << averageLatency.first << ";" << averageLatency.second
463+
<< std::endl;
460464
}
461465
csvFile.close();
462466
}

0 commit comments

Comments
 (0)