JeVois  1.20
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
SysInfo.C
Go to the documentation of this file.
1 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 //
3 // JeVois Smart Embedded Machine Vision Toolkit - Copyright (C) 2016 by Laurent Itti, the University of Southern
4 // California (USC), and iLab at USC. See http://iLab.usc.edu and http://jevois.org for information about this project.
5 //
6 // This file is part of the JeVois Smart Embedded Machine Vision Toolkit. This program is free software; you can
7 // redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software
8 // Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
9 // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
10 // License for more details. You should have received a copy of the GNU General Public License along with this program;
11 // if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
12 //
13 // Contact information: Laurent Itti - 3641 Watt Way, HNB-07A - Los Angeles, CA 90089-2520 - USA.
14 // Tel: +1 213 740 3527 - itti@pollux.usc.edu - http://iLab.usc.edu - http://jevois.org
15 // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
16 /*! \file */
17 
18 #include <jevois/Debug/SysInfo.H>
19 #include <jevois/Util/Utils.H>
20 #include <fstream>
21 #include <algorithm>
22 
23 // ####################################################################################################
24 std::string jevois::getSysInfoCPU()
25 {
26 #ifdef JEVOIS_PLATFORM_PRO
27  // One JeVois Pro, use cpu 2 (big core) and thermal zone 1:
28  int freq = 2208;
29  try { freq = std::stoi(jevois::getFileString("/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq")) / 1000; }
30  catch (...) { } // silently ignore any errors
31 
32  int temp = 30;
33  try { temp = std::stoi(jevois::getFileString("/sys/class/thermal/thermal_zone1/temp")); }
34  catch (...) { } // silently ignore any errors
35 #else
36  int freq = 1344;
37  try { freq = std::stoi(jevois::getFileString("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq")) / 1000; }
38  catch (...) { } // silently ignore any errors
39 
40  int temp = 30;
41  try { temp = std::stoi(jevois::getFileString("/sys/class/thermal/thermal_zone0/temp")); }
42  catch (...) { } // silently ignore any errors
43 #endif
44 
45  // On some hosts, temp is in millidegrees:
46  if (temp > 200) temp /= 1000;
47 
48  std::string load = jevois::getFileString("/proc/loadavg");
49  return "CPU: " + std::to_string(freq) + "MHz, " + std::to_string(temp) + "C, load: " + load;
50 }
51 
52 // ####################################################################################################
53 namespace
54 {
55  // from http://stackoverflow.com/questions/8362094/replace-multiple-spaces-with-one-space-in-a-string
56  bool BothAreSpaces(char lhs, char rhs) { return (lhs == rhs) && (lhs == ' '); }
57 
58  void cleanSpaces(std::string & str)
59  {
60  std::string::iterator new_end = std::unique(str.begin(), str.end(), BothAreSpaces);
61  str.erase(new_end, str.end());
62  }
63 }
64 
65 // ####################################################################################################
66 std::string jevois::getSysInfoMem()
67 {
68  std::string memtotal = jevois::getFileString("/proc/meminfo"); cleanSpaces(memtotal);
69  std::string memfree = jevois::getFileString("/proc/meminfo", 1); cleanSpaces(memfree);
70  return memtotal + ", " + memfree;
71 }
72 
73 // ####################################################################################################
75 {
76  std::string ver = jevois::getFileString("/proc/version");
77 
78  // Truncate at "Linux Version XXX":
79  size_t pos = ver.find(' ');
80  pos = ver.find(' ', pos + 1);
81  pos = ver.find(' ', pos + 1);
82 
83  return ver.substr(0, pos);
84 }
85 
86 // ####################################################################################################
88 {
89  size_t n = 0;
90 
91  // First detect any PCIe accelerators:
92  while (true)
93  {
94  try { jevois::getFileString(("/sys/class/apex/apex_" + std::to_string(n) + "/temp").c_str()); }
95  catch (...) { break; }
96  ++n;
97  }
98 
99  // Then detect any USB accelerators:
100  // Note: reported name and USB ID in lsusb changes once we start using the device...
101  // Before running a network: ID 1a6e:089a Global Unichip Corp.
102  // After running a network: ID 18d1:9302 Google Inc.
103 
104  try { n += std::stoi(jevois::system("/usr/bin/lsusb | /usr/bin/grep 1a6e:089a | /usr/bin/wc -l")); } catch (...) { }
105 
106  try { n += std::stoi(jevois::system("/usr/bin/lsusb | /usr/bin/grep 18d1:9302 | /usr/bin/wc -l")); } catch (...) { }
107 
108  return n;
109 }
110 
111 // ####################################################################################################
113 {
114  // Note: reported name and USB ID in lsusb changes once we start using the device...
115  // Before running a network: ID 03e7:2485 Intel Movidius MyriadX
116  // After running a network: ID 03e7:f63b Myriad VPU [Movidius Neural Compute Stick]
117  size_t n = 0;
118 
119  try { n += std::stoi(jevois::system("/usr/bin/lsusb | /usr/bin/grep 03e7:2485 | /usr/bin/wc -l")); } catch (...) { }
120 
121  try { n += std::stoi(jevois::system("/usr/bin/lsusb | /usr/bin/grep 03e7:f63b | /usr/bin/wc -l")); } catch (...) { }
122 
123  return n;
124 }
125 
126 // ####################################################################################################
128 {
129  // Note: could also check /proc/cpuinfo to get the NPU hardware version
130 #ifdef JEVOIS_PLATFORM_PRO
131  return 1;
132 #else
133  return 0;
134 #endif
135 }
136 
137 // ####################################################################################################
139 {
140  size_t n = 0;
141 
142  while (true)
143  {
144  try { jevois::getFileString(("/sys/class/hailo_chardev/hailo" + std::to_string(n) + "/device_id").c_str()); }
145  catch (...) { break; }
146  ++n;
147  }
148 
149  return n;
150 }
151 
152 // ####################################################################################################
154 {
155 #ifdef JEVOIS_PLATFORM_PRO
156  try
157  {
158  int period = std::stoi(jevois::getFileString("/sys/class/pwm/pwmchip8/pwm0/period"));
159  int duty = std::stoi(jevois::getFileString("/sys/class/pwm/pwmchip8/pwm0/duty_cycle"));
160  if (period == 0) return 100;
161  return 100 * duty / period;
162  }
163  catch (...) { }
164 #endif
165 
166  return 0;
167 }
jevois::getFanSpeed
int getFanSpeed()
Get fan speed in percent, only meaningful on JeVois-Pro Platform, all others return 0.
Definition: SysInfo.C:153
jevois::getSysInfoMem
std::string getSysInfoMem()
Get memory info.
Definition: SysInfo.C:66
jevois::getFileString
std::string getFileString(char const *fname, int skip=0)
Read one line from a file and return it as a string.
Definition: Utils.C:541
jevois::getSysInfoVersion
std::string getSysInfoVersion()
Get O.S. version info.
Definition: SysInfo.C:74
jevois::getNumInstalledNPUs
size_t getNumInstalledNPUs()
Get the number of JeVois-Pro NPUs present on this system.
Definition: SysInfo.C:127
jevois::getSysInfoCPU
std::string getSysInfoCPU()
Get CPU info: frequency, thermal, load.
Definition: SysInfo.C:24
jevois::system
std::string system(std::string const &cmd, bool errtoo=true)
Execute a command and grab stdout output to a string.
Definition: Utils.C:461
SysInfo.H
jevois::getNumInstalledTPUs
size_t getNumInstalledTPUs()
Get the number of Coral TPUs present on this system.
Definition: SysInfo.C:87
jevois::getNumInstalledSPUs
size_t getNumInstalledSPUs()
Get the number of Hailo8 SPUs present on this system.
Definition: SysInfo.C:138
jevois::getNumInstalledVPUs
size_t getNumInstalledVPUs()
Get the number of Myriad-X VPUs present on this system.
Definition: SysInfo.C:112
jevois::to_string
std::string to_string(T const &val)
Convert from type to string.
Utils.H