Measure the framerate of a data source.
Measure the framerate of a data source. This example was originally designed for images but should work with anything.
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
static int ct = 0;
ct++;
fprintf(
stderr,
"[try %d of %d] Asking to shut down smoothly\n",ct, 3);
if (ct>2)
{
fprintf(
stderr,
"[try %d of %d] OK asking to abort...\n", ct, 3);
exit(-1);
}
}
int main(
int argc,
char *argv[]) {
if (argc==1) {
printf(
"This program checks the framerate of an output port\n");
printf(
" framerate --remote /port_name --local /local_name --prot protocol\n");
printf(
"protocol can be for example tcp,udp,mcast\n");
exit(0);
}
opt.fromCommand(argc,argv);
std::string
local =
"/get_image";
if (
opt.check(
"local",val)) {
}
if (
opt.check(
"remote", val))
{
else
}
double first = Time::now();
double prev = 0;
int ct = 0;
double now = Time::now()-first;
ct++;
if (now-prev>=2) {
double period = (
now-prev)/ct;
printf(
"Period is %g ms per message, freq is %g (%d mgs in %g secs)\n",
period*1000, 1/period, ct, now-prev);
ct = 0;
}
printf(
"Got something with %d top-level elements\n", bot->
size());
}
}
}
return 0;
}
static void handler(int sig)
A simple collection of objects that can be described and transmitted in a portable way.
size_type size() const
Gets the number of elements in the bottle.
A mini-server for performing network communication in the background.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void interrupt() override
Interrupt any current reads or writes attached to the port.
T * read(bool shouldWait=true) override
Read an available object from the port.
Utilities for manipulating the YARP network, including initialization and shutdown.
A class for storing options and configuration information.
A single value (typically within a Bottle).
virtual std::string asString() const
Get string value.
int main(int argc, char *argv[])
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.
The main, catch-all namespace for YARP.