Damans227 commented on code in PR #14226:
URL: https://github.com/apache/cloudstack/pull/14226#discussion_r4284795641


##########
plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/linux/KVMHostInfo.java:
##########
@@ -126,55 +125,57 @@ protected static long getCpuSpeed(final String 
cpabilities, final NodeInfo nodeI
             return speed;
         }
 
-        speed = getCpuSpeedFromHostCapabilities(cpabilities);
+        speed = getCpuSpeedFromHostCapabilities(capabilities);
         if(speed > 0L) {
             return speed;
         }
 
-        LOGGER.info(String.format("Using the value [%s] provided by Libvirt.", 
nodeInfo.mhz));
+        LOGGER.info("Using the value [{}] provided by Libvirt.", nodeInfo.mhz);
         speed = nodeInfo.mhz;
         return speed;
     }
 
     private static long getCpuSpeedFromCommandLscpu() {
         long speed = 0L;
         LOGGER.info("Fetching CPU speed from command \"lscpu\".");
+        String command = null;
         try {
-            String command = "lscpu | grep -i 'CPU max MHz' | head -n 1 | sed 
's/^.*: //' | xargs";
+            command = "lscpu | grep -i 'CPU max MHz' | head -n 1 | sed 's/^.*: 
//' | xargs";
             if(isHostS390x()) {
                 command = "lscpu | grep 'CPU dynamic MHz' | cut -d ':' -f 2 | 
tr -d ' ' | awk '{printf \"%.1f\\n\", $1 / 1000}'";
             }
             String result = Script.runSimpleBashScript(command);
             speed = (long) (Float.parseFloat(result));
-            LOGGER.info(String.format("Command [%s] resulted in the value [%s] 
for CPU speed.", command, speed));
+            logCpuSpeedCommandAndSpeed(command, speed);
             return speed;
         } catch (NullPointerException | NumberFormatException e) {
-            LOGGER.error(String.format("Unable to retrieve the CPU speed from 
lscpu."), e);
+            logFailureToGetCpuSpeedAndException(command, e);
         }
+
         try {
-            String command = "lscpu | grep -i 'Model name' | head -n 1 | egrep 
-o '[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'";
+            command = "lscpu | grep -i 'Model name' | head -n 1 | egrep -o 
'[[:digit:]].[[:digit:]]+GHz' | sed 's/GHz//g'";
             if(isHostS390x()) {
                 command = "lscpu | grep 'CPU dynamic MHz' | cut -d ':' -f 2 | 
tr -d ' ' | awk '{printf \"%.1f\\n\", $1 / 1000}'";
             }
             String result = Script.runSimpleBashScript(command);
             speed = (long) (Float.parseFloat(result) * 1000);
-            LOGGER.info(String.format("Command [%s] resulted in the value [%s] 
for CPU speed.", command, speed));
+            logCpuSpeedCommandAndSpeed(command, speed);
             return speed;
         } catch (NullPointerException | NumberFormatException e) {
-            LOGGER.error(String.format("Unable to retrieve the CPU speed from 
lscpu."), e);
+            logFailureToGetCpuSpeedAndException(command, e);
         }
         return speed;
     }
 
     private static long getCpuSpeedFromFile() {
         for (final String cpuInfoFreqFileName:  cpuInfoFreqFileNames) {
-            LOGGER.info(String.format("Fetching CPU speed from file [%s].", 
cpuInfoFreqFileName));
+            LOGGER.info("Fetching CPU speed from file [{}].", 
cpuInfoFreqFileName);
             try (Reader reader = new FileReader(cpuInfoFreqFileName)) {
                 Long cpuInfoFreq = 
Long.parseLong(IOUtils.toString(reader).trim());
-                LOGGER.info(String.format("Retrieved value [%s] from file 
[%s]. This corresponds to a CPU speed of [%s] MHz.", cpuInfoFreq, 
cpuInfoFreqFileName, cpuInfoFreq / 1000));
+                LOGGER.info("Retrieved value [{}] from file [{}]. This 
corresponds to a CPU speed of [{}] MHz.", cpuInfoFreq, cpuInfoFreqFileName, 
cpuInfoFreq / 1000);
                 return cpuInfoFreq / 1000;
             } catch (IOException | NumberFormatException e) {
-                LOGGER.error(String.format("Unable to retrieve the CPU speed 
from file [%s]", cpuInfoFreqFileName), e);
+                LOGGER.error("Unable to retrieve the CPU speed from file 
[{}]", cpuInfoFreqFileName, e);

Review Comment:
   should this one drop to debug too? a lot of hosts dont have base_frequency, 
so it still logs an error with a stack trace when it just moves on to the next 
file



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to