You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2021/06/07 15:20:39 UTC

[GitHub] [nifi-minifi-cpp] lordgamez commented on a change in pull request #1101: MINIFICPP-1557 Fix CPU usage percentage calculation and extend verification

lordgamez commented on a change in pull request #1101:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1101#discussion_r646695046



##########
File path: extensions/http-curl/tests/HTTPHandlers.h
##########
@@ -422,11 +423,15 @@ class HeartbeatHandler : public ServerAwareHandler {
 
   void verify(struct mg_connection *conn) {
     auto post_data = readPayload(conn);
+    if (!isServerRunning()) {
+      return;
+    }
     if (!IsNullOrEmpty(post_data)) {
       rapidjson::Document root;
-      rapidjson::ParseResult ok = root.Parse(post_data.data(), post_data.size());
-      assert(ok);
-      (void)ok;  // unused in release builds
+      rapidjson::ParseResult result = root.Parse(post_data.data(), post_data.size());
+      if (!result) {
+        throw std::runtime_error("JSON parse error: " + std::string(rapidjson::GetParseError_En(result.Code())) + "\n JSON data: " + post_data);

Review comment:
       Updated in a199f6907d09938d30af9fe21b65ffc0e5116cb2

##########
File path: libminifi/src/utils/ProcessCpuUsageTracker.cpp
##########
@@ -126,7 +127,7 @@ double ProcessCpuUsageTracker::getProcessCpuUsageBetweenLastTwoQueries() const {
   uint64_t sys_cpu_times_diff = sys_cpu_times_ - previous_sys_cpu_times_;
   uint64_t user_cpu_times_diff = user_cpu_times_ - previous_user_cpu_times_;
   double percent = static_cast<double>(sys_cpu_times_diff + user_cpu_times_diff) / static_cast<double>(cpu_times_diff);
-  percent = percent / std::thread::hardware_concurrency();
+  percent = percent / (std::max)(static_cast<uint32_t>(1), std::thread::hardware_concurrency());

Review comment:
       Updated in a199f6907d09938d30af9fe21b65ffc0e5116cb2




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org