網頁

2020年9月2日 星期三

為在 jetson nano 的 conky 加速

conky 若是利用 exec, execp 等命令,會大量耗費資源
之前使用 execi 執行 tegrastats 取得一些系統資訊
直接改用 C, 編寫出 jetson_fan, 
jetson_temp_ao, jetson_temp_cpu, jetson_temp_gpu,
jetson_power_cpu, jetson_power_gpu, jetson_power_all
等變數
$ vi .conkyrc
RAM:${jetson_ram_usage}${alignr}${jetson_ram}
RAM lfb:${alignr}${jetson_ram_lfb}
SWAP:${jetson_swap_usage}${alignr}${jetson_swap}
SWAP Cached:${alignr}${jetson_swap_cached}
EMC Bandwidth:${jetson_emc} ${jetson_emc_bar}
CPU0:${jetson_cpu_frq 0} ${jetson_cpu_bar 0}
CPU1:${jetson_cpu_frq 1} ${jetson_cpu_bar 1}
CPU2:${jetson_cpu_frq 2} ${jetson_cpu_bar 2}
CPU3:${jetson_cpu_frq 3} ${jetson_cpu_bar 3}
GPU  ${jetson_gpu} ${jetson_gpu_bar}
${font :blod:size=12}Temperature ${hr}
${font :normal:size=10}Thermal:${alignr} ${jetson_temp_thermal}
PLL:${alignr} ${jetson_temp_pll}
CPU:${alignr} ${jetson_temp_cpu}
Wifi:${alignr} ${jetson_temp_wifi}
PMIC:${alignr} ${jetson_temp_pmic}
GPU:${alignr} ${jetson_temp_gpu}
AO:${alignr} ${jetson_temp_ao}
Fan Speed:${jetson_fan} ${jetson_fan_bar}




以下是 conky source 的 patch
diff --git a/cmake/ConkyBuildOptions.cmake b/cmake/ConkyBuildOptions.cmake
index 9e9826f9..758f4072 100644
--- a/cmake/ConkyBuildOptions.cmake
+++ b/cmake/ConkyBuildOptions.cmake
@@ -260,6 +260,8 @@ option(BUILD_JOURNAL "Enable support for reading from the systemd journal"
 option(BUILD_PULSEAUDIO
        "Enable support for Pulseaudio's default sink and source" false)

+option(BUILD_JETSON "Enable jetson support" true)
+
 message(STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS})
 message(STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS})

diff --git a/cmake/config.h.in b/cmake/config.h.in
index 570e26a5..a6a0dce8 100644
--- a/cmake/config.h.in
+++ b/cmake/config.h.in
@@ -127,6 +127,8 @@

 #cmakedefine BUILD_JOURNAL 1

+#cmakedefine BUILD_JETSON 1
+
 #cmakedefine HAVE_STATFS64 1
 #ifndef HAVE_STATFS64
 #define statfs64 statfs
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 4472a28e..00b8cbe0 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -282,6 +282,11 @@ if(BUILD_PULSEAUDIO)
   set(optional_sources ${optional_sources} ${pulseaudio})
 endif(BUILD_PULSEAUDIO)

+if(BUILD_JETSON)
+  set(jetson jetson.cc jetson.h)
+  set(optional_sources ${optional_sources} ${jetson})
+endif(BUILD_PJETSON)
+
 if(BUILD_TESTS)
   # Create a library strictly for testing
   add_library(conky_core ${conky_sources} ${optional_sources})
diff --git a/src/core.cc b/src/core.cc
index b5e4834a..18931e08 100644
--- a/src/core.cc
+++ b/src/core.cc
@@ -107,6 +107,7 @@
 #ifdef BUILD_PULSEAUDIO
 #include "pulseaudio.h"
 #endif /* BUILD_PULSEAUDIO */
+#include "jetson.h"

 /* check for OS and include appropriate headers */
 #if defined(__linux__)
@@ -1968,6 +1969,90 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
   obj->callbacks.free = &free_pulseaudio;
   init_pulseaudio(obj);
 #endif /* BUILD_PULSEAUDIO */
+#ifdef BUILD_JETSON
+  END OBJ(jetson_fan, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_fan;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_fan_bar, 0) init_jetson_bar(obj, arg);
+  obj->callbacks.barval = &jetson_fan_barval;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_ram, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_ram;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_ram_usage, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_ram_usage;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_ram_lfb, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_ram_lfb;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_swap, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_swap;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_swap_usage, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_swap_usage;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_swap_cached, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_swap_cached;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_cpu_frq, 0) init_jetson_cpu(obj, arg);
+  obj->callbacks.print = &jetson_cpu_frq;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_cpu_bar, 0) init_jetson_cpu_bar(obj, arg);
+  obj->callbacks.barval = &jetson_cpu_barval;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_emc, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_emc;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_emc_bar, 0) init_jetson_bar(obj, arg);
+  obj->callbacks.barval = &jetson_emc_barval;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_gpu, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_gpu;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_gpu_bar, 0) init_jetson_bar(obj, arg);
+  obj->callbacks.barval = &jetson_gpu_barval;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_temp_pll, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_temp_pll;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_temp_cpu, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_temp_cpu;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_temp_wifi, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_temp_wifi;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_temp_pmic, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_temp_pmic;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_temp_gpu, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_temp_gpu;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_temp_ao, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_temp_ao;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_temp_thermal, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_temp_thermal;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_power_all_cur, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_power_all_cur;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_power_all_avg, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_power_all_avg;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_power_gpu_cur, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_power_gpu_cur;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_power_gpu_avg, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_power_gpu_avg;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_power_cpu_cur, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_power_cpu_cur;
+  obj->callbacks.free = &free_jetson;
+  END OBJ(jetson_power_cpu_avg, 0) init_jetson(obj);
+  obj->callbacks.print = &jetson_power_cpu_avg;
+  obj->callbacks.free = &free_jetson;
+#endif /* BUILD_JETSON */
+
   END {
     auto *buf = static_cast<char *>(malloc(text_buffer_size.get(*state)));

diff --git a/src/top.cc b/src/top.cc
index c95a817f..5c22de39 100644
--- a/src/top.cc
+++ b/src/top.cc
@@ -481,6 +481,7 @@ static void print_top_mem(struct text_object *obj, char *p,
     return;
   }

+  if (info.memmax == 0) update_meminfo();
   width = std::min(p_max_size, static_cast<unsigned int>(7));
   snprintf(p, width, "%6.2f",
            (static_cast<float>(td->list[td->num]->rss) / info.memmax) / 10);


jetson.h
/*
 *
 * Conky, a system monitor, based on torsmo
 *
 * Any original torsmo code is licensed under the BSD license
 *
 * All code written since the fork of torsmo is licensed under the GPL
 *
 * Please see COPYING for details
 *
 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
 * Copyright (c) 2005-2019 Brenden Matthews, Philip Kovacs, et. al.
 *      (see AUTHORS)
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef _JETSON_H
#define _JETSON_H

#include "text_object.h"

void init_jetson(struct text_object *obj);
void init_jetson_bar(struct text_object *obj, const char *arg);
void init_jetson_cpu(struct text_object *obj, const char *arg);
void init_jetson_cpu_bar(struct text_object *obj, const char *arg);
void free_jetson(struct text_object *obj);
void jetson_fan(struct text_object *obj, char *p,
                          unsigned int p_max_size);
double jetson_fan_barval(struct text_object *obj);
void jetson_ram(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_ram_usage(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_ram_lfb(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_swap(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_swap_usage(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_swap_cached(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_cpu_frq(struct text_object *obj, char *p,
                          unsigned int p_max_size);
double jetson_cpu_barval(struct text_object *obj);
void jetson_emc(struct text_object *obj, char *p,
                          unsigned int p_max_size);
double jetson_emc_barval(struct text_object *obj);
void jetson_gpu(struct text_object *obj, char *p,
                          unsigned int p_max_size);
double jetson_gpu_barval(struct text_object *obj);
void jetson_temp_pll(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_temp_cpu(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_temp_wifi(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_temp_pmic(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_temp_gpu(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_temp_ao(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_temp_thermal(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_power_all_cur(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_power_all_avg(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_power_gpu_cur(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_power_gpu_avg(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_power_cpu_cur(struct text_object *obj, char *p,
                          unsigned int p_max_size);
void jetson_power_cpu_avg(struct text_object *obj, char *p,
                          unsigned int p_max_size);

#endif /* _JETSON_H */


jetson.cc
/*
 *
 * Conky, a system monitor, based on torsmo
 *
 * Any original torsmo code is licensed under the BSD license
 *
 * All code written since the fork of torsmo is licensed under the GPL
 *
 * Please see COPYING for details
 *
 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
 * Copyright (c) 2005-2019 Brenden Matthews, Philip Kovacs, et. al.
 *     (see AUTHORS)
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#include "jetson.h"
#include <pthread.h>
#include <math.h>
#include <unistd.h>
#include "common.h"
#include "config.h"
#include "conky.h"
#include "core.h"
#include "logging.h"
#include "specials.h"
#include "text_object.h"

struct jetson_cpu {
  int usage;
  int max;
};

struct jetson_info {
  pthread_t *thread;
  bool running;
  int ram_used;
  int ram_total;
  char *ram_lfb;
  int swap_used;
  int swap_total;
  int swap_cached;
  int cpu_cnt;
  struct jetson_cpu *cpus;
  int emc;
  int gpu;
  float temp_pll;
  float temp_cpu;
  float temp_wifi;
  float temp_pmic;
  float temp_gpu;
  float temp_ao;
  float temp_thermal;
  int power_all_cur;
  int power_all_avg;
  int power_gpu_cur;
  int power_gpu_avg;
  int power_cpu_cur;
  int power_cpu_avg;
};

static struct jetson_info *p_jetson_info = nullptr;

void *tegrastats_thread(void *ptr) {
  struct jetson_info *p_jetson_info = (struct jetson_info *)ptr;
  char line[512];
  FILE *fp = popen("tegrastats", "r");
  if (fp != nullptr) {
    p_jetson_info->running = true;
    while (p_jetson_info->running) {
      if (fgets(line, 512, fp) == nullptr) {
        break;
      }
      char *nt;
      char *token = strtok_r(line, " ", &nt);
      int cnt = 0;
      while (token != nullptr) {
        //fprintf(stderr, "%d:%s ", cnt, token);
        if (strcmp("RAM", token) == 0) {
          token = strtok_r(NULL, " ", &nt); cnt++;
          sscanf(token, "%d/%dMB", &p_jetson_info->ram_used, &p_jetson_info->ram_total);
        } else if (strcmp("(lfb", token) == 0) {
          token = strtok_r(NULL, " ", &nt); cnt++;
          p_jetson_info->ram_lfb = strdup(token);
          int l = strlen(p_jetson_info->ram_lfb);
          if (l > 0) {
            p_jetson_info->ram_lfb[l - 1] = 0;
          }
        } else if (strcmp("SWAP", token) == 0) {
          token = strtok_r(NULL, " ", &nt); cnt++;
          sscanf(token, "%d/%dMB", &p_jetson_info->swap_used, &p_jetson_info->swap_total);
        } else if (strcmp("(cached", token) == 0) {
          token = strtok_r(NULL, " ", &nt); cnt++;
          sscanf(token, "%dMB", &p_jetson_info->swap_cached);
        } else if (token[0] == '[' && token[strlen(token) - 1] == ']') {
          int tt_cnt = 1;
          for (int i=0; i < strlen(token); i++) {
            if (token[i] == ',') tt_cnt++;
          }
          if (p_jetson_info->cpu_cnt != tt_cnt) {
            if (p_jetson_info->cpus != nullptr) {
              free(p_jetson_info->cpus);
            }
            p_jetson_info->cpus = (struct jetson_cpu *)malloc(sizeof(struct jetson_cpu) * tt_cnt);
            p_jetson_info->cpu_cnt = tt_cnt;
          }
          char *nnt;
          char *tt = strtok_r(token+1, ",", &nnt);
          tt_cnt = 0;
          while (tt != nullptr) {
            if (tt[strlen(tt) - 1] == ']') {
              sscanf(tt, "%d%%@%d]", &p_jetson_info->cpus[tt_cnt].usage, &p_jetson_info->cpus[tt_cnt].max);
              break;
            } else {
              sscanf(tt, "%d%%@%d", &p_jetson_info->cpus[tt_cnt].usage, &p_jetson_info->cpus[tt_cnt].max);
            }
            tt = strtok_r(NULL, ",", &nnt); tt_cnt++;
          }
        } else if (strcmp("EMC_FREQ", token) == 0) {
          token = strtok_r(NULL, " ", &nt); cnt++;
          sscanf(token, "%d%%", &p_jetson_info->emc);
        } else if (strcmp("GR3D_FREQ", token) == 0) {
          token = strtok_r(NULL, " ", &nt); cnt++;
          sscanf(token, "%d%%", &p_jetson_info->gpu);
        } else if (strncmp("PLL@", token, 4) == 0) {
          sscanf(token, "PLL@%fC", &p_jetson_info->temp_pll);
        } else if (strncmp("CPU@", token, 4) == 0) {
          sscanf(token, "CPU@%fC", &p_jetson_info->temp_cpu);
        } else if (strncmp("iwlwifi@", token, 8) == 0) {
          sscanf(token, "iwlwifi@%fC", &p_jetson_info->temp_wifi);
        } else if (strncmp("PMIC@", token, 5) == 0) {
          sscanf(token, "PMIC@%fC", &p_jetson_info->temp_pmic);
        } else if (strncmp("GPU@", token, 4) == 0) {
          sscanf(token, "GPU@%fC", &p_jetson_info->temp_gpu);
        } else if (strncmp("AO@", token, 3) == 0) {
          sscanf(token, "AO@%fC", &p_jetson_info->temp_ao);
        } else if (strncmp("thermal@", token, 8) == 0) {
          sscanf(token, "thermal@%fC", &p_jetson_info->temp_thermal);
        } else if (strcmp("POM_5V_IN", token) == 0) {
          token = strtok_r(NULL, " ", &nt); cnt++;
          sscanf(token, "%d/%d", &p_jetson_info->power_all_cur, &p_jetson_info->power_all_avg);
        } else if (strcmp("POM_5V_GPU", token) == 0) {
          token = strtok_r(NULL, " ", &nt); cnt++;
          sscanf(token, "%d/%d", &p_jetson_info->power_gpu_cur, &p_jetson_info->power_gpu_avg);
        } else if (strcmp("POM_5V_CPU", token) == 0) {
          token = strtok_r(NULL, " ", &nt); cnt++;
          sscanf(token, "%d/%d", &p_jetson_info->power_cpu_cur, &p_jetson_info->power_cpu_avg);
        }
        token = strtok_r(NULL, " ", &nt); cnt++;
      }
    }
    pclose(fp);
  }
  fprintf(stderr, PACKAGE_NAME ": tegrastats_thread %p stop\n", p_jetson_info);
}

void init_jetson(struct text_object *obj) {
  if (p_jetson_info == nullptr) {
    p_jetson_info = (jetson_info *)malloc(sizeof(jetson_info));
    memset(p_jetson_info, 0, sizeof(jetson_info));
    p_jetson_info->thread = (pthread_t *)malloc(sizeof(pthread_t));
    pthread_create(p_jetson_info->thread, nullptr, tegrastats_thread, p_jetson_info);
    fprintf(stderr, PACKAGE_NAME ": init_jetson %p\n", p_jetson_info);
  }
}

void init_jetson_bar(struct text_object *obj, const char *arg) {
  scan_bar(obj, arg, 100);
  init_jetson(obj);
}

void init_jetson_cpu(struct text_object *obj, const char *arg) {
  int offset = 0;
  sscanf(arg, "%d %n", &obj->data.i, &offset);
  init_jetson(obj);
}

void init_jetson_cpu_bar(struct text_object *obj, const char *arg) {
  int offset = 0;
  sscanf(arg, "%d %n", &obj->data.i, &offset);
  arg += offset;
  init_jetson_bar(obj, arg);
}

void free_jetson(struct text_object *obj) {
  if (p_jetson_info != nullptr) {
    fprintf(stderr, PACKAGE_NAME ": free_jetson %p\n", p_jetson_info);
    p_jetson_info->running = false;
    pthread_join(*(p_jetson_info->thread), nullptr);
    free(p_jetson_info->cpus);
    free(p_jetson_info->ram_lfb);
    free(p_jetson_info->thread);
    free(p_jetson_info);
    p_jetson_info = nullptr;
  }
}

void jetson_fan(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  static int reported = 0;
  FILE *fp;
  if (!(fp = open_file("/sys/devices/pwm-fan/cur_pwm", &reported))) {
      return;
  }
  int value = 0;
  if (fscanf(fp, "%d", &value) >= 0) {
    snprintf(p, p_max_size, "%d%%", value*100/255);
  }
  fclose(fp);
  return;
}

double jetson_fan_barval(struct text_object *obj) {
  static int reported = 0;
  FILE *fp;
  if (!(fp = open_file("/sys/devices/pwm-fan/cur_pwm", &reported))) {
      return 0.;
  }
  int value = 0;
  int rt = fscanf(fp, "%d", &value);
  fclose(fp);
  return value*100./255;
}

void jetson_ram(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%d / %dMB", p_jetson_info->ram_used, p_jetson_info->ram_total);
}

void jetson_ram_usage(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%d%%", p_jetson_info->ram_used * 100 / p_jetson_info->ram_total);
}

void jetson_ram_lfb(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%s", p_jetson_info->ram_lfb);
}

void jetson_swap(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%d / %dMB", p_jetson_info->swap_used, p_jetson_info->swap_total);
}

void jetson_swap_usage(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%d%%", p_jetson_info->swap_used * 100 / p_jetson_info->swap_total);
}

void jetson_swap_cached(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%dMB", p_jetson_info->swap_cached);
}

void jetson_cpu_frq(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  if (obj->data.i < p_jetson_info->cpu_cnt) {
    snprintf(p, p_max_size, "%.1fGHz", p_jetson_info->cpus[obj->data.i].max / 1000.0);
  }
}

double jetson_cpu_barval(struct text_object *obj) {
  if (obj->data.i >= p_jetson_info->cpu_cnt) {
    return 0;
  }
  return p_jetson_info->cpus[obj->data.i].usage;
}

void jetson_emc(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%d%%", p_jetson_info->emc);
}

double jetson_emc_barval(struct text_object *obj) {
  return p_jetson_info->emc;
}

void jetson_gpu(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%d%%", p_jetson_info->gpu);
}

double jetson_gpu_barval(struct text_object *obj) {
  return p_jetson_info->gpu;
}

void jetson_temp_pll(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%.1f°C", p_jetson_info->temp_pll);
}

void jetson_temp_cpu(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%.1f°C", p_jetson_info->temp_cpu);
}

void jetson_temp_wifi(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%.1f°C", p_jetson_info->temp_wifi);
}

void jetson_temp_pmic(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%.1f°C", p_jetson_info->temp_pmic);
}

void jetson_temp_gpu(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%.1f°C", p_jetson_info->temp_gpu);
}

void jetson_temp_ao(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%.1f°C", p_jetson_info->temp_ao);
}

void jetson_temp_thermal(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%.1f°C", p_jetson_info->temp_thermal);
}

void jetson_power_all_cur(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%d", p_jetson_info->power_all_cur);
}

void jetson_power_all_avg(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%d", p_jetson_info->power_all_avg);
}

void jetson_power_gpu_cur(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%d", p_jetson_info->power_gpu_cur);
}

void jetson_power_gpu_avg(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%d", p_jetson_info->power_gpu_avg);
}

void jetson_power_cpu_cur(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%d", p_jetson_info->power_cpu_cur);
}

void jetson_power_cpu_avg(struct text_object *obj, char *p,
                          unsigned int p_max_size) {
  snprintf(p, p_max_size, "%d", p_jetson_info->power_cpu_avg);
}


沒有留言:

張貼留言