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
|
||||
|
||||
sub send_benchmark {
|
||||
my ($lib, $addr, $port, $iter, $threads, $start, $end, $step) = @_;
|
||||
my ($lib, $addr, $port, $iter, $threads, $start, $end) = @_;
|
||||
my ($socket, $remote, $data);
|
||||
|
||||
$socket = IO::Socket::INET->new(
|
||||
|
|
@ -23,8 +23,8 @@ sub send_benchmark {
|
|||
$remote = $socket->accept();
|
||||
|
||||
while ($threads ne 0) {
|
||||
for (my $i = $start; $i <= $end; $i += $step) {
|
||||
my $logname = "send_results_$threads" . "threads_$i". "us";
|
||||
for (my $i = $start; $i <= $end; $i *= 2) {
|
||||
my $logname = "send_results_$threads" . "threads_$i". "fps";
|
||||
for ((1 .. $iter)) {
|
||||
$remote->recv($data, 16);
|
||||
system ("time ./$lib/sender $threads $i >> $lib/results/$logname 2>&1");
|
||||
|
|
@ -36,7 +36,7 @@ sub send_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(
|
||||
PeerAddr => $addr,
|
||||
|
|
@ -47,8 +47,8 @@ sub recv_benchmark {
|
|||
) or die "Couldn't connect to $addr:$port : $@\n";
|
||||
|
||||
while ($threads ne 0) {
|
||||
for (my $i = $start; $i <= $end; $i += $step) {
|
||||
my $logname = "recv_results_$threads" . "threads_$i". "us";
|
||||
for (my $i = $start; $i <= $end; $i *= 2) {
|
||||
my $logname = "recv_results_$threads" . "threads_$i". "fps";
|
||||
for ((1 .. $iter)) {
|
||||
$socket->send("start");
|
||||
system ("time ./$lib/receiver $threads >> $lib/results/$logname 2>&1");
|
||||
|
|
@ -65,25 +65,17 @@ GetOptions(
|
|||
"addr=s" => \(my $addr = ""),
|
||||
"port=i" => \(my $port = 0),
|
||||
"iter=i" => \(my $iter = 100),
|
||||
"sleep=i" => \(my $sleep = 0),
|
||||
"threads=i" => \(my $threads = 1),
|
||||
"start=i" => \(my $start = 0),
|
||||
"end=i" => \(my $end = 0),
|
||||
"step=i" => \(my $step = 0)
|
||||
"start=f" => \(my $start = 0),
|
||||
"end=f" => \(my $end = 0),
|
||||
) or die "failed to parse command line!\n";
|
||||
|
||||
if ($lib eq "") {
|
||||
print "library not defined!\n" and exit;
|
||||
}
|
||||
|
||||
if ($sleep ne 0) {
|
||||
if ($start ne 0 or $end ne 0 or $step ne 0) {
|
||||
print "start/end/step and sleep are mutually exclusive\n" and exit;
|
||||
}
|
||||
|
||||
$start = $sleep;
|
||||
$end = $sleep + 1;
|
||||
$step = 1;
|
||||
if (!$start or !$end) {
|
||||
print "start and end FPS values must be defined!\n" and exit;
|
||||
}
|
||||
|
||||
if ($addr eq "" or $port eq 0) {
|
||||
|
|
@ -92,10 +84,10 @@ if ($addr eq "" or $port eq 0) {
|
|||
|
||||
if ($role eq "send") {
|
||||
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" ){
|
||||
system ("make $lib" . "_receiver");
|
||||
recv_benchmark($lib, $addr, $port, $iter, $threads, $start, $end, $step);
|
||||
recv_benchmark($lib, $addr, $port, $iter, $threads, $start, $end);
|
||||
} else {
|
||||
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);
|
||||
|
||||
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 };
|
||||
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_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;
|
||||
frames++;
|
||||
|
|
@ -120,7 +120,7 @@ void thread_func(void *mem, size_t len, int thread_num, int sleep)
|
|||
int main(int argc, char **argv)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -134,7 +134,7 @@ int main(int argc, char **argv)
|
|||
std::thread **threads = (std::thread **)malloc(sizeof(std::thread *) * nthreads);
|
||||
|
||||
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)
|
||||
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);
|
||||
|
||||
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;
|
||||
uint64_t chunk_size = 0;
|
||||
|
|
@ -44,8 +44,7 @@ void thread_func(void *mem, size_t len, int thread_num, int sleep)
|
|||
for (;;);
|
||||
}
|
||||
|
||||
if (sleep >= 100)
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(sleep));
|
||||
std::this_thread::sleep_for(std::chrono::microseconds((int)((1000 / fps) * 1000)));
|
||||
|
||||
offset += 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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +76,7 @@ int main(int argc, char **argv)
|
|||
std::thread **threads = (std::thread **)malloc(sizeof(std::thread *) * nthreads);
|
||||
|
||||
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)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
|
|
|
|||
Loading…
Reference in New Issue