Ignore:
Timestamp:
10/12/05 16:05:46 (16 years ago)
Author:
Daniel Lawson <dlawson@…>
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:
2e22a5df
Parents:
eaa5529
Message:

uses tracetime, not clocktime

File:
1 edited

Legend:

Unmodified
Added
Removed
  • examples/rate/rate-dir.c

    r5c88a60 r2cc187b  
    4747struct libtrace_t *trace;
    4848
    49 #define SCANSIZE 4096
    50 
    5149#define ALPHA 0.9
    52 
    53 char *buffer[SCANSIZE];
    5450
    5551static int docalc = 0;
     
    7975struct timeval current,last,diff,total;
    8076
    81 void alarmsig(int sig) {
    82         docalc++;
    83 }
    8477
    8578static int32_t smoothed(int32_t smoothed, int32_t instant, int32_t alpha) {
     
    123116        int psize = 0;
    124117        int direction = 0;
    125         struct sigaction sigact;
    126118        struct libtrace_ip *ipptr = 0;
    127119        struct libtrace_packet_t packet;
    128 
    129         struct itimerval itv;
    130 
    131         /*
    132          * Set up a timer to expire every second, for reporting
    133          */
    134         sigact.sa_handler = alarmsig;
    135         sigact.sa_flags = SA_RESTART;
    136         if(sigaction(SIGALRM, &sigact, NULL) < 0)
    137                 perror("sigaction");
    138         itv.it_interval.tv_sec = 1;
    139         itv.it_interval.tv_usec = 0;
    140         itv.it_value.tv_sec = 1;
    141         itv.it_value.tv_usec = 0;
    142         if (setitimer(ITIMER_REAL, &itv, NULL) < 0)
    143                 perror("setitimer");
    144 
    145         if (argc == 2) {
     120       
     121        uint32_t last_second = 0;
     122        double ts = 0.0;
     123       
     124        if (argc == 2) {
    146125                uri = strdup(argv[1]);
    147126        }
     
    169148                counter[direction][PACKETS][INSTANT] ++;
    170149
     150                ts = trace_get_seconds(&packet);
     151                if(last_second == 0) {
     152                        last_second = (int)ts;
     153                } else if (last_second < (int)ts) {
     154                        last_second = (int)ts;
     155                        docalc++;
     156                }
     157
    171158                if(docalc) {
    172159                        secondreport();
Note: See TracChangeset for help on using the changeset viewer.