Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions cmd/traffic_crashlog/procinfo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,40 @@ procfd_readlink(pid_t pid, const char *fname)
return resolved.release();
}

bool
crashlog_write_regions(FILE *fp, const crashlog_target &target)
// Suck in a file from /proc/$PID and write it out with the given label.
static bool
write_procfd_file(const char *filename, const char *label, FILE *fp, const crashlog_target &target)
{
ats_scoped_fd fd;
textBuffer text(0);

fd = procfd_open(target.pid, "maps");
fd = procfd_open(target.pid, filename);
if (fd != -1) {
text.slurp(fd);
text.chomp();
fprintf(fp, "Memory Regions:\n%.*s\n", (int)text.spaceUsed(), text.bufPtr());
fprintf(fp, "%s:\n%.*s\n", label, (int)text.spaceUsed(), text.bufPtr());
}

return !text.empty();
}

bool
crashlog_write_regions(FILE *fp, const crashlog_target &target)
{
return write_procfd_file("maps", "Memory Regions", fp, target);
}

bool
crashlog_write_procstatus(FILE *fp, const crashlog_target &target)
{
return write_procfd_file("status", "Process Status", fp, target);
}

bool
crashlog_write_proclimits(FILE *fp, const crashlog_target &target)
{
return write_procfd_file("limits", "Process Limits", fp, target);
}

bool
crashlog_write_uname(FILE *fp, const crashlog_target &)
{
Expand Down Expand Up @@ -123,23 +141,6 @@ crashlog_write_datime(FILE *fp, const crashlog_target &target)
return true;
}

bool
crashlog_write_procstatus(FILE *fp, const crashlog_target &target)
{
ats_scoped_fd fd;
textBuffer text(0);

fd = procfd_open(target.pid, "status");
if (fd != -1) {
text.slurp(fd);
text.chomp();

fprintf(fp, "Process Status:\n%s\n", text.bufPtr());
}

return !text.empty();
}

bool
crashlog_write_backtrace(FILE *fp, const crashlog_target &)
{
Expand Down
3 changes: 3 additions & 0 deletions cmd/traffic_crashlog/traffic_crashlog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ main(int /* argc ATS_UNUSED */, const char **argv)
fprintf(fp, "\n");
crashlog_write_procstatus(fp, target);

fprintf(fp, "\n");
crashlog_write_proclimits(fp, target);

fprintf(fp, "\n");
crashlog_write_regions(fp, target);

Expand Down
9 changes: 5 additions & 4 deletions cmd/traffic_crashlog/traffic_crashlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ struct crashlog_target {
};

bool crashlog_write_backtrace(FILE *, const crashlog_target &);
bool crashlog_write_regions(FILE *, const crashlog_target &);
bool crashlog_write_exename(FILE *, const crashlog_target &);
bool crashlog_write_uname(FILE *, const crashlog_target &);
bool crashlog_write_datime(FILE *, const crashlog_target &);
bool crashlog_write_exename(FILE *, const crashlog_target &);
bool crashlog_write_proclimits(FILE *, const crashlog_target &);
bool crashlog_write_procname(FILE *, const crashlog_target &);
bool crashlog_write_procstatus(FILE *, const crashlog_target &);
bool crashlog_write_records(FILE *, const crashlog_target &);
bool crashlog_write_siginfo(FILE *, const crashlog_target &);
bool crashlog_write_regions(FILE *, const crashlog_target &);
bool crashlog_write_registers(FILE *, const crashlog_target &);
bool crashlog_write_siginfo(FILE *, const crashlog_target &);
bool crashlog_write_uname(FILE *, const crashlog_target &);

#endif /* __TRAFFIC_CRASHLOG_H__ */