Changeset d97865b
- Timestamp:
- 04/11/05 12:00:19 (16 years ago)
- Branches:
- 4.0.1-hotfixes, cachetimestamps, develop, dpdk-ndag, etsilive, getfragoff, help, libtrace4, master, ndag_format, pfring, rc-4.0.1, rc-4.0.2, rc-4.0.3, rc-4.0.4, ringdecrementfix, ringperformance, ringtimestampfixes
- Children:
- be02abd
- Parents:
- 001fbb6
- Location:
- examples/event
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
examples/event/Makefile
r001fbb6 rd97865b 9 9 LDLIBS = $(libdir) -lpcap -lz 10 10 11 BINS = rate 11 BINS = rate rate-tracetime 12 12 .PHONY: all clean distclean install depend 13 13 … … 15 15 16 16 rate: rate.c ../../lib/.libs/libtrace.a 17 18 rate-tracetime: rate-tracetime.c ../../lib/.libs/libtrace.a 17 19 18 20 clean: -
examples/event/rate.c
r001fbb6 rd97865b 70 70 int32_t counter[MAXCOUNTERTYPE][MAXCOUNTERFRAME]; 71 71 72 int32_t event_read_packet(struct libtrace_t *trace, struct libtrace_packet_t *packet); 73 72 74 struct timeval current,last,diff,total; 73 75 … … 104 106 struct libtrace_ip *ipptr = 0; 105 107 struct libtrace_packet_t packet; 106 struct libtrace_eventobj_t obj;107 108 108 109 struct itimerval itv; 109 struct timeval etv;110 uint32_t sleepsec = 0;111 fd_set rfds;112 113 FD_ZERO(&rfds);114 110 115 111 /* … … 141 137 142 138 for (;;) { 143 obj = trace_event(trace,&packet); 144 // printf("event.type = %d\n",obj.type); 145 146 if (obj.type == TRACE_EVENT_TERMINATE) { 139 if ((psize = event_read_packet(trace,&packet)) < 0) { 147 140 break; 148 141 } 149 150 if (obj.type == TRACE_EVENT_IOWAIT) { 151 // sleep on fd 152 FD_ZERO(&rfds); 153 FD_SET(obj.fd,&rfds); 154 select(obj.fd + 1, &rfds,NULL,NULL,0); 142 if (psize == 0) { 155 143 continue; 156 } else if (obj.type == TRACE_EVENT_SLEEP) {157 // sleep on seconds158 //159 etv.tv_sec = (int) obj.seconds;160 etv.tv_usec = (int) (obj.seconds - etv.tv_sec) * 1000000;161 162 /* printf("waiting for %ld.%ld (%f)usec\n",163 etv.tv_sec,164 etv.tv_usec,165 obj.seconds);166 */167 select(0,NULL,NULL,NULL,&etv);168 continue;169 170 171 172 173 } else if (obj.type == TRACE_EVENT_PACKET) {174 if (packet.size < 0) {175 break;176 } else if (packet.size == 0) {177 continue;178 }179 } else {180 fprintf(stderr,"Unknown event type %d\n",obj.type);181 break;182 144 } 183 //printf("packet.size = %d\n",packet.size);184 //printf("foo\n");185 145 186 146 if((ipptr = trace_get_ip(&packet)) == 0) { … … 201 161 return 0; 202 162 } 163 164 165 int32_t event_read_packet(struct libtrace_t *trace, struct libtrace_packet_t *packet) { 166 struct libtrace_eventobj_t obj; 167 struct timeval etv; 168 int32_t sleepusec = 0; 169 fd_set rfds; 170 171 FD_ZERO(&rfds); 172 173 for (;;) { 174 obj = trace_event(trace,packet); 175 if (obj.size <= 0) { 176 return obj.size; 177 } 178 if (obj.type == TRACE_EVENT_IOWAIT) { 179 // select() on fd 180 FD_ZERO(&rfds); 181 FD_SET(obj.fd,&rfds); 182 select(obj.fd + 1, &rfds,NULL,NULL,0); 183 continue; 184 } else if (obj.type == TRACE_EVENT_SLEEP) { 185 // sleep on seconds 186 // Use select for better precision. 187 etv.tv_sec = (int) obj.seconds; 188 etv.tv_usec = (int) ((obj.seconds - etv.tv_sec) * 1000000.0); 189 select(0,NULL,NULL,NULL,&etv); 190 continue; 191 } else if (obj.type == TRACE_EVENT_PACKET) { 192 return packet->size; 193 } else { 194 fprintf(stderr,"Unknown event type %d\n",obj.type); 195 return -1; 196 } 197 } 198 199 }
Note: See TracChangeset
for help on using the changeset viewer.