Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8aa2ed0b authored by Len Brown's avatar Len Brown
Browse files

tools/power turbostat: on SIGINT: sample, print and exit



When running in interval-mode, catch interrupts
and print a final data record before exiting.

Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 3f44a5c6
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -267,6 +267,10 @@ CPU PRF_CTRL


.fi
.fi


.SH SIGNALS

SIGINT will interrupt interval-mode.
The end-of-interval data will be collected and displayed before turbostat exits.
.SH NOTES
.SH NOTES


.B "turbostat "
.B "turbostat "
+30 −0
Original line number Original line Diff line number Diff line
@@ -2600,11 +2600,37 @@ int snapshot_proc_sysfs_files(void)
	return 0;
	return 0;
}
}


int exit_requested;

static void signal_handler (int signal)
{
	switch (signal) {
	case SIGINT:
		exit_requested = 1;
		if (debug)
			fprintf(stderr, " SIGINT\n");
		break;
	}
}

void setup_signal_handler(void)
{
	struct sigaction sa;

	memset(&sa, 0, sizeof(sa));

	sa.sa_handler = &signal_handler;

	if (sigaction(SIGINT, &sa, NULL) < 0)
		err(1, "sigaction SIGINT");
}
void turbostat_loop()
void turbostat_loop()
{
{
	int retval;
	int retval;
	int restarted = 0;
	int restarted = 0;


	setup_signal_handler();

restart:
restart:
	restarted++;
	restarted++;


@@ -2646,6 +2672,8 @@ void turbostat_loop()
		compute_average(EVEN_COUNTERS);
		compute_average(EVEN_COUNTERS);
		format_all_counters(EVEN_COUNTERS);
		format_all_counters(EVEN_COUNTERS);
		flush_output_stdout();
		flush_output_stdout();
		if (exit_requested)
			break;
		nanosleep(&interval_ts, NULL);
		nanosleep(&interval_ts, NULL);
		if (snapshot_proc_sysfs_files())
		if (snapshot_proc_sysfs_files())
			goto restart;
			goto restart;
@@ -2665,6 +2693,8 @@ void turbostat_loop()
		compute_average(ODD_COUNTERS);
		compute_average(ODD_COUNTERS);
		format_all_counters(ODD_COUNTERS);
		format_all_counters(ODD_COUNTERS);
		flush_output_stdout();
		flush_output_stdout();
		if (exit_requested)
			break;
	}
	}
}
}