#include "sysCallStat.h" extern KRNL_API_STATS API_STATS[sysCallMax]; /* "enc", "-pbkdf2 -aes-256-cbc -in plain.txt -out cipher.enc -kfile keyfile.key" */ void clearSysTableData() { int i=0; for (; i< sysCallMax; i++) { API_STATS[i].execTimeUsec=0; API_STATS[i].sysCallCount=0; } } void sysCallMeasurementTask(const char* cmd, const char* arg) { measurementFlag = 1; shellCmdExec (cmd, arg); measurementFlag=0; semBGive(sysCallSemID); measurementFlag = 0; displayStats(); } void CaptureSysCallMetrics(const char* cmd, const char* arg) { tsFreq = sysTimestampFreq(); /*Set this once during init and neednot set during every system call execution.*/ sysCallSemID = semBCreate(SEM_Q_FIFO,SEM_EMPTY); if(!sysCallSemID) { printf("CaptureSysCallMetrics: Failed to create semaphore\n"); return ; } clearSysTableData(); sysCallTaskID= taskSpawn("tSysCallMeasure", 50, /* priority */ 0, /* options */ 8192, /* stack */ (FUNCPTR)sysCallMeasurementTask, cmd, arg,0,0,0,0,0,0,0,0); if(sysCallTaskID == ERROR) /*This is to avoid parent task in block state if taskSpawn fails to create a task.*/ { printf("CaptureSysCallMetrics: Failed to create a task\n"); return ; } semBTake(sysCallSemID, WAIT_FOREVER); /*As we crated semaphore with SEM_EMPTY, so it is unavilable and gets blocked here for parent and gets unblcoked when child executes semGive().*/ semDelete(sysCallSemID); } void displayStats() { printf("------------------------------------------------------------------\n"); printf("%-15s %-15s %-15s %-20s\n","crypto cmd","system call","Invocations","Total time (USec)"); printf("------------------------------------------------------------------\n"); printf("%-15s %-15s %-15d %-20lu\n","enc","open",API_STATS[openCall].sysCallCount,API_STATS[openCall].execTimeUsec); printf("%-15s %-15s %-15d %-20lu\n","enc","close",API_STATS[closeCall].sysCallCount,API_STATS[closeCall].execTimeUsec); printf("%-15s %-15s %-15d %-20lu\n","enc","read",API_STATS[readCall].sysCallCount,API_STATS[readCall].execTimeUsec ); printf("%-15s %-15s %-15d %-20lu\n","enc","write",API_STATS[writeCall].sysCallCount,API_STATS[writeCall].execTimeUsec); printf("-------------------------------------------------------------------\n"); }