Example 4 Code complexity metrics
$ cat /tmp/example.c
#include <stdio.h> #include <pthread.h>
#define INDEX 500
pthread_mutex_t mutex;
int mata[INDEX][INDEX], matb[INDEX][INDEX], matres[INDEX][INDEX] ; void print_output();
void matrix_multiply() { int i, j, k ;
/*
for (k = 0 ; k < INDEX ; k++) { for (j = 0 ; j < INDEX ; j++) {
matres[i][j] = matres[i][j] +
mata[i][k] * matb[k][j] ;
}
}
}
print_output(); /* print the result of multiplication */ return;
}
$ cadvise +metrics aCC
$ cat example.metrics
=======================================================================
Begin program complexity data for /tmp/example.c
=======================================================================
File level program complexity data :
Include Files: 2
Total Lines: 23
Blank Lines: 3
Comment Lines: 1
Lines Of Code: 19
Mixed Lines: 1
No. of Globals: 4
No. of Statics: 0
No. of Functions: 1
No. of ExternFunctions: 1
No. of Global Thread Local Variables: 0
No. of Static Thread Local Variables: 0
No. of Global Mutexes: 1
No. of Static Mutexes: 0
Function level program complexity data :
Begin Function: matrix_multiply
Signature: void matrix_multiply()
Total Lines: 15
Blank Lines: 1
Comment Lines: 1
Lines of Code: 13
Mixed Lines: 1
16 Using Cadvise