log.c revision b9a496c166c35f670b1f0fce8745bc5df5ea74ad
/***
log.c - This file is part of systemd-bootchart
Copyright (C) 2009-2013 Intel Coproration
Authors:
Auke Kok <auke-jan.h.kok@intel.com>
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 <http://www.gnu.org/licenses/>.
***/
#define _GNU_SOURCE 1
#include <unistd.h>
#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <fcntl.h>
#include <time.h>
#include "bootchart.h"
#include "util.h"
/*
* Alloc a static 4k buffer for stdio - primarily used to increase
* PSS buffering from the default 1k stdin buffer to reduce
* read() overhead.
*/
static char smaps_buf[4096];
int procfd=-1;
double gettime_ns(void)
{
struct timespec n;
clock_gettime(CLOCK_MONOTONIC, &n);
}
void log_uptime(void)
{
FILE *f;
char str[32];
double uptime;
if (!f)
return;
fclose(f);
return;
}
fclose(f);
log_start = gettime_ns();
/* start graph at kernel boot time */
if (relative)
else
}
static char *bufgetline(char *buf)
{
char *c;
if (!buf)
return NULL;
if (c)
c++;
return c;
}
ssize_t n;
if (fd < 0)
return -errno;
if (n > 0) {
int i;
for (i = 0; i < n; i++)
if (buffer[i] == '\0')
buffer[i] = ' ';
buffer[n] = '\0';
}
return 0;
}
void log_sample(int sample)
{
static int vmstat;
static int schedstat;
char buf[4095];
char key[256];
char val[256];
char rt[256];
char wt[256];
char *m;
int c;
int p;
int mod;
static int e_fd;
ssize_t s;
ssize_t n;
int fd;
/* all the per-process stuff goes here */
if (!proc) {
/* find all processes */
if (!proc)
return;
} else {
}
if (!vmstat) {
/* block stuff */
if (vmstat == -1) {
exit (EXIT_FAILURE);
}
}
if (n <= 0) {
return;
}
buf[n] = '\0';
m = buf;
while (m) {
goto vmstat_next;
break;
}
m = bufgetline(m);
if (!m)
break;
}
if (!schedstat) {
/* overall CPU utilization */
if (schedstat == -1) {
exit (EXIT_FAILURE);
}
}
if (n <= 0) {
return;
}
buf[n] = '\0';
m = buf;
while (m) {
goto schedstat_next;
if (c > MAXCPUS)
/* Oops, we only have room for MAXCPUS data */
break;
if (c == cpus)
cpus = c + 1;
}
m = bufgetline(m);
if (!m)
break;
}
if (entropy) {
if (!e_fd) {
}
if (e_fd) {
if (n > 0) {
buf[n] = '\0';
}
}
}
int pid;
continue;
continue;
break;
}
/* end of our LL? then append a new record */
char t[32];
perror("calloc(ps_struct)");
exit (EXIT_FAILURE);
}
perror("calloc(ps_struct)");
exit (EXIT_FAILURE);
}
pscount++;
/* mark our first sample */
/* get name, start time */
continue;
}
if (s <= 0) {
continue;
}
buf[s] = '\0';
continue;
/* cmdline */
if (show_cmdline)
/* discard line 2 */
m = bufgetline(buf);
if (!m)
continue;
m = bufgetline(m);
if (!m)
continue;
if (!sscanf(m, "%*s %*s %s", t))
continue;
/* ppid */
if (!st)
continue;
continue;
}
/*
* setup child pointers
*
* these are used to paint the tree coherently later
* each parent has a LL of children, and a LL of siblings
*/
if (pid == 1)
continue; /* nothing to do for init atm */
/* kthreadd has ppid=0, which breaks our tree ordering */
/* orphan */
}
/* it's the first child */
} else {
/* walk all children and append */
}
}
/* else -> found pid, append data in ps */
/* below here is all continuous logging parts - we get here on every
* iteration */
/* rt, wt */
continue;
}
if (s <= 0) {
/* clean up our file descriptors - assume that the process exited */
//if (ps->smaps)
// fclose(ps->smaps);
continue;
}
buf[s] = '\0';
continue;
/ 1000000000.0;
if (!pss)
goto catch_rename;
/* Pss */
continue;
} else {
}
while (1) {
int pss_kb;
/* skip one line, this contains the object mapped */
break;
/* then there's a 28 char 14 line block */
break;
}
/* catch process rename, try to randomize time */
/* re-fetch name */
/* get name, start time */
continue;
}
if (s <= 0) {
/* clean up file descriptors */
//if (ps->smaps)
// fclose(ps->smaps);
continue;
}
buf[s] = '\0';
continue;
/* cmdline */
if (show_cmdline)
}
}
}