Changeset edca0b8 for examples


Ignore:
Timestamp:
10/31/05 16:31:01 (15 years ago)
Author:
Perry Lorier <perry@…>
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:
fd9d44c
Parents:
f20b30e
Message:

Updated tracemark to show cpu used

Location:
examples/tracemark
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • examples/tracemark/Makefile

    rc9caf07 redca0b8  
    44
    55INCLUDE = -I$(PREFIX)/include
    6 CFLAGS = -Wall -Wimplicit -Wformat -pipe -g -O2
     6CFLAGS = -Wall -Wimplicit -W -Wformat -pipe -g -Os
    77CFLAGS += $(INCLUDE)
    88libdir = -L$(PREFIX)/lib
  • examples/tracemark/tracemark.c

    rc9caf07 redca0b8  
    4646#include <getopt.h>
    4747#include <inttypes.h>
     48#include <sys/resource.h>
     49#include <unistd.h>
    4850
    4951#include "libtrace.h"
     
    8688}
    8789
     90#define TIMER_SUB(res,a,b)                              \
     91        do {                                            \
     92                res.tv_sec = a.tv_sec - b.tv_sec;       \
     93                res.tv_usec = a.tv_usec - b.tv_usec;    \
     94                if (res.tv_usec < 0) {                  \
     95                        --res.tv_sec;                   \
     96                        res.tv_usec += 1000000;         \
     97                }                                       \
     98        } while(0)
     99
    88100int main(int argc, char *argv[]) {
    89101
     
    91103        struct timeval start,end;
    92104        struct timeval interval;
     105        struct rusage start_usage,end_usage;
    93106
     107        getrusage(RUSAGE_SELF,&start_usage);
    94108        gettimeofday(&start,NULL);
    95109        for(i=optind;i<argc;++i) {
     
    97111        }
    98112        gettimeofday(&end,NULL);
    99         interval.tv_sec = end.tv_sec - start.tv_sec;                             
    100         interval.tv_usec = end.tv_usec - start.tv_usec;     
    101         if (interval.tv_usec < 0) {                         
    102                 --interval.tv_sec;                         
    103                 interval.tv_usec += 1000000;     
    104         }                                                 
     113        getrusage(RUSAGE_SELF,&end_usage);
     114
     115        TIMER_SUB(interval,end,start);
    105116
    106117        printf("Tracemarks: %.02f\n",((double)tot)/(interval.tv_sec+interval.tv_usec/100000));
     118
     119        printf("Real: %i.%05is\n",interval.tv_sec,interval.tv_usec);
     120        TIMER_SUB(interval,end_usage.ru_utime,start_usage.ru_utime);
     121        printf("User: %i.%05is\n",interval.tv_sec,interval.tv_usec);
     122        TIMER_SUB(interval,end_usage.ru_stime,start_usage.ru_stime);
     123        printf("System: %i.%06is\n",interval.tv_sec,interval.tv_usec);
     124        printf("I/O: %li/%li\n",end_usage.ru_inblock-start_usage.ru_inblock,
     125                                end_usage.ru_oublock-start_usage.ru_oublock);
    107126        return 0;
    108127}
Note: See TracChangeset for help on using the changeset viewer.