|
|
@ -0,0 +1,59 @@ |
|
|
|
#include <stdio.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <assert.h> |
|
|
|
#include <math.h> |
|
|
|
#include <unistd.h> |
|
|
|
#include <string.h> |
|
|
|
#include <sys/time.h> |
|
|
|
#include <sys/types.h> |
|
|
|
|
|
|
|
float exec_cmd(char *cmd) |
|
|
|
{ |
|
|
|
FILE* fp; |
|
|
|
char* command; |
|
|
|
char* line; |
|
|
|
char* result; |
|
|
|
|
|
|
|
line = malloc(200 * sizeof(char)); |
|
|
|
command = malloc(200 * sizeof(char)); |
|
|
|
strcpy(command, cmd); |
|
|
|
|
|
|
|
fp = popen(command,"r"); |
|
|
|
while((fgets(line, 60, fp))) |
|
|
|
{ |
|
|
|
result = line; |
|
|
|
} |
|
|
|
return atof(result); |
|
|
|
} |
|
|
|
|
|
|
|
long long current_timestamp() { |
|
|
|
struct timeval te; |
|
|
|
gettimeofday(&te, NULL); // get current time |
|
|
|
long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000; // calculate milliseconds |
|
|
|
// printf("milliseconds: %lld\n", milliseconds); |
|
|
|
return milliseconds; |
|
|
|
} |
|
|
|
|
|
|
|
float main() |
|
|
|
{ |
|
|
|
float freq = exec_cmd("cat /proc/cpuinfo | grep \"cpu MHz\" | awk '{s+=$4} END {printf \"%0.3f\", s}'"); |
|
|
|
float cpus = exec_cmd("cat /proc/cpuinfo | grep processor | wc -l"); |
|
|
|
float core = exec_cmd("grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {print usage \"\"}'"); |
|
|
|
float ram = exec_cmd("free -mt | grep Total: | awk '{s+=$3} END {printf \"%d\", s}'"); |
|
|
|
float pid = getpid(); |
|
|
|
|
|
|
|
printf("\nRamdy 0.1\n"); |
|
|
|
printf("\n-------------------------\n"); |
|
|
|
printf("\nTimestamp: %lld \nPid: %1.0f \nFreq: %.6f \nCpus: %.6f \nCore: %.6f \n", current_timestamp(), pid, freq, cpus,core); |
|
|
|
printf("\n----------\n"); |
|
|
|
|
|
|
|
float date = (getpid() * current_timestamp()) % 1000; |
|
|
|
int cpu = (int)(freq * ram) % 1000; |
|
|
|
float result = (100 * (date * cpu)) / 998001; |
|
|
|
|
|
|
|
printf("\nDate: %1.0f\n", date); |
|
|
|
printf("\nCpu: %d\n", cpu); |
|
|
|
printf("\nResult: %.6f\n", result); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |