Testing calloc performance
This commit is contained in:
parent
b7e1868f24
commit
01d4d93876
@ -1,19 +1,20 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "lxcstat.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "parsing.h"
|
||||
|
||||
int parseLxcConfigFile(lxcinfo *lxc, char *filedata) {
|
||||
lxc->cpucount = 0;
|
||||
lxc->memlimit = 0;
|
||||
|
||||
char *temp = filedata;
|
||||
lxc->cpucount = findAndParseField(&temp, "cores");
|
||||
temp = filedata;
|
||||
|
||||
lxc->memlimit = findAndParseField(&temp, "memory") * 1024 * 1024;
|
||||
temp = filedata;
|
||||
|
||||
lxc->swaplimit = findAndParseField(&temp, "swap") * 1024 * 1024;
|
||||
|
||||
char *ptr = strstr(filedata, "hostname:");
|
||||
ptr += strlen("hostname:");
|
||||
@ -48,7 +49,7 @@ lxcinfo *getLXCInfo(lxcinfo **lxcs, int lxcid) {
|
||||
lxc = lxc->next;
|
||||
}
|
||||
|
||||
lxc = malloc(sizeof(lxcinfo));
|
||||
lxc = calloc(1, sizeof(lxcinfo));
|
||||
lxc->lxcid = lxcid;
|
||||
|
||||
if (readLxcConfig(lxc, lxcid)) {
|
||||
|
||||
@ -8,6 +8,7 @@ typedef struct _lxc_info {
|
||||
int lxcid;
|
||||
int cpucount;
|
||||
int memlimit;
|
||||
int swaplimit;
|
||||
char hostname[128];
|
||||
} lxcinfo;
|
||||
|
||||
|
||||
19
src/server.c
19
src/server.c
@ -61,16 +61,8 @@ int parseStatFile(Process *proc, char *filedata) {
|
||||
proc->cpuTime += fast_str2ull(&location);
|
||||
location += 1;
|
||||
|
||||
// (16) cutime - %lu
|
||||
proc->childCpuTime = fast_str2ull(&location);
|
||||
location += 1;
|
||||
|
||||
// (17) cstime - %lu
|
||||
proc->childCpuTime += fast_str2ull(&location);
|
||||
location += 1;
|
||||
|
||||
// skip 18-19
|
||||
skipRange(18, 20);
|
||||
// skip 16-19
|
||||
skipRange(16, 20);
|
||||
|
||||
// (20) num_threads - %ld
|
||||
proc->nThreads = fast_str2ull(&location);
|
||||
@ -118,9 +110,7 @@ char *readProcesses(char *procdir) {
|
||||
char first;
|
||||
FILE *file;
|
||||
|
||||
Process *cur = malloc(sizeof(Process));
|
||||
cur->prev = NULL;
|
||||
cur->next = NULL;
|
||||
Process *cur = calloc(1, sizeof(Process));
|
||||
Process *head = cur;
|
||||
lxcinfo *lxcs = NULL;
|
||||
|
||||
@ -172,7 +162,7 @@ char *readProcesses(char *procdir) {
|
||||
}
|
||||
|
||||
nextProcess:
|
||||
cur->next = malloc(sizeof(Process));
|
||||
cur->next = calloc(1, sizeof(Process));
|
||||
cur->next->prev = cur;
|
||||
cur = cur->next;
|
||||
}
|
||||
@ -211,6 +201,7 @@ char *readProcesses(char *procdir) {
|
||||
sprintf(buffer, "lxc=\"%d\",lxcname=\"%s\"", lxc->lxcid, lxc->hostname);
|
||||
ptr += sprintf(ptr, "lxc_cpu_core_count{%s} %u\n", buffer, lxc->cpucount);
|
||||
ptr += sprintf(ptr, "lxc_memory_limit_bytes{%s} %llu\n", buffer, lxc->memlimit);
|
||||
ptr += sprintf(ptr, "lxc_swap_limit_bytes{%s} %llu\n", buffer, lxc->swaplimit);
|
||||
// free and proceed
|
||||
lxcinfo *prev = lxc;
|
||||
lxc = lxc->next;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user