Skip to content

Commit

Permalink
work correctly without CONFIG_SCHED_DEBUG (#10)
Browse files Browse the repository at this point in the history
The app appeared to work without CONFIG_SCHED_DEBUG (no error messages),
but the PS part of the graph was not plotted, and process command lines
were not collected with -C. It was hard to find out what's the reason. A
small change fixes the code to work correctly without requirement for
this config.
  • Loading branch information
akavel authored and sofar committed Aug 30, 2016
1 parent dcb246b commit 1d5fa8c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
For systemd-bootchart, several proc debug interfaces are required in the kernel config:
CONFIG_SCHEDSTATS
below is optional, for additional info:
CONFIG_SCHED_DEBUG
32 changes: 17 additions & 15 deletions src/store.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,48 +252,49 @@ int log_sample(DIR *proc,
ps->sample->runtime = atoll(rt);
ps->sample->waittime = atoll(wt);

/* get name, start time */
/* get name, start time; requires CONFIG_SCHED_DEBUG in kernel */
if (ps->sched < 0) {
sprintf(filename, "%d/sched", pid);
ps->sched = openat(procfd, filename, O_RDONLY|O_CLOEXEC);
if (ps->sched < 0)
continue;
goto no_sched;
}

s = pread(ps->sched, buf, sizeof(buf) - 1, 0);
if (s <= 0) {
ps->sched = safe_close(ps->sched);
continue;
goto no_sched;
}
buf[s] = '\0';

if (!sscanf(buf, "%s %*s %*s", key))
continue;
goto no_sched;

strscpy(ps->name, sizeof(ps->name), key);

/* cmdline */
if (arg_show_cmdline)
pid_cmdline_strscpy(procfd, ps->name, sizeof(ps->name), pid);

/* discard line 2 */
m = bufgetline(buf);
if (!m)
continue;
goto no_sched;

m = bufgetline(m);
if (!m)
continue;
goto no_sched;

if (!sscanf(m, "%*s %*s %s", t))
continue;
goto no_sched;

r = safe_atod(t, &ps->starttime);
if (r < 0)
continue;
goto no_sched;

ps->starttime /= 1000.0;

no_sched:
/* cmdline */
if (arg_show_cmdline)
pid_cmdline_strscpy(procfd, ps->name, sizeof(ps->name), pid);

if (arg_show_cgroup)
/* if this fails, that's OK */
cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER,
Expand Down Expand Up @@ -527,24 +528,25 @@ int log_sample(DIR *proc,
sprintf(filename, "%d/sched", pid);
ps->sched = openat(procfd, filename, O_RDONLY|O_CLOEXEC);
if (ps->sched < 0)
continue;
goto no_sched2;
}

s = pread(ps->sched, buf, sizeof(buf) - 1, 0);
if (s <= 0) {
/* clean up file descriptors */
ps->sched = safe_close(ps->sched);
ps->schedstat = safe_close(ps->schedstat);
continue;
goto no_sched2;
}

buf[s] = '\0';

if (!sscanf(buf, "%s %*s %*s", key))
continue;
goto no_sched2;

strscpy(ps->name, sizeof(ps->name), key);

no_sched2:
/* cmdline */
if (arg_show_cmdline)
pid_cmdline_strscpy(procfd, ps->name, sizeof(ps->name), pid);
Expand Down

0 comments on commit 1d5fa8c

Please sign in to comment.