View | Details | Raw Unified | Return to bug 246929
Collapse All | Expand All

(-)Makefile (-2 / +2 lines)
Lines 2-8 Link Here
2
# $FreeBSD$
2
# $FreeBSD$
3
3
4
PORTNAME=	ntopng
4
PORTNAME=	ntopng
5
PORTVERSION=	4.0.d20200530
5
PORTVERSION=	4.0.d20200608
6
PORTEPOCH=	1
6
PORTEPOCH=	1
7
CATEGORIES=	net
7
CATEGORIES=	net
8
8
Lines 36-42 Link Here
36
36
37
USE_GITHUB=	yes
37
USE_GITHUB=	yes
38
GH_ACCOUNT=	ntop
38
GH_ACCOUNT=	ntop
39
GH_TAGNAME=	66a6a44
39
GH_TAGNAME=	a020c6e
40
40
41
CPE_VENDOR=	ntop
41
CPE_VENDOR=	ntop
42
42
(-)distinfo (-3 / +3 lines)
Lines 1-3 Link Here
1
TIMESTAMP = 1590935345
1
TIMESTAMP = 1591913842
2
SHA256 (ntop-ntopng-4.0.d20200530-66a6a44_GH0.tar.gz) = ee56a7418d46c40e5375dde963fd06d773c0c8237b77cab1208c93e8e525f85c
2
SHA256 (ntop-ntopng-4.0.d20200608-a020c6e_GH0.tar.gz) = df14f9ac370212e01dbef38f06d6837f9476bc76adaa688d2fa65fa47e6d26d4
3
SIZE (ntop-ntopng-4.0.d20200530-66a6a44_GH0.tar.gz) = 43398672
3
SIZE (ntop-ntopng-4.0.d20200608-a020c6e_GH0.tar.gz) = 43401037
(-)files/patch-fix-CPU-usage (+117 lines)
Line 0 Link Here
1
diff --git a/include/Utils.h b/include/Utils.h
2
index 75238911d..1b584883d 100755
3
--- include/Utils.h
4
+++ include/Utils.h
5
@@ -58,6 +58,7 @@ public:
6
   static u_int32_t hashString(const char * const s);
7
   static float timeval2ms(struct timeval *tv);
8
   static float msTimevalDiff(const struct timeval *end, const struct timeval *begin);
9
+  static u_int32_t usecTimevalDiff(const struct timeval *end, const struct timeval *begin);
10
   static size_t file_write(const char *path, const char *content, size_t content_len);
11
   static size_t file_read(const char *path, char **content);
12
   static bool file_exists(const char * const path);
13
diff --git a/src/Ntop.cpp b/src/Ntop.cpp
14
index 5ca6a1f69..3cdfda3b1 100644
15
--- src/Ntop.cpp
16
+++ src/Ntop.cpp
17
@@ -547,7 +547,7 @@ void Ntop::start() {
18
   _usleep((5 - begin.tv_sec % 5) * 1e6 - begin.tv_usec);
19
 
20
   while((!globals->isShutdown()) && (!globals->isShutdownRequested())) {
21
-    u_long nap = ntop->getPrefs()->get_housekeeping_frequency() * 1e6;
22
+    const u_int32_t nap_usec = ntop->getPrefs()->get_housekeeping_frequency() * 1e6;
23
 
24
     gettimeofday(&begin, NULL);
25
 
26
@@ -566,35 +566,39 @@ void Ntop::start() {
27
 
28
     runHousekeepingTasks();
29
 
30
+#ifndef __linux__
31
+    gettimeofday(&end, NULL);
32
+    
33
+    usec_diff = Utils::usecTimevalDiff(&end, &begin);
34
+
35
+    if(usec_diff < nap_usec)
36
+      _usleep(nap_usec-usec_diff);
37
+#else
38
     do {
39
       gettimeofday(&end, NULL);
40
+      usec_diff = Utils::usecTimevalDiff(&end, &begin);
41
 
42
-      usec_diff = (end.tv_sec * 1e6) + end.tv_usec - (begin.tv_sec * 1e6) - begin.tv_usec;
43
-
44
-      if(usec_diff < nap) {
45
+      if(usec_diff < nap_usec) {
46
         int maxfd = 0;
47
         fd_set rset;
48
         struct timeval tv;
49
 
50
 #if 0
51
-        ntop->getTrace()->traceEvent(TRACE_DEBUG,
52
+        ntop->getTrace()->traceEvent(TRACE_NORMAL,
53
             "Sleeping %i microsecods before doing the chores.",
54
-            (nap - usec_diff));
55
+            (nap_usec - usec_diff));
56
 #endif
57
 
58
         FD_ZERO(&rset);
59
 
60
-#ifdef __linux__
61
         if(inotify_fd > 0) {
62
           FD_SET(inotify_fd, &rset);
63
           maxfd = inotify_fd;
64
         }
65
-#endif
66
 
67
-        tv.tv_sec = 0, tv.tv_usec = (nap - usec_diff);
68
+        tv.tv_sec = 0, tv.tv_usec = (nap_usec - usec_diff);
69
 
70
         if(select(maxfd + 1, &rset, NULL, NULL, &tv) > 0) {
71
-#ifdef __linux__
72
           if(FD_ISSET(inotify_fd, &rset)) {
73
             char buffer[EVENT_BUF_LEN];
74
 
75
@@ -604,10 +608,10 @@ void Ntop::start() {
76
             ntop->getTrace()->traceEvent(TRACE_DEBUG, "Directory changed");
77
             reloadPeriodicScripts();
78
           }
79
-#endif
80
         }
81
       }
82
-    } while(usec_diff < nap);
83
+    } while(usec_diff < nap_usec);
84
+#endif    
85
   }
86
 }
87
 
88
diff --git a/src/Utils.cpp b/src/Utils.cpp
89
index 4761c843f..4e3b50fc2 100755
90
--- src/Utils.cpp
91
+++ src/Utils.cpp
92
@@ -436,6 +436,25 @@ u_int32_t Utils::timeval2usec(const struct timeval *tv) {
93
 
94
 /* ****************************************************** */
95
 
96
+u_int32_t Utils::usecTimevalDiff(const struct timeval *end, const struct timeval *begin) {
97
+  if((end->tv_sec == 0) && (end->tv_usec == 0))
98
+    return(0);
99
+  else {
100
+    struct timeval res;
101
+    
102
+    res.tv_sec = end->tv_sec - begin->tv_sec;
103
+    if(begin->tv_usec > end->tv_usec) {
104
+      res.tv_usec = end->tv_usec + 1000000 - begin->tv_usec;
105
+      res.tv_sec--;
106
+    } else
107
+      res.tv_usec = end->tv_usec - begin->tv_usec;
108
+
109
+    return((res.tv_sec*1000000) + (res.tv_usec));
110
+  }
111
+}
112
+
113
+/* ****************************************************** */
114
+
115
 float Utils::msTimevalDiff(const struct timeval *end, const struct timeval *begin) {
116
   if((end->tv_sec == 0) && (end->tv_usec == 0))
117
     return(0);

Return to bug 246929