c - How to check performance of a function in kernel -


i trying understand , use existing utilities or programmable snippets allow measure cpu utilization/performance in terms of power consumption, cpu cycles of function in kernel space.

i have 2 function snippets same work:

convert ip address string.

char* inet_ntoa(struct in_addr in, char* buf, size_t* rlen) {          int i;         char* bp;          bp = buf;         (i = 0;i < 4; i++ ) {                 unsigned int o, n;                 o = ((unsigned char*)&in)[i];                 n = o;                 if ( n >= 200 ) {                         *bp++ = '2';                         n -= 200;                 }else if ( n >= 100 ) {                         *bp++ = '1';                         n -= 100;                 }                 if ( o >= 10 ) {                         int i;                         ( = 0; n >= 10; i++ ) {                                 n -= 10;                         }                         *bp++ = + '0';                 }                 *bp++ = n + '0';                 *bp++ = '.';         }         *--bp = 0;         if ( rlen ) {                 *rlen = bp - buf;         }          return buf; } 

and

char *inet_ntoa (struct in_addr in)     {       unsigned char *bytes = (unsigned char *) &in;       __snprintf (buffer, sizeof (buffer), "%d.%d.%d.%d",               bytes[0], bytes[1], bytes[2], bytes[3]);        return buffer;     } 

the later function glibc. former 1 own.

the 2 function called in kernel space. how can measure there performance compare.

my machine ubuntu 14.04 x86 i686. linux kernel 3.13

i installed perf source linux/tools.

i have module running. how can hook perf measure functions performance.

kindly suggest.

you might interested this paper intel engineer.
explains how accurately time code cpu timer.

don't forget time wide range of inputs. might want take account potential difference in robustness (how code behave wrong inputs).


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -