Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fetch proc info

  • Loading branch information...
commit abad91a8c64b9dd37accd0dfa8097ac7b6c8b111 1 parent 04f7f91
Further Lee authored
Showing with 67 additions and 12 deletions.
  1. +33 −1 cmrecorder.c
  2. +1 −1  cmrecorder.h
  3. +33 −10 main.c
34 cmrecorder.c
View
@@ -1,7 +1,39 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/sysinfo.h>
#include "cmrecorder.h"
-int start_record(struct record_param* param){
+struct{
+ FILE* logger;
+ unsigned long total_mem;
+
+}env;
+
+static void setup_logger(const char* path){
+ env.logger = fopen(path, "w");
+ struct sysinfo si;
+ sysinfo(&si);
+ env.total_mem = si.totalram;
+}
+static void output_overall_info(){
// TODO
+}
+
+static void output_one_result(unsigned long mem, double cpu){
+ // TODO
+}
+
+static void close_logger(){
+ fclose(env.logger);
+}
+
+int start_record(struct record_param* param){
+
+ setup_logger(param->output_path);
+ output_overall_info();
+ // TODO
+
+ close_logger();
return 0;
}
2  cmrecorder.h
View
@@ -4,7 +4,7 @@
struct record_param{
double record_interval;
double total_time;
- int* pids;
+ unsigned long* pids;
int pid_num;
char* output_path;
};
43 main.c
View
@@ -2,10 +2,14 @@
#include <stdlib.h>
#include <ctype.h>
#include <unistd.h>
+#include <string.h>
#include "cmrecorder.h"
+#define MAX_PIDS 32
+
static char* version = "CPU Memory Recorder 0.1";
static char* license = "GPL2";
+static struct record_param* global_param = NULL;
static void usage(){
printf("%s\n%s\n"
@@ -22,39 +26,58 @@ static void usage(){
}
static int set_interval(const char* opt){
- // TODO
- return 1;
+ global_param->record_interval = atof(opt);
+ if (global_param->record_interval > 0.0)
+ return 1;
+ else
+ return 0;
}
static int set_time(const char* opt){
- // TODO
- return 1;
+ global_param->total_time = atof(opt);
+ if (global_param->total_time > 0.0)
+ return 1;
+ else
+ return 0;
}
-static int set_output(const char* opt){
- // TODO
+static int set_output(char* opt){
+ global_param->output_path = opt;
return 1;
}
static int set_pids_by_command(const char* opt){
- // TODO
+ char line[512];
+ char cmd[512];
+ sprintf(cmd, "pidof %s", opt);
+ FILE *fd = popen(cmd, "r");
+ fgets(line, 512, fd);
+ char *p;
+ for (p = strtok(line, " "); p != NULL; p = strtok(NULL, " "))
+ global_param->pids[global_param->pid_num++] = strtoul(p, NULL, 10);
+ pclose(fd);
return 1;
}
-static int set_pids(const char* opt){
- // TODO
+static int set_pids(char* opt){
+ char* p;
+ for (p = strtok(opt, "."); p != NULL; p = strtok(NULL, "."))
+ global_param->pids[global_param->pid_num++] = strtoul(p, NULL, 10);
+
return 1;
}
-static struct record_param* global_param = NULL;
static void global_init(){
global_param = (struct record_param*)malloc(sizeof(struct record_param));
global_param->total_time = -1;
+ global_param->pids = (unsigned long *)malloc(MAX_PIDS*sizeof(unsigned long));
+ global_param->pid_num = 0;
// TODO register signal
}
static void global_deinit(){
+ free(global_param->pids);
free(global_param);
}
Please sign in to comment.
Something went wrong with that request. Please try again.