Skip to content

Commit fbd284d

Browse files
committed
Update turbostat handling in CMakeLists file.
1 parent 719c634 commit fbd284d

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

src/hws/cpu/CMakeLists.txt

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,43 @@ endif ()
2727
find_program(HWS_TURBOSTAT_FOUND turbostat)
2828
if (HWS_TURBOSTAT_FOUND)
2929
## check if the turbostat command works as intended
30-
execute_process(COMMAND turbostat -n 1 -S -q
31-
RESULT_VARIABLE HWS_TURBOSTAT_WITHOUT_ROOT
30+
execute_process(COMMAND sudo -n turbostat -n 1 -i 0.001 -S -q
31+
RESULT_VARIABLE HWS_TURBOSTAT_WITH_ROOT_N
3232
OUTPUT_QUIET
3333
ERROR_QUIET)
34-
if (NOT HWS_TURBOSTAT_WITHOUT_ROOT EQUAL 0)
35-
message(STATUS "Can't use turbostat without root permissions! Try using with sudo...")
36-
execute_process(COMMAND sudo -n turbostat -n 1 -i 0.001 -S -q
37-
RESULT_VARIABLE HWS_TURBOSTAT_ROOT_PASSWORD_REQUIRED
34+
if (HWS_TURBOSTAT_WITH_ROOT_N EQUAL 0)
35+
## can execute with root
36+
execute_process(COMMAND sudo turbostat -n 1 -i 0.001 -S -q
37+
RESULT_VARIABLE HWS_TURBOSTAT_WITH_ROOT
3838
OUTPUT_QUIET
3939
ERROR_QUIET)
40-
if (NOT HWS_TURBOSTAT_ROOT_PASSWORD_REQUIRED EQUAL 0)
41-
message(STATUS "Can't use turbostat with root if a sudo password is required! Please add turbostat to the sudoer group.")
42-
message(STATUS "Disabling turbostat support!")
43-
else ()
44-
execute_process(COMMAND sudo turbostat -n 1 -i 0.001 -S -q
45-
RESULT_VARIABLE HWS_TURBOSTAT_WITH_ROOT
46-
OUTPUT_QUIET
47-
ERROR_QUIET)
48-
if (NOT HWS_TURBOSTAT_WITH_ROOT EQUAL 0)
49-
message(STATUS "Can't use turbostat with root even if no sudo password is required!")
50-
message(STATUS "Disabling turbostat support!")
51-
else ()
52-
message(STATUS "Enable sampling of CPU information using turbostat.")
40+
if (HWS_TURBOSTAT_WITH_ROOT EQUAL 0)
41+
message(STATUS "Enable sampling of CPU information using turbostat with root privileges.")
5342

54-
set(HWS_TURBOSTAT_EXECUTION_TYPE "root")
55-
# add compile definitions
56-
target_compile_definitions(${HWS_LIBRARY_NAME} PUBLIC HWS_VIA_TURBOSTAT_ENABLED)
57-
target_compile_definitions(${HWS_LIBRARY_NAME} PUBLIC HWS_VIA_TURBOSTAT_ROOT)
58-
endif ()
43+
set(HWS_TURBOSTAT_EXECUTION_TYPE "root")
44+
# add compile definitions
45+
target_compile_definitions(${HWS_LIBRARY_NAME} PUBLIC HWS_VIA_TURBOSTAT_ENABLED)
46+
target_compile_definitions(${HWS_LIBRARY_NAME} PUBLIC HWS_VIA_TURBOSTAT_ROOT)
47+
else ()
48+
message(STATUS "Can't use turbostat even with root privileges!")
49+
message(STATUS "Disabling turbostat support!")
5950
endif ()
6051
else ()
61-
set(HWS_TURBOSTAT_EXECUTION_TYPE "without_root")
62-
# add compile definitions
63-
target_compile_definitions(${HWS_LIBRARY_NAME} PUBLIC HWS_VIA_TURBOSTAT_ENABLED)
52+
## check if turbostat can be executed without root -> potential less data
53+
execute_process(COMMAND turbostat -n 1 -i 0.001 -S -q
54+
RESULT_VARIABLE HWS_TURBOSTAT_WITHOUT_ROOT
55+
OUTPUT_QUIET
56+
ERROR_QUIET)
57+
if (HWS_TURBOSTAT_WITHOUT_ROOT EQUAL 0)
58+
message(STATUS "Enable sampling of CPU information using turbostat without root privileges.")
59+
60+
set(HWS_TURBOSTAT_EXECUTION_TYPE "without_root")
61+
# add compile definitions
62+
target_compile_definitions(${HWS_LIBRARY_NAME} PUBLIC HWS_VIA_TURBOSTAT_ENABLED)
63+
else ()
64+
message(STATUS "Can't use turbostat (with or without root privileges)!")
65+
message(STATUS "Disabling turbostat support!")
66+
endif ()
6467
endif ()
6568
endif ()
6669

0 commit comments

Comments
 (0)