Convert the benchmark setup to FPS-based
This commit is contained in:
parent
b4c7e84900
commit
29bf2197fb
|
|
@ -9,7 +9,7 @@ use Getopt::Long;
|
||||||
$| = 1; # autoflush
|
$| = 1; # autoflush
|
||||||
|
|
||||||
sub send_benchmark {
|
sub send_benchmark {
|
||||||
my ($lib, $addr, $port, $iter, $threads, $start, $end, $step) = @_;
|
my ($lib, $addr, $port, $iter, $threads, $start, $end) = @_;
|
||||||
my ($socket, $remote, $data);
|
my ($socket, $remote, $data);
|
||||||
|
|
||||||
$socket = IO::Socket::INET->new(
|
$socket = IO::Socket::INET->new(
|
||||||
|
|
@ -23,8 +23,8 @@ sub send_benchmark {
|
||||||
$remote = $socket->accept();
|
$remote = $socket->accept();
|
||||||
|
|
||||||
while ($threads ne 0) {
|
while ($threads ne 0) {
|
||||||
for (my $i = $start; $i <= $end; $i += $step) {
|
for (my $i = $start; $i <= $end; $i *= 2) {
|
||||||
my $logname = "send_results_$threads" . "threads_$i". "us";
|
my $logname = "send_results_$threads" . "threads_$i". "fps";
|
||||||
for ((1 .. $iter)) {
|
for ((1 .. $iter)) {
|
||||||
$remote->recv($data, 16);
|
$remote->recv($data, 16);
|
||||||
system ("time ./$lib/sender $threads $i >> $lib/results/$logname 2>&1");
|
system ("time ./$lib/sender $threads $i >> $lib/results/$logname 2>&1");
|
||||||
|
|
@ -36,7 +36,7 @@ sub send_benchmark {
|
||||||
}
|
}
|
||||||
|
|
||||||
sub recv_benchmark {
|
sub recv_benchmark {
|
||||||
my ($lib, $addr, $port, $iter, $threads, $start, $end, $step) = @_;
|
my ($lib, $addr, $port, $iter, $threads, $start, $end) = @_;
|
||||||
|
|
||||||
my $socket = IO::Socket::INET->new(
|
my $socket = IO::Socket::INET->new(
|
||||||
PeerAddr => $addr,
|
PeerAddr => $addr,
|
||||||
|
|
@ -47,8 +47,8 @@ sub recv_benchmark {
|
||||||
) or die "Couldn't connect to $addr:$port : $@\n";
|
) or die "Couldn't connect to $addr:$port : $@\n";
|
||||||
|
|
||||||
while ($threads ne 0) {
|
while ($threads ne 0) {
|
||||||
for (my $i = $start; $i <= $end; $i += $step) {
|
for (my $i = $start; $i <= $end; $i *= 2) {
|
||||||
my $logname = "recv_results_$threads" . "threads_$i". "us";
|
my $logname = "recv_results_$threads" . "threads_$i". "fps";
|
||||||
for ((1 .. $iter)) {
|
for ((1 .. $iter)) {
|
||||||
$socket->send("start");
|
$socket->send("start");
|
||||||
system ("time ./$lib/receiver $threads >> $lib/results/$logname 2>&1");
|
system ("time ./$lib/receiver $threads >> $lib/results/$logname 2>&1");
|
||||||
|
|
@ -65,25 +65,17 @@ GetOptions(
|
||||||
"addr=s" => \(my $addr = ""),
|
"addr=s" => \(my $addr = ""),
|
||||||
"port=i" => \(my $port = 0),
|
"port=i" => \(my $port = 0),
|
||||||
"iter=i" => \(my $iter = 100),
|
"iter=i" => \(my $iter = 100),
|
||||||
"sleep=i" => \(my $sleep = 0),
|
|
||||||
"threads=i" => \(my $threads = 1),
|
"threads=i" => \(my $threads = 1),
|
||||||
"start=i" => \(my $start = 0),
|
"start=f" => \(my $start = 0),
|
||||||
"end=i" => \(my $end = 0),
|
"end=f" => \(my $end = 0),
|
||||||
"step=i" => \(my $step = 0)
|
|
||||||
) or die "failed to parse command line!\n";
|
) or die "failed to parse command line!\n";
|
||||||
|
|
||||||
if ($lib eq "") {
|
if ($lib eq "") {
|
||||||
print "library not defined!\n" and exit;
|
print "library not defined!\n" and exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($sleep ne 0) {
|
if (!$start or !$end) {
|
||||||
if ($start ne 0 or $end ne 0 or $step ne 0) {
|
print "start and end FPS values must be defined!\n" and exit;
|
||||||
print "start/end/step and sleep are mutually exclusive\n" and exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
$start = $sleep;
|
|
||||||
$end = $sleep + 1;
|
|
||||||
$step = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($addr eq "" or $port eq 0) {
|
if ($addr eq "" or $port eq 0) {
|
||||||
|
|
@ -92,10 +84,10 @@ if ($addr eq "" or $port eq 0) {
|
||||||
|
|
||||||
if ($role eq "send") {
|
if ($role eq "send") {
|
||||||
system ("make $lib" . "_sender");
|
system ("make $lib" . "_sender");
|
||||||
send_benchmark($lib, $addr, $port, $iter, $threads, $start, $end, $step);
|
send_benchmark($lib, $addr, $port, $iter, $threads, $start, $end);
|
||||||
} elsif ($role eq "recv" ){
|
} elsif ($role eq "recv" ){
|
||||||
system ("make $lib" . "_receiver");
|
system ("make $lib" . "_receiver");
|
||||||
recv_benchmark($lib, $addr, $port, $iter, $threads, $start, $end, $step);
|
recv_benchmark($lib, $addr, $port, $iter, $threads, $start, $end);
|
||||||
} else {
|
} else {
|
||||||
print "invalid role: '$role'\n" and exit;
|
print "invalid role: '$role'\n" and exit;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ extern void *get_mem(int argc, char **argv, size_t& len);
|
||||||
|
|
||||||
std::atomic<int> nready(0);
|
std::atomic<int> nready(0);
|
||||||
|
|
||||||
void thread_func(void *mem, size_t len, int thread_num, int sleep)
|
void thread_func(void *mem, size_t len, int thread_num, double fps)
|
||||||
{
|
{
|
||||||
char addr[64] = { 0 };
|
char addr[64] = { 0 };
|
||||||
enum AVCodecID codec_id = AV_CODEC_ID_H265;
|
enum AVCodecID codec_id = AV_CODEC_ID_H265;
|
||||||
|
|
@ -94,7 +94,7 @@ void thread_func(void *mem, size_t len, int thread_num, int sleep)
|
||||||
|
|
||||||
av_interleaved_write_frame(avfctx, &pkt);
|
av_interleaved_write_frame(avfctx, &pkt);
|
||||||
av_packet_unref(&pkt);
|
av_packet_unref(&pkt);
|
||||||
std::this_thread::sleep_for(std::chrono::microseconds(sleep));
|
std::this_thread::sleep_for(std::chrono::microseconds((int)((1000 / fps) * 1000)));
|
||||||
|
|
||||||
i += chunk_size;
|
i += chunk_size;
|
||||||
frames++;
|
frames++;
|
||||||
|
|
@ -120,7 +120,7 @@ void thread_func(void *mem, size_t len, int thread_num, int sleep)
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
fprintf(stderr, "usage: ./%s <number of threads> <us of sleep between frames>\n", __FILE__);
|
fprintf(stderr, "usage: ./%s <number of threads> <fps>\n", __FILE__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,7 +134,7 @@ int main(int argc, char **argv)
|
||||||
std::thread **threads = (std::thread **)malloc(sizeof(std::thread *) * nthreads);
|
std::thread **threads = (std::thread **)malloc(sizeof(std::thread *) * nthreads);
|
||||||
|
|
||||||
for (int i = 0; i < nthreads; ++i)
|
for (int i = 0; i < nthreads; ++i)
|
||||||
threads[i] = new std::thread(thread_func, mem, len, i * 2, atoi(argv[2]));
|
threads[i] = new std::thread(thread_func, mem, len, i * 2, atof(argv[2]));
|
||||||
|
|
||||||
while (nready.load() != nthreads)
|
while (nready.load() != nthreads)
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ extern void *get_mem(int argc, char **argv, size_t& len);
|
||||||
|
|
||||||
std::atomic<int> nready(0);
|
std::atomic<int> nready(0);
|
||||||
|
|
||||||
void thread_func(void *mem, size_t len, int thread_num, int sleep)
|
void thread_func(void *mem, size_t len, int thread_num, double fps)
|
||||||
{
|
{
|
||||||
size_t bytes_sent = 0;
|
size_t bytes_sent = 0;
|
||||||
uint64_t chunk_size = 0;
|
uint64_t chunk_size = 0;
|
||||||
|
|
@ -44,8 +44,7 @@ void thread_func(void *mem, size_t len, int thread_num, int sleep)
|
||||||
for (;;);
|
for (;;);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sleep >= 100)
|
std::this_thread::sleep_for(std::chrono::microseconds((int)((1000 / fps) * 1000)));
|
||||||
std::this_thread::sleep_for(std::chrono::microseconds(sleep));
|
|
||||||
|
|
||||||
offset += chunk_size;
|
offset += chunk_size;
|
||||||
bytes_sent += chunk_size;
|
bytes_sent += chunk_size;
|
||||||
|
|
@ -67,7 +66,7 @@ void thread_func(void *mem, size_t len, int thread_num, int sleep)
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc != 3) {
|
if (argc != 3) {
|
||||||
fprintf(stderr, "usage: ./%s <number of threads> <us of sleep between frames>\n", __FILE__);
|
fprintf(stderr, "usage: ./%s <number of threads> <fps>\n", __FILE__);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +76,7 @@ int main(int argc, char **argv)
|
||||||
std::thread **threads = (std::thread **)malloc(sizeof(std::thread *) * nthreads);
|
std::thread **threads = (std::thread **)malloc(sizeof(std::thread *) * nthreads);
|
||||||
|
|
||||||
for (int i = 0; i < nthreads; ++i)
|
for (int i = 0; i < nthreads; ++i)
|
||||||
threads[i] = new std::thread(thread_func, mem, len, i * 2, atoi(argv[2]));
|
threads[i] = new std::thread(thread_func, mem, len, i * 2, atof(argv[2]));
|
||||||
|
|
||||||
while (nready.load() != nthreads)
|
while (nready.load() != nthreads)
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue