Milestone 3

This commit is contained in:
Joey Yakimowich-Payne 2026-01-29 17:47:31 -07:00
commit 691eb327d0
6 changed files with 507 additions and 24 deletions

View file

@ -22,6 +22,12 @@ Registry snapshot + add/remove events (milestone 1):
./build/warppipe_perf --mode registry --count 1000 --events 100
```
Link creation + removal (milestone 3):
```
./build/warppipe_perf --mode links --links 200
./build/warppipe_perf --mode links --links 200 --batch 50
```
Optional format and loopback:
```
./build/warppipe_perf --mode create-destroy --count 200 --type sink --rate 48000 --channels 2

View file

@ -1,8 +1,10 @@
#include <chrono>
#include <algorithm>
#include <cstdint>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <optional>
#include <string>
#include <vector>
@ -18,6 +20,8 @@ struct Options {
std::string target;
uint32_t count = 200;
uint32_t events = 100;
uint32_t links = 200;
uint32_t batch = 0;
uint32_t rate = 48000;
uint32_t channels = 2;
};
@ -37,10 +41,12 @@ bool ParseUInt(const char* value, uint32_t* out) {
void PrintUsage() {
std::cout << "warppipe_perf usage:\n"
<< " --mode create-destroy|registry\n"
<< " --mode create-destroy|registry|links\n"
<< " --type sink|source|both\n"
<< " --count N (default 200, per-type when --type both)\n"
<< " --events N (registry mode, default 100)\n"
<< " --links N (links mode, default 200)\n"
<< " --batch N (links mode, batch size)\n"
<< " --rate N (default 48000)\n"
<< " --channels N (default 2)\n"
<< " --target <node-name> (loopback target, optional)\n";
@ -61,6 +67,14 @@ bool ParseArgs(int argc, char* argv[], Options* options) {
if (!ParseUInt(argv[++i], &options->events)) {
return false;
}
} else if (arg == "--links" && i + 1 < argc) {
if (!ParseUInt(argv[++i], &options->links)) {
return false;
}
} else if (arg == "--batch" && i + 1 < argc) {
if (!ParseUInt(argv[++i], &options->batch)) {
return false;
}
} else if (arg == "--rate" && i + 1 < argc) {
if (!ParseUInt(argv[++i], &options->rate)) {
return false;
@ -80,7 +94,7 @@ bool ParseArgs(int argc, char* argv[], Options* options) {
if (options->type != "sink" && options->type != "source" && options->type != "both") {
return false;
}
if (options->mode != "create-destroy" && options->mode != "registry") {
if (options->mode != "create-destroy" && options->mode != "registry" && options->mode != "links") {
return false;
}
return true;
@ -94,6 +108,23 @@ double ToMillis(std::chrono::steady_clock::duration duration) {
return std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(duration).count();
}
std::optional<warppipe::PortId> FindPort(warppipe::Client* client,
warppipe::NodeId node,
bool want_input) {
for (int attempt = 0; attempt < 50; ++attempt) {
auto ports = client->ListPorts(node);
if (ports.ok()) {
for (const auto& port : ports.value) {
if (port.is_input == want_input) {
return port.id;
}
}
}
usleep(5000);
}
return std::nullopt;
}
} // namespace
int main(int argc, char* argv[]) {
@ -226,6 +257,96 @@ int main(int argc, char* argv[]) {
return 0;
}
if (options.mode == "links") {
const uint32_t pair_count = options.links;
const uint32_t batch = options.batch == 0 ? pair_count : options.batch;
double total_create_ms = 0.0;
double total_remove_ms = 0.0;
size_t total_links = 0;
for (uint32_t start_index = 0; start_index < pair_count; start_index += batch) {
const uint32_t batch_count = std::min(batch, pair_count - start_index);
std::vector<warppipe::NodeId> sinks;
std::vector<warppipe::NodeId> sources;
sinks.reserve(batch_count);
sources.reserve(batch_count);
for (uint32_t i = 0; i < batch_count; ++i) {
uint32_t index = start_index + i;
std::string sink_name = prefix + "-sink-" + std::to_string(index);
auto sink = client.value->CreateVirtualSink(sink_name, node_options);
if (!sink.ok()) {
std::cerr << "create sink failed at " << index << ": " << sink.status.message << "\n";
break;
}
sinks.push_back(sink.value.node);
std::string source_name = prefix + "-source-" + std::to_string(index);
auto source = client.value->CreateVirtualSource(source_name, node_options);
if (!source.ok()) {
std::cerr << "create source failed at " << index << ": " << source.status.message << "\n";
break;
}
sources.push_back(source.value.node);
}
const size_t pair_limit = std::min(sinks.size(), sources.size());
std::vector<warppipe::LinkId> links;
links.reserve(pair_limit);
std::vector<warppipe::PortId> out_ports;
std::vector<warppipe::PortId> in_ports;
out_ports.reserve(pair_limit);
in_ports.reserve(pair_limit);
for (size_t i = 0; i < pair_limit; ++i) {
auto out_port = FindPort(client.value.get(), sources[i], false);
auto in_port = FindPort(client.value.get(), sinks[i], true);
if (!out_port || !in_port) {
std::cerr << "port lookup failed at " << (start_index + i) << "\n";
break;
}
out_ports.push_back(*out_port);
in_ports.push_back(*in_port);
}
auto create_start = std::chrono::steady_clock::now();
for (size_t i = 0; i < out_ports.size() && i < in_ports.size(); ++i) {
auto link = client.value->CreateLink(out_ports[i], in_ports[i], warppipe::LinkOptions{});
if (!link.ok()) {
std::cerr << "link failed at " << (start_index + i) << ": " << link.status.message << "\n";
break;
}
links.push_back(link.value.id);
}
auto create_end = std::chrono::steady_clock::now();
for (const auto& link_id : links) {
client.value->RemoveLink(link_id);
}
auto remove_end = std::chrono::steady_clock::now();
for (const auto& node : sources) {
client.value->RemoveNode(node);
}
for (const auto& node : sinks) {
client.value->RemoveNode(node);
}
total_links += links.size();
total_create_ms += ToMillis(create_end - create_start);
total_remove_ms += ToMillis(remove_end - create_end);
}
const double total_ms = total_create_ms + total_remove_ms;
std::cout << "link_count=" << total_links << "\n"
<< "link_create_ms=" << std::fixed << std::setprecision(2) << total_create_ms << "\n"
<< "link_remove_ms=" << total_remove_ms << "\n"
<< "link_total_ms=" << total_ms << "\n"
<< "link_batch=" << batch << "\n";
return 0;
}
PrintUsage();
return 2;
}