This is what i wrote:
#include <stdlib.h> /* EXIT_SUCCESS, EXIT_FAILURE */
#include <stdio.h> /* printf(), fprintf() */
#include <sys/neutrino.h> /* struct _pulse, ChannelCreate(), ChannelDestroy(), ConnectAttach(), MsgReceivePulse */
#include <sys/siginfo.h> /* struct sigevent, SIGEV_PULSE_INIT */
#include <string.h> /* strerror() */
#include <errno.h> /* extern int errno */
#include <time.h> /* clock(), struct itimerspec, timer_create(), timer_delete(), timer_settime() */
#define CODE_TIMER 1
#define FREQ 50 /* Hz */
#define FREQUENCY ((long) (1000000000/FREQ))
#define DIM 255 /* Dimensione del buffer */
extern int errno;
int chid; /* Channel ID */
int start_time;
char * progname = "My_Project.c";
char * file = "/dev/zero";
timer_t SetupPulseAndTimer (long);
int GotAPulse (void);
int Delete_Timer (timer_t);
int main(void)
{
start_time = time(NULL);
int count, rcvid; //PID del mittente
struct _pulse pulse; //Il nostro pulse
timer_t t_id;
if((chid = ChannelCreate(0)) == - 1)
{
fprintf(stderr, "%s: couldn't create channel. Error: %s\n", progname, strerror(errno));
exit(EXIT_FAILURE);
}
//Prepariamo pulse e timer
t_id = SetupPulseAndTimer(FREQUENCY);
for(count = 1; ;count++)
{
rcvid = MsgReceivePulse (chid, (void *) &pulse, sizeof(pulse), NULL);
printf("%d - ", count);
GotAPulse();
}
/* Never reached */
//Distruggiamo il canale
if(ChannelDestroy(chid) == -1)
{
fprintf(stderr, "%s: couldn't destroy channel. Error: %s\n", progname, strerror(errno));
exit(EXIT_FAILURE);
}
//Distruggiamo il timer
if(timer_delete(t_id) == -1)
{
fprintf(stderr, "%s: couldn't destroy timer. Error: %s\n", progname, strerror(errno));
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
timer_t SetupPulseAndTimer (long freq)
{
timer_t timer_id; //ID del timer
struct sigevent event; //evento da lanciare
struct itimerspec timer; //Struttura dati del timer
int coid; //Connection ID
//Creiamo una connessione
coid = ConnectAttach (0, 0, chid, 0, 0);
if(coid == -1)
{
fprintf(stderr, "%s: couldn't ConnectAttach to self. Error: %s\n", progname, strerror(errno));
exit(EXIT_FAILURE);
}
SIGEV_PULSE_INIT (&event, coid, SIGEV_PULSE_PRIO_INHERIT, CODE_TIMER, 0);
if(timer_create (CLOCK_REALTIME, &event, &timer_id) == -1)
{
fprintf(stderr, "%s: couldn't create timer. Error: %s (%d)\n", progname, strerror(errno), errno);
exit(EXIT_FAILURE);
}
//Impostiamo il timer alla frequenza prestabilita
timer.it_value.tv_sec = 1;
timer.it_value.tv_nsec = 0;
timer.it_interval.tv_sec = 0;
timer.it_interval.tv_nsec = freq;
timer_settime (timer_id, 0, &timer, NULL);
return timer_id;
}
int GotAPulse (void)
{
char buffer[DIM];
FILE * file_p = fopen(file, "r");
if(file_p == NULL)
{
fprintf(stderr, "Unable to open \"%s\". Error: %s\n", file, strerror(errno));
return EXIT_FAILURE;
}
if (fread( buffer, sizeof(buffer), 1, file_p) == 0)
{
fprintf(stderr, "Unable to read from \"%s\". Error: %s\n", file, strerror(errno));
return EXIT_FAILURE;
}
printf("Buffer: %s\n", buffer);
fclose(file_p);
return EXIT_SUCCESS;
}
Tell me what it looks like to you.
Now, how can i check the performance with and without disturbing the application?
System Profiler? If so, what view?
Thanx