Subversion Repositories shark

Compare Revisions

Ignore whitespace Rev 1095 → Rev 1096

/demos/trunk/tracer/utils/udpdump.c
0,0 → 1,216
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* Massimiliano Giorgi <massy@gandalf.sssup.it>
* Luca Abeni <luca@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Massimiliano Giorgi
* Copyright (C) 2002 Paolo Gai
* Copyright (C) 2002 Tomas Lenvall
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* CVS : $Id: udpdump.c,v 1.1 2002-10-28 08:07:32 pj Exp $
*/
 
/* this example simply prints a Shark trace file */
 
// INCLUDES
#include <netinet/in.h>
#include "types.h"
#include "trace.h"
#include "util.h"
 
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdio.h>
#include <unistd.h>/* close() */
#include <string.h> /* memset() */
#include <stdlib.h>
 
 
// GLOBALS
char server_ipaddr[20]; // Store the IP adress of the server
 
// DEFINES
#define LOCAL_SERVER_PORT 20000
#define MAX_MSG 10000
 
// FUNCTIONS
/* */
int dumpsys(trc_system_event_t *sys)
{
printf("%02i\n",sys->task);
return 0;
}
 
/* */
int dumpusr(trc_user_event_t *usr)
{
printf("%8li ",usr->n);
printf("\n");
return 0;
}
 
/* */
int dumpsem(trc_sem_event_t *sem)
{
printf("on [%i]\n",sem->id);
return 0;
}
 
/* */
int dumpfunc(trc_event_t *ev)
{
static int counter=0;
printf("\t%4i ",counter);
counter++;
printf("%12s ",format_time(ev->time));
printf("%-10s ",event_name(ev->event));
 
//printf("%08x\n",(unsigned)ev->sys.event);
//return 0;
switch(event_class(ev->event)) {
case TRC_CLASS_SYSTEM: return dumpsys(&ev->x.sys);
case TRC_CLASS_USER: return dumpusr(&ev->x.usr);
case TRC_CLASS_SEM: return dumpsem(&ev->x.sem);
}
printf("\nEVENT %i... CLASS %i UNKNOWN!\n",ev->event,event_class(ev->event));
return -1;
}
 
 
/* Use UDP/IP to receive the events from the client computer */
int main(int argc, char *argv[])
{
int sd, rc, n, cliLen;
struct sockaddr_in cliAddr, servAddr;
char msg[MAX_MSG];
 
// socket creation
sd = socket(AF_INET, SOCK_DGRAM, 0);
if(sd < 0) {
printf("%s: cannot open socket \n",argv[0]);
exit(1);
}
 
// bind local server port
servAddr.sin_family = AF_INET;
 
servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
servAddr.sin_port = htons(LOCAL_SERVER_PORT);
 
rc = bind (sd, (struct sockaddr *)&servAddr,sizeof(servAddr));
if(rc < 0) {
printf("%s: cannot bind port number %d \n",
argv[0], LOCAL_SERVER_PORT);
exit(1);
}
 
while(1){
// init buffer
memset(msg, 0x0, MAX_MSG);
 
// receive message
cliLen = sizeof(cliAddr);
n = recvfrom(sd, msg, MAX_MSG, 0,(struct sockaddr *)&cliAddr, &cliLen);
 
printf("Packet received, length %d, %d tracer events.\n", n,
*((short int *)msg));
if(n < 0) {
printf("%s: cannot receive data \n",argv[0]);
continue;
}
// Read the trace we got from the network
read_udp_trace(msg, dumpfunc);
}
 
return 0;
}
 
 
// test main: testing this program from a file (simulating a network package)
// ONLY USED FOR TESTING!!!
 
/*int main(int argc, char *argv[])
{
FILE* fin;
int nr_of_events = 0;
trc_event_t buffer;
char all_events[1000];
char tmpbuf[2];
 
if(argc != 2) {
printf("Missing filename!\n");
return -1;
}
 
// open the file and send event by event
fin = fopen(argv[1], "r");
if (fin == NULL) {
printf("Cannot open file\n");
return -1;
}
// check how many events
while (!feof(fin)) {
fread(&buffer, sizeof(trc_event_t), 1, fin);
nr_of_events++;
}
 
//printf("Nr of events: %d\n", nr_of_events);
 
rewind(fin); // start from the beginning again...
//strncpy(tmpbuf, itoa(nr_of_events), 2);
sprintf(tmpbuf, "%d", nr_of_events);
//printf("tmpbuf: %s\n", tmpbuf);
 
memset(all_events, 0, 1000);
memcpy(all_events, tmpbuf, 2);
printf("all_events(1): %s\n", all_events);
// read all tracer events and store them in an array
fread(all_events + 2, sizeof(trc_event_t), nr_of_events, fin);
fclose(fin);
 
printf("all_events(2): %s\n", all_events);
// send it to the event reader
read_trace(all_events, dumpfunc);
 
return 1;
}
*/
/demos/trunk/tracer/utils/util.h
1,4 → 1,44
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* Massimiliano Giorgi <massy@gandalf.sssup.it>
* Luca Abeni <luca@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Massimiliano Giorgi
* Copyright (C) 2002 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* CVS : $Id: util.h,v 1.2 2002-10-28 08:07:32 pj Exp $
*/
 
#ifndef __UTIL_H
#define __UTIL_H
 
10,6 → 50,7
int event_class(int evt);
 
int read_trace(char *filename,int (*func)(trc_event_t *));
int read_udp_trace(void *msg, int (*func)(trc_event_t *));
 
char *format_time(long time);
 
/demos/trunk/tracer/utils/sa.c
1,4 → 1,43
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* Massimiliano Giorgi <massy@gandalf.sssup.it>
* Luca Abeni <luca@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Massimiliano Giorgi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* CVS : $Id: sa.c,v 1.2 2002-10-28 08:07:32 pj Exp $
*/
 
#include <netinet/in.h>
 
#include <stdlib.h>
/demos/trunk/tracer/utils/wait.c
1,4 → 1,43
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* Massimiliano Giorgi <massy@gandalf.sssup.it>
* Luca Abeni <luca@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Massimiliano Giorgi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* CVS : $Id: wait.c,v 1.2 2002-10-28 08:07:32 pj Exp $
*/
 
#include <stdio.h>
#include <stdlib.h>
#include "types.h"
/demos/trunk/tracer/utils/distr.c
1,4 → 1,43
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* Massimiliano Giorgi <massy@gandalf.sssup.it>
* Luca Abeni <luca@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Massimiliano Giorgi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* CVS : $Id: distr.c,v 1.2 2002-10-28 08:07:32 pj Exp $
*/
 
long t[PREC];
long counter;
long hoops;
/demos/trunk/tracer/utils/road.c
1,4 → 1,43
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* Massimiliano Giorgi <massy@gandalf.sssup.it>
* Luca Abeni <luca@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Massimiliano Giorgi
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* CVS : $Id: road.c,v 1.2 2002-10-28 08:07:32 pj Exp $
*/
 
#include <stdio.h>
#include <stdlib.h>
#include "types.h"
/demos/trunk/tracer/utils/tdump.c
1,4 → 1,44
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* Massimiliano Giorgi <massy@gandalf.sssup.it>
* Luca Abeni <luca@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Massimiliano Giorgi
* Copyright (C) 2002 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* CVS : $Id: tdump.c,v 1.2 2002-10-28 08:07:32 pj Exp $
*/
 
/* this example simply prints a Shark trace file */
 
#include <netinet/in.h>
/demos/trunk/tracer/utils/types.h
1,3 → 1,44
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* Massimiliano Giorgi <massy@gandalf.sssup.it>
* Luca Abeni <luca@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Massimiliano Giorgi
* Copyright (C) 2002 Paolo Gai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* CVS : $Id: types.h,v 1.2 2002-10-28 08:07:32 pj Exp $
*/
 
#ifndef __TYPES_H__
#define __TYPES_H__
 
/demos/trunk/tracer/utils/makefile
11,6 → 11,7
 
all:
@echo Targets: util_dos util_linux clean
@echo Note: udpdump is available only under linux
 
util_dos: tdump.exe jdump.exe sa.exe road.exe wait.exe
 
57,6 → 58,9
gcc -s -Wimplicit-function-declaration -Wall \
-I$(BASE)/include/trace wait.c util.c -o wait
 
udpdump: udpdump.c util.c
gcc -Wimplicit-function-declaration -Wall -ggdb\
-I$(BASE)/include/trace udpdump.c util.c -o udpdump
 
 
 
/demos/trunk/tracer/utils/util.c
1,7 → 1,50
/*
* Project: S.Ha.R.K.
*
* Coordinators:
* Giorgio Buttazzo <giorgio@sssup.it>
* Paolo Gai <pj@gandalf.sssup.it>
*
* Authors :
* Paolo Gai <pj@gandalf.sssup.it>
* Massimiliano Giorgi <massy@gandalf.sssup.it>
* Luca Abeni <luca@gandalf.sssup.it>
* (see the web pages for full authors list)
*
* ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
*
* http://www.sssup.it
* http://retis.sssup.it
* http://shark.sssup.it
*/
 
/*
* Copyright (C) 2000 Massimiliano Giorgi
* Copyright (C) 2002 Paolo Gai
* Copyright (C) 2002 Tomas Lenvall
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* CVS : $Id: util.c,v 1.2 2002-10-28 08:07:32 pj Exp $
*/
 
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
 
#include "types.h"
#include <trace.h>
45,9 → 88,14
int event_class(int ev)
{
int i;
if (ev<0||ev>=TRC_NUMEVENTS) return -1;
for (i=0;i<TRC_NUMCLASSES;i++)
if (ev>=classtable[i]&&ev<classtable[i+1]) return i;
 
if (ev < 0 || ev >= TRC_NUMEVENTS)
return -1;
 
for (i = 0; i < TRC_NUMCLASSES; i++)
if (ev >= classtable[i] && ev < classtable[i+1])
return i;
 
return -1;
}
 
121,3 → 169,34
close(fin);
return 0;
}
 
 
/* reads trace events from a udp message */
int read_udp_trace(char *msg, int (*func)(trc_event_t *))
{
short int events; // temporary storage of nr of events
int res;
 
/* message:
|2 bytes=nr of events|12 bytes=event 0|12 bytes=event 1|...
 
Note: the size of an event depends on the extra informations that
are put on the trc_event_t data structures. That size is
currently 12 bytes, but it can change if additional fields are
added to the trc_event_t structure. Including the
include/trace/types.h header ensures that the size used in this
application is coherent with the size of the compiled Shark
applications...
*/
events = *((short int *)msg);
 
msg += 2; // skip the 2 first bytes
 
for (;
events > 0;
events--, msg += sizeof(trc_event_t))
res = (*func)((trc_event_t *)msg);
 
return 1;
}