Skip to content

Commit

Permalink
matron: set thread names for easier debugging
Browse files Browse the repository at this point in the history
giving explicitly created threads names makes it
substantially easier to narrow in on a particular
thread in gdb
  • Loading branch information
ngwese committed Jun 14, 2022
1 parent a8de41f commit f79a536
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions matron/src/clocks/clock_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static void clock_internal_start() {

pthread_attr_init(&attr);
pthread_create(&clock_internal_thread, &attr, &clock_internal_thread_run, NULL);
pthread_setname_np(clock_internal_thread, "clock_internal");
pthread_attr_destroy(&attr);
}

Expand Down
1 change: 1 addition & 0 deletions matron/src/clocks/clock_link.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ void clock_link_start() {
clock_link_shared_data.enabled = false;

pthread_create(&clock_link_thread, &attr, &clock_link_run, NULL);
pthread_setname_np(clock_link_thread, "clock_link");
}

void clock_link_join_session() {
Expand Down
1 change: 1 addition & 0 deletions matron/src/clocks/clock_scheduler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ void clock_scheduler_start() {

pthread_attr_init(&attr);
pthread_create(&clock_scheduler_tick_thread, &attr, &clock_scheduler_tick_thread_run, NULL);
pthread_setname_np(clock_scheduler_tick_thread, "clock_sched_tick");
pthread_attr_destroy(&attr);
}

Expand Down
2 changes: 2 additions & 0 deletions matron/src/device/device.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ int dev_start(union dev *d) {
fprintf(stderr, "m_init(): error creating thread\n");
return -1;
}
pthread_setname_np(d->base.tid, "device_loop");

return 0;
}

Expand Down
1 change: 1 addition & 0 deletions matron/src/device/device_monitor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ void dev_monitor_init(void) {
if (s) {
fprintf(stderr, "error creating thread\n");
}
pthread_setname_np(watch_tid, "watch_loop");
pthread_attr_destroy(&attr);
}

Expand Down
1 change: 1 addition & 0 deletions matron/src/hardware/battery.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void battery_init() {
if (pthread_create(&p, NULL, battery_check, 0)) {
fprintf(stderr, "BATTERY: Error creating thread\n");
}
pthread_setname_np(p, "battery_check");
} else {
fprintf(stderr, "BATTERY: FAIL.\n");
}
Expand Down
1 change: 1 addition & 0 deletions matron/src/hardware/input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ int input_setup(matron_io_t *io) {
fprintf(stderr, "ERROR (input %s) pthread error\n", io->ops->name);
return err;
}
pthread_setname_np(input->poll_thread, "input_poll");

return 0;
}
Expand Down
1 change: 1 addition & 0 deletions matron/src/hardware/stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void stat_init() {
if (pthread_create(&p, NULL, stat_check, 0)) {
fprintf(stderr, "STAT: Error creating thread\n");
}
pthread_setname_np(p, "stat_check");
}

void stat_deinit() {
Expand Down
1 change: 1 addition & 0 deletions matron/src/input.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ void input_init(void) {
if (s != 0) {
fprintf(stderr, "input_init(): error in pthread_create(): %d\n", s);
}
pthread_setname_np(pid, "input_run");
pthread_attr_destroy(&attr);
}
1 change: 1 addition & 0 deletions matron/src/metro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ void metro_init(struct metro *t, uint64_t nsec, int count) {
metro_handle_error(res, "pthread_create");
return;
} else {
pthread_setname_np(t->tid, "metro_loop");
t->status = METRO_STATUS_RUNNING;
if (res != 0) {
metro_handle_error(res, "pthread_setschedparam");
Expand Down

0 comments on commit f79a536

Please sign in to comment.