38,11 → 38,11 |
*/ |
|
/* |
* CVS : $Id: trace.c,v 1.1.1.1 2002-03-29 14:12:52 pj Exp $ |
* CVS : $Id: trace.c,v 1.2 2002-10-21 10:13:56 pj Exp $ |
* |
* File: $File$ |
* Revision: $Revision: 1.1.1.1 $ |
* Last update: $Date: 2002-03-29 14:12:52 $ |
* Revision: $Revision: 1.2 $ |
* Last update: $Date: 2002-10-21 10:13:56 $ |
*/ |
|
#include <ll/sys/types.h> |
58,6 → 58,7 |
|
#include <bits/limits.h> |
|
/* maximum number of different queues where we want to log our events */ |
#define TRC_MAXQUEUES 5 |
|
/* |
64,8 → 65,11 |
* |
*/ |
|
/* this is the base path that is used as a prologue for all the |
filenames that are passed to the tracer */ |
static char basepath[PATH_MAX]; |
|
/* used to create the name for a tracer file */ |
void trc_create_name(char *basename, int uniq, char *pathname) |
{ |
if (uniq) sprintf(pathname,"%s/%s%i",basepath,basename,uniq); |
76,27 → 80,42 |
* |
*/ |
|
/* the flag used to discriminate if an event have to be traced or not */ |
#define FLAG_NOTRACE 0x01 |
|
typedef struct TAGtrc_evtinfo_t { |
trc_queue_t *queue; |
unsigned flags; |
trc_queue_t *queue; /* the queue responsible for the logging of an event */ |
unsigned flags; /* if = FLAG_NOTRACE the event must not be logged */ |
} trc_evtinfo_t; |
|
/* -- */ |
|
/* one entry for each event; this array says for each event the queue to use |
and if it must be logged */ |
trc_evtinfo_t eventstable[TRC_NUMEVENTS]; |
|
/* For each kind of queue (see include/tracer/queues.h) there is a set of |
pointers to the functions that a queue should implement */ |
int (*createqueue[TRC_QUEUETYPESNUMBER])(trc_queue_t *, void *); |
int (*activatequeue[TRC_QUEUETYPESNUMBER])(void *,int); |
int (*terminatequeue[TRC_QUEUETYPESNUMBER])(void *); |
|
/* for each queue registered in the system, |
the functions used to get/post an event |
The elements of this table are initialized with calls to createqueue[type]() |
(see include/trace/queues.h) */ |
trc_queue_t queuetable[TRC_MAXQUEUES]; |
|
/* initialized as a dummy queue, the default value of all the queues */ |
trc_queue_t queuesink; |
|
/* number of registered queues in the system */ |
int numqueues; |
|
/* -- */ |
|
/* The Dummy queue */ |
|
static trc_event_t *dummy_get(void *foo) |
{ |
return NULL; |
127,6 → 146,8 |
|
/* -- */ |
|
/* this function simply register the functions that are used to |
handle a queue */ |
int trc_register_queuetype(int queuetype, |
int(*creat)(trc_queue_t *, void *), |
int(*activate)(void *,int), |
139,6 → 160,11 |
return 0; |
} |
|
/* this function register a queue in the system. |
It uses the type to access to the queue handling functions registered |
with the previous function (trc_register_queuetype) |
numqueue is incremented! |
*/ |
int trc_create_queue(int queuetype, void *args) |
{ |
int res; |
186,20 → 212,28 |
|
printk(KERN_INFO "initializing tracer..."); |
|
/* all the queues are initialized to the dummy queue (sink!) */ |
for (i=0;i<TRC_QUEUETYPESNUMBER;i++) { |
createqueue[i]=dummy_createqueue; |
terminatequeue[i]=dummy_terminatequeue; |
} |
|
/* the sink queue is initialized */ |
dummy_createqueue(&queuesink,NULL); |
|
/* no queues registered yet */ |
numqueues=0; |
|
/* all the events are initialized to put to the sink queue */ |
for (i=0;i<TRC_NUMEVENTS;i++) { |
eventstable[i].queue=&queuesink; |
eventstable[i].flags=FLAG_NOTRACE; |
} |
|
/* this will end the tracer at shutdown */ |
i=sys_atrunlevel(trc_end,NULL,RUNLEVEL_SHUTDOWN); |
|
/* initialize the parameters if not initialized */ |
{ |
TRC_PARMS m; |
trc_default_parms(m); |
212,10 → 246,13 |
trc_suspend=internal_trc_suspend; |
trc_resume=internal_trc_resume; |
|
/* start the tracer */ |
trc_resume(); |
return 0; |
} |
|
/* this function simply activates all the registered queues. |
This is usually called into the init() tasks!!! */ |
int TRC_init_phase2(void) |
{ |
int i; |
224,6 → 261,8 |
return 0; |
} |
|
/* saves the current logevent function and set it as |
the internal_trc_logevent */ |
static int internal_trc_resume(void) |
{ |
SYS_FLAGS f; |
238,6 → 277,8 |
return ret; |
} |
|
/* restores the saved logevent function (initially, the logevent function is |
a dummy function) */ |
static int internal_trc_suspend(void) |
{ |
SYS_FLAGS f; |
258,8 → 299,10 |
trc_queue_t *queue; |
SYS_FLAGS f; |
|
/* disables interrupts (this function can be called also into a task */ |
f=kern_fsave(); |
|
/* check if the event has to be logged */ |
if (eventstable[event].flags&FLAG_NOTRACE) { |
kern_frestore(f); |
return; |
266,6 → 309,7 |
} |
queue=eventstable[event].queue; |
|
/* gets a free event descriptor, fills it and post it */ |
evt=queue->get(queue->data); |
if (evt!=NULL) { |
evt->event=event; |
283,6 → 327,10 |
* |
*/ |
|
/* these set of functions can be used to trace or not single event and classes. |
They make use of the classtable structure, that is used to discriminate |
the indexes occupied by every class */ |
|
int classtable[TRC_NUMCLASSES+1]={ |
TRC_F_TRACER, |
TRC_F_SYSTEM, |
353,21 → 401,29 |
{ |
int qf,qc; |
int res; |
|
|
/* initialize the trace */ |
res=TRC_init_phase1(NULL); |
if (res) return res; |
|
/* register two kinds of queues, fixed and circular */ |
res=trc_register_circular_queue(); |
if (res) return res; |
res=trc_register_fixed_queue(); |
if (res) return res; |
|
/* creates two queues: |
a circular queue for the system events, |
a fixed queue |
*/ |
qc=trc_create_queue(TRC_CIRCULAR_QUEUE,NULL); |
qf=trc_create_queue(TRC_FIXED_QUEUE,NULL); |
if (qc==-1||qf==-1) return -97; |
|
/* We want to trace all the system events */ |
res=trc_trace_class(TRC_CLASS_SYSTEM); |
if (res) return res; |
/* All the system events must be traced into the circular queue */ |
res=trc_assign_class_to_queue(TRC_CLASS_SYSTEM,qc); |
if (res) return res; |
|