Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1085 | pj | 1 | #include <stdio.h> |
2 | #include <fcntl.h> |
||
3 | #include <unistd.h> |
||
4 | |||
5 | #include "types.h" |
||
6 | #include <trace.h> |
||
7 | #include <types.h> |
||
8 | |||
9 | static char *names[]={ |
||
10 | "reserved", |
||
11 | "hoops", |
||
12 | /*--*/ |
||
13 | "create", |
||
14 | "activate", |
||
15 | "schedule", |
||
16 | "delay", |
||
17 | "sleep", |
||
18 | "endcycle", |
||
19 | "destroy", |
||
20 | "intactiv", |
||
21 | /*--*/ |
||
22 | "user0", |
||
23 | "user1", |
||
24 | "user2", |
||
25 | "user3", |
||
26 | "user4", |
||
27 | "user5", |
||
28 | "user6", |
||
29 | "user7", |
||
30 | /*--*/ |
||
31 | "wait", |
||
32 | "waitnb", |
||
33 | "signal" |
||
34 | }; |
||
35 | |||
36 | int classtable[TRC_NUMCLASSES+1]={ |
||
37 | TRC_F_TRACER, |
||
38 | TRC_F_SYSTEM, |
||
39 | TRC_F_USER, |
||
40 | TRC_F_SEM, |
||
41 | TRC_F_LAST |
||
42 | }; |
||
43 | |||
44 | int event_class(int ev) |
||
45 | { |
||
46 | int i; |
||
47 | if (ev<0||ev>=TRC_NUMEVENTS) return -1; |
||
48 | for (i=0;i<TRC_NUMCLASSES;i++) |
||
49 | if (ev>=classtable[i]&&ev<classtable[i+1]) return i; |
||
50 | return -1; |
||
51 | } |
||
52 | |||
53 | char *event_name(int ev) |
||
54 | { |
||
55 | if (ev<0||ev>=TRC_NUMEVENTS) return "unknown"; |
||
56 | return names[ev]; |
||
57 | } |
||
58 | |||
59 | char *event_hexdump(u_int8_t *ptr,int maxsize) |
||
60 | { |
||
61 | static char buffer[256]; |
||
62 | int i; |
||
63 | for (i=0;i<maxsize;i++) sprintf(buffer+i*2,"%02x",*(ptr+i)); |
||
64 | buffer[maxsize*2]='\0'; |
||
65 | return buffer; |
||
66 | } |
||
67 | |||
68 | char *event_strdump(u_int8_t *ptr, int maxsize) |
||
69 | { |
||
70 | static char buffer[256]; |
||
71 | memcpy(buffer,ptr,maxsize); |
||
72 | buffer[maxsize]='\0'; |
||
73 | return buffer; |
||
74 | } |
||
75 | |||
76 | |||
77 | char *format_time(long time) |
||
78 | { |
||
79 | static char buffer[256]; |
||
80 | |||
81 | if (time<1000l) { |
||
82 | sprintf(buffer,"%li",time); |
||
83 | return buffer; |
||
84 | } |
||
85 | if (time<1000000l) { |
||
86 | sprintf(buffer,"%li,%03li",time/1000l,time%1000l); |
||
87 | return buffer; |
||
88 | } |
||
89 | sprintf(buffer,"%li,%03li,%03li", |
||
90 | (time/1000000l), |
||
91 | (time%1000000l)/1000l, |
||
92 | time%1000l); |
||
93 | return buffer; |
||
94 | } |
||
95 | |||
96 | #ifndef O_BINARY |
||
97 | #define O_BINARY 0 |
||
98 | #endif |
||
99 | |||
100 | int read_trace(char *filename,int (*func)(trc_event_t *)) |
||
101 | { |
||
102 | trc_event_t buffer; |
||
103 | int fin; |
||
104 | int res; |
||
105 | |||
106 | fin=open(filename,O_RDONLY|O_BINARY); |
||
107 | if (fin==-1) return -1; |
||
108 | for (;;) { |
||
109 | res=read(fin,&buffer,sizeof(trc_event_t)); |
||
110 | if (res!=sizeof(trc_event_t)) { |
||
111 | close(fin); |
||
112 | return res==0?0:-2; |
||
113 | } |
||
114 | res=(*func)(&buffer); |
||
115 | if (res!=0) { |
||
116 | close(fin); |
||
117 | return res; |
||
118 | } |
||
119 | } |
||
120 | close(fin); |
||
121 | return 0; |
||
122 | } |