-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add interval option #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking "Sign up for GitHub", you agree to our terms of service and privacy statement. We'll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: add interval option #34
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,14 +28,25 @@ Usage: | |
| -c : list CPU temperatures (Celsius) | ||
| -g : list GPU temperatures (Celsius) | ||
| -h : help | ||
| -i : set interval in milliseconds (e.g. -i25, valid range is 20-1000, default: 1000) | ||
| -l : list all keys and values | ||
| -f : fail-soft mode. Shows last valid value if current sensor read fails. | ||
| -v : version | ||
| -n : tries to query the temperature sensors for n times (e.g. -n3) (1 second interval) until a valid value is returned | ||
| -n : tries to query the temperature sensors for n times (e.g. -n3) until a valid value is returned | ||
|
|
||
| $ smctemp -c | ||
| 64.2 | ||
|
|
||
| $ smctemp -g | ||
| 36.2 | ||
| ``` | ||
|
|
||
| ## Note for M2 Mac Users | ||
| On M2 Macs, sensor values may be unstable as described in the following issue: | ||
| - https://github.com/narugit/smctemp/pull/14 | ||
| - https://github.com/narugit/smctemp/issues/32 | ||
|
|
||
| For M2 Macs, using the `-n`, `-i`, and `-f` options can help obtain more stable sensor values. | ||
| Try tuning these options to get better results. | ||
|
|
||
| The recommended settings are `-i25 -n180 -f` (See also https://github.com/narugit/smctemp/pull/34/files#r1721025001) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,8 @@ void usage(char* prog) { | |
| std::cout << " -c : list CPU temperatures (Celsius)" << std::endl; | ||
| std::cout << " -g : list GPU temperatures (Celsius)" << std::endl; | ||
| std::cout << " -h : help" << std::endl; | ||
| std::cout << " -i : set interval in milliseconds (e.g. -i25, valid range is 20-1000, default: 1000)" | ||
| << std::endl; | ||
| std::cout << " -l : list all keys and values" << std::endl; | ||
| std::cout << " -f : fail-soft mode. Shows last valid value if current sensor read fails." << std::endl; | ||
| std::cout << " -v : version" << std::endl; | ||
|
|
@@ -21,19 +23,31 @@ void usage(char* prog) { | |
| int main(int argc, char *argv[]) { | ||
| int c; | ||
| unsigned int attempts = 1; | ||
| unsigned int interval_ms = 1'000; | ||
|
|
||
| kern_return_t result; | ||
| int op = smctemp::kOpNone; | ||
| bool isFailSoft = false; | ||
|
|
||
| while ((c = getopt(argc, argv, "clvfhn:g")) != -1) { | ||
| while ((c = getopt(argc, argv, "clvfhn:gi:")) != -1) { | ||
| switch(c) { | ||
| case 'c': | ||
| op = smctemp::kOpReadCpuTemp; | ||
| break; | ||
| case 'g': | ||
| op = smctemp::kOpReadGpuTemp; | ||
| break; | ||
| case 'i': | ||
| if (optarg) { | ||
| unsigned int temp_interval; | ||
| auto [ptr, ec] = std::from_chars(optarg, optarg + strlen(optarg), temp_interval); | ||
| if (ec != std::errc() || temp_interval < 20 || temp_interval > 1000) { | ||
| std::cerr << "Invalid argument provided for -i (integer between 20 and 1000 is required)" << std::endl; | ||
| return 1; | ||
| } | ||
| interval_ms = temp_interval; | ||
| } | ||
| break; | ||
| case 'n': | ||
| if (optarg) { | ||
| auto [ptr, ec] = std::from_chars(optarg, optarg + strlen(optarg), attempts); | ||
|
|
@@ -91,7 +105,7 @@ int main(int argc, char *argv[]) { | |
| if (smc_temp.IsValidTemperature(temp, valid_temperature_limits)) { | ||
| break; | ||
| } else { | ||
| usleep(1'000'000); | ||
| usleep(interval_ms * 1'000); | ||
| attempts--; | ||
| } | ||
| } | ||
|
|
@@ -105,6 +119,11 @@ int main(int argc, char *argv[]) { | |
| } | ||
| } | ||
| std::cout << std::fixed << std::setprecision(1) << temp << std::endl; | ||
| if (temp == 0.0) { | ||
| std::cerr << "Could not get valid sensor value. Please use `-n` option and `-i` option." << std::endl; | ||
| std::cerr << "In M2 Mac, it would be work fine with `-i25 -n180 -f` options.`" << std::endl; | ||
| return 1; | ||
| } | ||
| break; | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.