diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..49fbbbe --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ + +CC = gcc +OUT_DIR = ./build +TARGET = proxmon +SRC_DIRS = ./src + +# Collect all C source files in the current directory +SRCS := $(shell find $(SRC_DIRS) -name '*.c') + +# Generate object files in the build directory +OBJS := $(patsubst $(SRC_DIRS)/%.c, $(OUT_DIR)/%.o, $(SRCS)) + +INC_DIRS := /usr/src/linux-headers-$(uname -r)/include +INC_DIRS := $(shell find $(SRC_DIRS) -type d) $(INC_DIRS) +INC_FLAGS := $(addprefix -I,$(INC_DIRS)) + +CCFLAGS := $(INC_FLAGS) + +$(OUT_DIR): + @mkdir -p $@ + +$(OUT_DIR)/%.o: $(SRC_DIRS)/%.c | $(OUT_DIR) + $(CC) $(CCFLAGS) -c $< -o $@ + +$(TARGET): $(OBJS) + $(CC) $(CCFLAGS) $(OBJS) -o $@ + +.PHONY: all clean +all: $(TARGET) + +clean: + @rm -rf $(TARGET) $(OUT_DIR) + diff --git a/proxmon b/proxmon new file mode 100755 index 0000000..b34e291 Binary files /dev/null and b/proxmon differ diff --git a/src/exampledir.c b/src/exampledir.c deleted file mode 100644 index 1e4091e..0000000 --- a/src/exampledir.c +++ /dev/null @@ -1,33 +0,0 @@ -#include -#include - -int main(int argc, char *argv[]) { - struct dirent *pDirent; - DIR *pDir; - - // Ensure correct argument count. - - if (argc != 2) { - printf("Usage: testprog \n"); - return 1; - } - - // Ensure we can open directory. - - pDir = opendir(argv[1]); - if (pDir == NULL) { - printf("Cannot open directory '%s'\n", argv[1]); - return 1; - } - - // Process each entry. - - while ((pDirent = readdir(pDir)) != NULL) { - printf("[%s]\n", pDirent->d_name); - } - - // Close directory and exit. - - closedir(pDir); - return 0; -} \ No newline at end of file diff --git a/src/proxmon.c b/src/proxmon.c index cea025b..36017ad 100644 --- a/src/proxmon.c +++ b/src/proxmon.c @@ -2,11 +2,11 @@ #include #include -int main(int argc, char *argv[]) { +int main3(int argc, char *argv[]) { DIR *procdir = opendir("/proc"); struct dirent *pDirent; while ((pDirent = readdir(procdir)) != NULL) { printf("[%s]\n", pDirent->d_name); } -} \ No newline at end of file +} diff --git a/src/server.c b/src/server.c index d84b11d..4b2d939 100644 --- a/src/server.c +++ b/src/server.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "process.h" static inline uint64_t fast_str2ull(char** str) { @@ -71,13 +72,14 @@ int parseStatFile(Process *proc, char *filedata) { location = strchr(location, ' ') + 1; // skip [7 - 14) - skipRange(7, 9); + skipRange(7,14); + //skipRange(7, 9); // (9) flags - %u - proc->iskernel = fast_str2ull(&location) & PS_KTHREAD; - location += 1; + //proc->iskernel = fast_str2ull(&location) & PF_KTHREAD; + //location += 1; - skipRange(10, 14); + //skipRange(10, 14); // (14) utime - %lu proc->cpuTime = fast_str2ull(&location); @@ -172,7 +174,10 @@ int main(int argc, char *argv[]) { cur = head; while (cur != NULL) { printf("proc_cpu_time{pid=\"%d\",ppid=\"%d\",label=\"%s\"} %d\n", cur->pid, cur->ppid, cur->label, cur->cpuTime); - cur = cur->next; + printf("proc_child_cpu_time{pid=\"%d\",ppid=\"%d\",label=\"%s\"} %d\n", cur->pid, cur->ppid, cur->label, cur->childCpuTime / clocks); + printf("proc_num_threads{pid=\"%d\",ppid=\"%d\",label=\"%s\"} %d\n", cur->pid, cur->ppid, cur->label, cur->nThreads); + printf("proc_resident_bytes{pid=\"%d\",ppid=\"%d\",label=\"%s\"} %d\n", cur->pid, cur->ppid, cur->label, cur->resident); + cur = cur->next; } // Close directory and exit.