Fix for AMD GPU drm different format proc file (#16561)
Emmanuel Vasilakis committed
Dec 7, 2023 at 16:39 UTC
e9732229374d13ffc507ba9f7e77e01a4d78179c
1 file changed
+7
-3
collectors/proc.plugin/sys_class_drm.c
+7
-3
@@ -648,13 +648,17 @@ static int read_clk_freq_file(procfile **p_ff, const char *const pathname, colle
648
*p_ff = procfile_open(pathname, NULL, PROCFILE_FLAG_NO_ERROR_ON_FILE_IO);
649
if(unlikely(!*p_ff)) return -2;
650
}
651
-
651
+
652
if(unlikely(NULL == (*p_ff = procfile_readall(*p_ff)))) return -3;
653
654
for(size_t l = 0; l < procfile_lines(*p_ff) ; l++) {
655
+ char *str_with_units = NULL;
656
+ if((*p_ff)->lines->lines[l].words >= 3 && !strcmp(procfile_lineword((*p_ff), l, 2), "*")) //format: X: collected_number *
657
+ str_with_units = procfile_lineword((*p_ff), l, 1);
658
+ else if ((*p_ff)->lines->lines[l].words == 2 && !strcmp(procfile_lineword((*p_ff), l, 1), "*")) //format: collected_number *
659
+ str_with_units = procfile_lineword((*p_ff), l, 0);
660
656
- if((*p_ff)->lines->lines[l].words >= 3 && !strcmp(procfile_lineword((*p_ff), l, 2), "*")){
657
- char *str_with_units = procfile_lineword((*p_ff), l, 1);
661
+ if (str_with_units) {
662
char *delim = strchr(str_with_units, 'M');
663
char str_without_units[10];
664
memcpy(str_without_units, str_with_units, delim - str_with_units);