Changeset 7bb7dda
- Timestamp:
- 04/11/05 12:52:37 (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:
- 808a478
- Parents:
- be02abd
- Location:
- lib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/libtrace.h
r3cfa94a r7bb7dda 460 460 * TRACE_EVENT_SLEEP Next event in <seconds> 461 461 * TRACE_EVENT_PACKET Packet arrived in <buffer> with size <size> 462 * TRACE_EVENT_TERMINATE Trace terminated (perhaps with an error condition) 462 463 */ 463 464 struct libtrace_eventobj_t trace_event(struct libtrace_t *trace, -
lib/trace.c
r3cfa94a r7bb7dda 167 167 int size; 168 168 } packet; 169 double tdelta; 170 double trace_start_ts; 171 double real_start_ts; 172 double trace_last_ts; 173 169 174 double last_ts; 170 175 double start_ts; 171 struct timeval start_tv;172 176 }; 173 177 … … 202 206 } 203 207 strncpy(scan,uri, (uridata - uri)); 208 209 (*libtrace)->tdelta = 0.0; 204 210 205 211 if (!strncasecmp(scan,"erf",3)) { … … 1448 1454 * TRACE_EVENT_SLEEP Next event in seconds 1449 1455 * TRACE_EVENT_PACKET Packet arrived in buffer with size size 1456 * TRACE_EVENT_TERMINATE Trace terminated (perhaps with an error condition) 1450 1457 * FIXME currently keeps a copy of the packet inside the trace pointer, 1451 1458 * which in turn is stored inside the new packet object... … … 1478 1485 if (data>0) { 1479 1486 event.size = trace_read_packet(trace,packet); 1480 if (event.size < 0) {1481 event.type = TRACE_EVENT_TERMINATE;1482 return event;1483 }1484 1487 event.type = TRACE_EVENT_PACKET; 1485 1488 return event; … … 1500 1503 if (data>0) { 1501 1504 event.size = trace_read_packet(trace,packet); 1502 if (event.size < 0) {1503 event.type = TRACE_EVENT_TERMINATE;1504 return event;1505 }1506 1505 event.type = TRACE_EVENT_PACKET; 1507 1506 return event; … … 1521 1520 trace->packet.size= 1522 1521 trace_read_packet(trace,packet); 1522 event.size = trace->packet.size; 1523 1523 if (trace->packet.size > 0 ) { 1524 1524 memcpy(trace->packet.buffer,packet->buffer,trace->packet.size); 1525 } else { 1526 // return here, the test for event.size will sort out the error 1527 event.type = TRACE_EVENT_PACKET; 1528 return event; 1525 1529 } 1526 1530 } 1527 event.size = trace->packet.size;1528 1529 if (event.size == 0) {1530 event.type = TRACE_EVENT_TERMINATE;1531 return event;1532 }1533 1531 1534 1532 ts=trace_get_seconds(packet); 1535 if (trace-> last_ts!=0) {1536 event.seconds = ts - trace->last_ts;1533 if (trace->tdelta!=0) { 1534 // Get the adjusted current time 1537 1535 gettimeofday(&stv, NULL); 1538 1536 now = stv.tv_sec + ((double)stv.tv_usec / 1000000.0); 1537 now -= trace->tdelta; // adjust for trace delta 1539 1538 1540 if (event.seconds > (now - trace->start_ts)) { 1539 1540 // if the trace timestamp is still in the future, 1541 // return a SLEEP event, otherwise fire the packet 1542 if (ts > now) { 1543 event.seconds = ts - trace->trace_last_ts; 1541 1544 event.type = TRACE_EVENT_SLEEP; 1542 1545 return event; 1543 1546 } 1544 1545 } 1546 else { 1547 } else { 1547 1548 gettimeofday(&stv, NULL); 1548 trace->start_ts = stv.tv_sec + ((double)stv.tv_usec / 1000000.0); 1549 trace->last_ts = ts; 1549 // work out the difference between the start of trace replay, 1550 // and the first packet in the trace 1551 trace->tdelta = stv.tv_sec + ((double)stv.tv_usec / 1000000.0); 1552 trace->tdelta -= ts; 1553 1550 1554 } 1551 1555 1556 // This is the first packet, so just fire away. 1552 1557 packet->size = trace->packet.size; 1553 1558 memcpy(packet->buffer,trace->packet.buffer,trace->packet.size); … … 1557 1562 event.type = TRACE_EVENT_PACKET; 1558 1563 1559 gettimeofday(&stv, NULL); 1560 trace->start_ts = stv.tv_sec + ((double)stv.tv_usec / 1000000.0); 1561 trace->last_ts = ts; 1562 1564 trace->trace_last_ts = ts; 1565 1563 1566 return event; 1564 1567 }
Note: See TracChangeset
for help on using the changeset viewer.