X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbootchart%2Flog.c;h=c7973a528502f552b72e6c5e492a70d628ebf22a;hb=cd3bccaaf7b3c0e000cfd1bac638a52cb4f510c3;hp=78f0cab17833c4015f9117bbb67a6caf9fc9c1a6;hpb=ef2648c12793ded136eb81b2482f84027cade614;p=elogind.git diff --git a/src/bootchart/log.c b/src/bootchart/log.c index 78f0cab17..c7973a528 100644 --- a/src/bootchart/log.c +++ b/src/bootchart/log.c @@ -1,16 +1,24 @@ -/* - * log.c - * - * Copyright (C) 2009-2012 Intel Coproration - * - * Authors: - * Auke Kok - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; version 2 - * of the License. - */ +/*** + log.c - This file is part of systemd-bootchart + + Copyright (C) 2009-2013 Intel Coproration + + Authors: + Auke Kok + + systemd is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + systemd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with systemd; If not, see . + ***/ #define _GNU_SOURCE 1 #include @@ -26,6 +34,7 @@ #include "bootchart.h" +#include "util.h" /* * Alloc a static 4k buffer for stdio - primarily used to increase @@ -38,11 +47,11 @@ DIR *proc; double gettime_ns(void) { - struct timespec now; + struct timespec n; - clock_gettime(CLOCK_MONOTONIC, &now); + clock_gettime(CLOCK_MONOTONIC, &n); - return (now.tv_sec + (now.tv_nsec / 1000000000.0)); + return (n.tv_sec + (n.tv_nsec / 1000000000.0)); } @@ -125,9 +134,9 @@ void log_sample(int sample) while (m) { if (sscanf(m, "%s %s", key, val) < 2) goto vmstat_next; - if (!strcmp(key, "pgpgin")) + if (streq(key, "pgpgin")) blockstat[sample].bi = atoi(val); - if (!strcmp(key, "pgpgout")) { + if (streq(key, "pgpgout")) { blockstat[sample].bo = atoi(val); break; } @@ -224,21 +233,19 @@ schedstat_next: char t[32]; struct ps_struct *parent; - ps->next_ps = malloc(sizeof(struct ps_struct)); + ps->next_ps = calloc(1, sizeof(struct ps_struct)); if (!ps->next_ps) { - perror("malloc(ps_struct)"); + perror("calloc(ps_struct)"); exit (EXIT_FAILURE); } - memset(ps->next_ps, 0, sizeof(struct ps_struct)); ps = ps->next_ps; ps->pid = pid; - ps->sample = malloc(sizeof(struct ps_sched_struct) * (len + 1)); + ps->sample = calloc(len + 1, sizeof(struct ps_sched_struct)); if (!ps->sample) { - perror("malloc(ps_struct)"); + perror("calloc(ps_struct)"); exit (EXIT_FAILURE); } - memset(ps->sample, 0, sizeof(struct ps_sched_struct) * (len + 1)); pscount++;