Skip to content

Add option to change signals - #33

Open
Bojun-Seo wants to merge 2 commits into
honggyukim:mainfrom
Bojun-Seo:signals
Open

Add option to change signals#33
Bojun-Seo wants to merge 2 commits into
honggyukim:mainfrom
Bojun-Seo:signals

Conversation

@Bojun-Seo

Copy link
Copy Markdown
Collaborator

Implementation of issue #22

heaptrace uses SIGUSR1 and SIGUSR2 to dump allocation status (in terms of size and count respectively) during process running. But the signal handler will not work properly, if the target process uses one or both of the signals.

So I suggest to add option to change signals to dump allocation status. For example,

# register signal 33 to dump the allocation status sorted in terms of size
$ heaptrace --signal size:33 ./a.out

# register signal 34 to dump the allocation status sorted in terms of count
$ heaptrace --signal count:34 ./a.out

# register signal 33 and 34 to dump the allocation status sorted in terms of size and count respectively
$ heaptrace --signal size:33,count:34 ./a.out

Add signal handler registration interface and modularize signal
handler registration

Signed-off-by: Bojun Seo <bojun.seo.0@gmail.com>
User could register signal to report on specific sort key. The option
format is "KEY1:SIGNO1,KEY2:SIGNO2". The usage is as follows:

  $ heaptrace --signal size:35 samples/samples.out
  $ heaptrace --signal count:35 samples/samples.out
  $ heaptrace --signal count:35,size:36 samples/samples.out

Signed-off-by: Bojun Seo <bojun.seo.0@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds support for customizing which signals trigger heap allocation dumps, to avoid conflicts with user processes.

  • Refactors signal registration into register_sighandler and exposes handlers for size/count
  • Parses a new --signals CLI option (and HEAPTRACE_SIGNALS env) to map keys (size/count) to arbitrary signal numbers
  • Updates headers, initialization logic, and child-environment setup to propagate the new option

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/sighandler.h Declares register_sighandler and new handler functions
src/sighandler.cc Refactors signal setup; defines size_sighandler/count_sighandler
src/libheaptrace.cc Reads HEAPTRACE_SIGNALS, parses key:number pairs, registers handlers
src/heaptrace.h Adds signals field to opts
src/heaptrace.cc Introduces --signals CLI option and exports via env
Comments suppressed due to low confidence (2)

src/heaptrace.cc:68

  • There are no tests covering parsing or handling of the new --signals option; consider adding unit or integration tests to verify correct behavior and error handling.
		opts->signals = arg;

src/sighandler.cc:44

  • [nitpick] The size_sighandler and sigusr1_handler functions both call dump_stackmap("size", ...); consider consolidating to a single handler to avoid duplicate logic.
void size_sighandler(int /*unused*/)

Comment thread src/libheaptrace.cc
for (const auto& key_num: key_num_vec) {
auto item_vec = utils::string_split(key_num, ':');
if (item_vec.size() != 2) {
pr_out("Failed to parsing signals: %s\n",

Copilot AI Jun 22, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message "Failed to parsing signals" is grammatically incorrect; consider "Failed to parse signal definition: %s".

Suggested change
pr_out("Failed to parsing signals: %s\n",
pr_out("Failed to parse signals: %s\n",

Copilot uses AI. Check for mistakes.
Comment thread src/libheaptrace.cc
} else if (key == "count") {
register_sighandler(count_sighandler, signo);
} else {
pr_out("Cannot register not supporting key: %s\n",

Copilot AI Jun 22, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error text is awkward; consider "Unsupported key: %s" for clarity.

Suggested change
pr_out("Cannot register not supporting key: %s\n",
pr_out("Unsupported key: %s\n",

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants