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; |
} |
|