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>
BufferedPort<Bottle> *iPort=0;
static int ct = 0;
ct++;
fprintf(stderr, "[try %d of %d] Asking to shut down smoothly\n",ct, 3);
if (iPort!=0)
iPort->interrupt();
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("Call as:\n");
printf(" framerate --remote /port_name --local /local_name --prot protocol\n");
printf("protocol can be for example tcp,udp,mcast\n");
exit(0);
}
BufferedPort<Bottle> port;
iPort=&port;
Property opt;
opt.fromCommand(argc,argv);
Value *val;
Value *prot;
std::string
local =
"/get_image";
if (opt.check("local",val)) {
local = val->asString().c_str();
}
port.open(
local.c_str());
if (opt.check("remote", val))
{
if (opt.check("prot", prot))
else
}
double prev = 0;
int ct = 0;
bool spoke = false;
Bottle *bot = port.read(true);
ct++;
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);
fflush(stdout);
ct = 0;
spoke = false;
}
if (bot!=NULL) {
if (!spoke) {
printf("Got something with %d top-level elements\n", bot->size());
fflush(stdout);
spoke = true;
}
}
}
iPort=0;
return 0;
}
static void handler(int sig)
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
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.
int main(int argc, char *argv[])