Skip to content

Commit 1d5fa8c

Browse files
akavelsofar
authored andcommitted
work correctly without CONFIG_SCHED_DEBUG (#10)
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.
1 parent dcb246b commit 1d5fa8c

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
For systemd-bootchart, several proc debug interfaces are required in the kernel config:
22
CONFIG_SCHEDSTATS
3+
below is optional, for additional info:
34
CONFIG_SCHED_DEBUG

src/store.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -252,48 +252,49 @@ int log_sample(DIR *proc,
252252
ps->sample->runtime = atoll(rt);
253253
ps->sample->waittime = atoll(wt);
254254

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

263263
s = pread(ps->sched, buf, sizeof(buf) - 1, 0);
264264
if (s <= 0) {
265265
ps->sched = safe_close(ps->sched);
266-
continue;
266+
goto no_sched;
267267
}
268268
buf[s] = '\0';
269269

270270
if (!sscanf(buf, "%s %*s %*s", key))
271-
continue;
271+
goto no_sched;
272272

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

275-
/* cmdline */
276-
if (arg_show_cmdline)
277-
pid_cmdline_strscpy(procfd, ps->name, sizeof(ps->name), pid);
278-
279275
/* discard line 2 */
280276
m = bufgetline(buf);
281277
if (!m)
282-
continue;
278+
goto no_sched;
283279

284280
m = bufgetline(m);
285281
if (!m)
286-
continue;
282+
goto no_sched;
287283

288284
if (!sscanf(m, "%*s %*s %s", t))
289-
continue;
285+
goto no_sched;
290286

291287
r = safe_atod(t, &ps->starttime);
292288
if (r < 0)
293-
continue;
289+
goto no_sched;
294290

295291
ps->starttime /= 1000.0;
296292

293+
no_sched:
294+
/* cmdline */
295+
if (arg_show_cmdline)
296+
pid_cmdline_strscpy(procfd, ps->name, sizeof(ps->name), pid);
297+
297298
if (arg_show_cgroup)
298299
/* if this fails, that's OK */
299300
cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER,
@@ -527,24 +528,25 @@ int log_sample(DIR *proc,
527528
sprintf(filename, "%d/sched", pid);
528529
ps->sched = openat(procfd, filename, O_RDONLY|O_CLOEXEC);
529530
if (ps->sched < 0)
530-
continue;
531+
goto no_sched2;
531532
}
532533

533534
s = pread(ps->sched, buf, sizeof(buf) - 1, 0);
534535
if (s <= 0) {
535536
/* clean up file descriptors */
536537
ps->sched = safe_close(ps->sched);
537538
ps->schedstat = safe_close(ps->schedstat);
538-
continue;
539+
goto no_sched2;
539540
}
540541

541542
buf[s] = '\0';
542543

543544
if (!sscanf(buf, "%s %*s %*s", key))
544-
continue;
545+
goto no_sched2;
545546

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

549+
no_sched2:
548550
/* cmdline */
549551
if (arg_show_cmdline)
550552
pid_cmdline_strscpy(procfd, ps->name, sizeof(ps->name), pid);

0 commit comments

Comments
 (0)