Blame |
Last modification |
View Log
| RSS feed
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include "types.h"
#include <trace.h>
#include <types.h>
static char *names
[]={
"reserved",
"hoops",
/*--*/
"create",
"activate",
"schedule",
"delay",
"sleep",
"endcycle",
"destroy",
"intactiv",
/*--*/
"user0",
"user1",
"user2",
"user3",
"user4",
"user5",
"user6",
"user7",
/*--*/
"wait",
"waitnb",
"signal"
};
int classtable
[TRC_NUMCLASSES
+1]={
TRC_F_TRACER
,
TRC_F_SYSTEM
,
TRC_F_USER
,
TRC_F_SEM
,
TRC_F_LAST
};
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
;
return -1;
}
char *event_name
(int ev
)
{
if (ev
<0||ev
>=TRC_NUMEVENTS
) return "unknown";
return names
[ev
];
}
char *event_hexdump
(u_int8_t
*ptr
,int maxsize
)
{
static char buffer
[256];
int i
;
for (i
=0;i
<maxsize
;i
++) sprintf(buffer
+i
*2,"%02x",*(ptr
+i
));
buffer
[maxsize
*2]='\0';
return buffer
;
}
char *event_strdump
(u_int8_t
*ptr
, int maxsize
)
{
static char buffer
[256];
memcpy(buffer
,ptr
,maxsize
);
buffer
[maxsize
]='\0';
return buffer
;
}
char *format_time
(long time)
{
static char buffer
[256];
if (time
<1000l) {
sprintf(buffer
,"%li",time);
return buffer
;
}
if (time
<1000000l) {
sprintf(buffer
,"%li,%03li",time/1000l,time
%1000l
);
return buffer
;
}
sprintf(buffer
,"%li,%03li,%03li",
(time/1000000l),
(time
%1000000l
)/1000l,
time
%1000l
);
return buffer
;
}
#ifndef O_BINARY
#define O_BINARY 0
#endif
int read_trace
(char *filename
,int (*func
)(trc_event_t
*))
{
trc_event_t buffer
;
int fin
;
int res
;
fin
=open
(filename
,O_RDONLY
|O_BINARY
);
if (fin
==-1) return -1;
for (;;) {
res
=read
(fin
,&buffer
,sizeof(trc_event_t
));
if (res
!=sizeof(trc_event_t
)) {
close
(fin
);
return res
==0?0:-2;
}
res
=(*func
)(&buffer
);
if (res
!=0) {
close
(fin
);
return res
;
}
}
close
(fin
);
return 0;
}