View | Details | Raw Unified | Return to bug 229296 | Differences between
and this patch

Collapse All | Expand All

(-)sysutils/libsysstat/Makefile (+21 lines)
Line 0 Link Here
1
# Created by: Olivier Duchateau
2
# $FreeBSD$
3
4
PORTNAME=	libsysstat
5
PORTVERSION=	0.4.0
6
CATEGORIES=	sysutils
7
MASTER_SITES=	LXQT/${PORTNAME}
8
9
MAINTAINER=	jesper@schmitz.computer
10
COMMENT=	Library used to query system info and statistics
11
12
LICENSE=	LGPL21
13
14
USES=	cmake:outsource lxqt pkgconfig tar:xz
15
USE_QT5=	qmake_build buildtools_build core
16
USE_LXQT=	buildtools
17
18
post-extract:
19
	@${CP} ${FILESDIR}/config.h.in ${WRKSRC};
20
21
.include <bsd.port.mk>
(-)sysutils/libsysstat/distinfo (+3 lines)
Line 0 Link Here
1
TIMESTAMP = 1509028217
2
SHA256 (lxqt/libsysstat-0.4.0.tar.xz) = 8fea723545aeb266f1a998d450aa4c985194b8b79d314817c7c2a78e9b4e996b
3
SIZE (lxqt/libsysstat-0.4.0.tar.xz) = 17716
(-)sysutils/libsysstat/files/config.h.in (+3 lines)
Line 0 Link Here
1
#cmakedefine HAVE_SYSCTL_H
2
#cmakedefine HAVE_IF_H
3
#cmakedefine HAVE_KVM_H
(-)sysutils/libsysstat/files/patch-CMakeLists.txt (+32 lines)
Line 0 Link Here
1
--- CMakeLists.txt.orig	2016-12-10 23:50:29 UTC
2
+++ CMakeLists.txt
3
@@ -23,6 +23,16 @@ include(LXQtCreatePkgConfigFile)
4
 include(LXQtCreatePortableHeaders)
5
 include(LXQtCompilerSettings NO_POLICY_SCOPE)
6
 
7
+include(CheckIncludeFiles)
8
+include(CheckLibraryExists)
9
+
10
+check_include_files("sys/socket.h;net/if.h;net/if_mib.h;net/if_types.h" HAVE_IF_H)
11
+check_library_exists(kvm kvm_getswapinfo "kvm.h" HAVE_KVM_H)
12
+check_library_exists(c sysctlbyname "sys/sysctl.h" HAVE_SYSCTL_H)
13
+
14
+configure_file(config.h.in config.h)
15
+add_definitions("-DHAVE_CONFIG_H=1")
16
+
17
 set(CMAKE_AUTOMOC ON)
18
 set(CMAKE_INCLUDE_CURRENT_DIR ON)
19
 
20
@@ -80,7 +90,11 @@ add_library(${SYSSTAT_LIBRARY_NAME}
21
         ${SYSSTAT_QM_FILES}
22
 )
23
 
24
-target_link_libraries(${SYSSTAT_LIBRARY_NAME} Qt5::Core)
25
+if(HAVE_SYSCTL_H AND HAVE_KVM_H)
26
+    target_link_libraries(${SYSSTAT_LIBRARY_NAME} c kvm Qt5::Core)
27
+else()
28
+    target_link_libraries(${SYSSTAT_LIBRARY_NAME} Qt5::Core)
29
+endif()
30
 
31
 set_target_properties(${SYSSTAT_LIBRARY_NAME} PROPERTIES
32
     VERSION ${SYSSTAT_VERSION}
(-)sysutils/libsysstat/files/patch-cpustat.cpp (+294 lines)
Line 0 Link Here
1
--- cpustat.cpp.orig	2017-09-23 12:46:10 UTC
2
+++ cpustat.cpp
3
@@ -23,15 +23,68 @@
4
 **
5
 ** END_COMMON_COPYRIGHT_HEADER */
6
 
7
-
8
+#ifdef HAVE_CONFIG_H
9
+#include "config.h"
10
+#endif
11
 #include <unistd.h>
12
+#ifdef HAVE_SYSCTL_H
13
+extern "C"
14
+{
15
+    #include <stdlib.h>
16
+    #include <limits.h>
17
+    #include <string.h>
18
+    #include <sys/resource.h> /* CPUSTATES */
19
 
20
+    #include <sys/types.h>
21
+    #include <sys/sysctl.h>
22
+}
23
+#endif
24
 #include "cpustat.h"
25
 #include "cpustat_p.h"
26
 
27
 
28
 namespace SysStat {
29
 
30
+#ifdef HAVE_SYSCTL_H
31
+char *GetFirstFragment(char *string, const char *delim)
32
+{
33
+    char *token = NULL;
34
+
35
+    token = strsep(&string, delim);
36
+    if (token != NULL)
37
+    {
38
+        /* We need only the first fragment, so no loop! */
39
+        return token;
40
+    }
41
+    else
42
+        return NULL;
43
+}
44
+
45
+int GetCpu(void)
46
+{
47
+    static int mib[] = { CTL_HW, HW_NCPU };
48
+    int buf;
49
+    size_t len = sizeof(int);
50
+
51
+    if (sysctl(mib, 2, &buf, &len, NULL, 0) < 0)
52
+        return 0;
53
+    else
54
+        return buf;
55
+}
56
+
57
+/* Frequence is in MHz */
58
+ulong CurrentFreq(void)
59
+{
60
+    ulong freq;
61
+    size_t len = sizeof(freq);
62
+
63
+    if (sysctlbyname("dev.cpu.0.freq", &freq, &len, NULL, 0) < 0)
64
+        return 0;
65
+    else
66
+        return freq;
67
+}
68
+#endif
69
+
70
 CpuStatPrivate::CpuStatPrivate(CpuStat *parent)
71
     : BaseStatPrivate(parent)
72
     , mMonitoring(CpuStat::LoadAndFrequency)
73
@@ -39,7 +92,10 @@ CpuStatPrivate::CpuStatPrivate(CpuStat *
74
     mSource = defaultSource();
75
 
76
     connect(mTimer, SIGNAL(timeout()), SLOT(timeout()));
77
-
78
+#ifdef HAVE_SYSCTL_H
79
+	size_t flen=2;
80
+	sysctlnametomib("kern.cp_times",mib,&flen);
81
+#endif
82
     mUserHz = sysconf(_SC_CLK_TCK);
83
 
84
     updateSources();
85
@@ -47,6 +103,49 @@ CpuStatPrivate::CpuStatPrivate(CpuStat *
86
 
87
 void CpuStatPrivate::addSource(const QString &source)
88
 {
89
+#ifdef HAVE_SYSCTL_H
90
+    char buf[1024];
91
+    char *tokens, *t;
92
+    ulong min = 0, max = 0;
93
+    size_t len = sizeof(buf);
94
+
95
+    /* The string returned by the dev.cpu.0.freq_levels sysctl
96
+     * is a space separated list of MHz/milliwatts.
97
+     */
98
+    if (sysctlbyname("dev.cpu.0.freq_levels", buf, &len, NULL, 0) < 0)
99
+        return;
100
+
101
+    t = strndup(buf, len);
102
+    if (t == NULL)
103
+    {
104
+        free(t);
105
+        return;
106
+    }
107
+
108
+    while ((tokens = strsep(&t, " ")) != NULL)
109
+    {
110
+        char *freq;
111
+        ulong res;
112
+
113
+        freq = GetFirstFragment(tokens, "/");
114
+        if (freq != NULL)
115
+        {
116
+            res = strtoul(freq, &freq, 10);
117
+            if (res > max)
118
+            {
119
+                max = res;
120
+            }
121
+            else
122
+            {
123
+                if ((min == 0) || (res < min))
124
+                    min = res;
125
+            }
126
+        }
127
+    }
128
+
129
+    free(t);
130
+    mBounds[source] = qMakePair(min, max);
131
+#else
132
     bool ok;
133
 
134
     uint min = readAllFile(qPrintable(QString("/sys/devices/system/cpu/%1/cpufreq/scaling_min_freq").arg(source))).toUInt(&ok);
135
@@ -56,11 +155,26 @@ void CpuStatPrivate::addSource(const QSt
136
         if (ok)
137
             mBounds[source] = qMakePair(min, max);
138
     }
139
+#endif
140
 }
141
 
142
 void CpuStatPrivate::updateSources()
143
 {
144
     mSources.clear();
145
+#ifdef HAVE_SYSCTL_H
146
+    int cpu;
147
+
148
+    cpu = GetCpu();
149
+    for (int i =0;i<cpu;i++)
150
+    {
151
+        mSources.append(QString("cpu%1").arg(i));
152
+
153
+
154
+
155
+        addSource(QString("cpu%1").arg(i));
156
+    }
157
+    mBounds.clear();
158
+#else
159
 
160
     foreach (const QString &row, readAllFile("/proc/stat").split(QChar('\n'), QString::SkipEmptyParts))
161
     {
162
@@ -97,6 +211,7 @@ void CpuStatPrivate::updateSources()
163
                 addSource(QString("cpu%1").arg(number));
164
         }
165
     }
166
+#endif
167
 }
168
 
169
 CpuStatPrivate::~CpuStatPrivate()
170
@@ -117,14 +232,98 @@ void CpuStatPrivate::recalculateMinMax()
171
 {
172
     int cores = 1;
173
     if (mSource == "cpu")
174
+#ifdef HAVE_SYSCTL_H
175
+		cores = mSources.size();
176
+#else
177
         cores = mSources.size() - 1;
178
-
179
+#endif
180
     mIntervalMin = static_cast<float>(mTimer->interval()) / 1000 * static_cast<float>(mUserHz) * static_cast<float>(cores) / 1.25; // -25%
181
     mIntervalMax = static_cast<float>(mTimer->interval()) / 1000 * static_cast<float>(mUserHz) * static_cast<float>(cores) * 1.25; // +25%
182
 }
183
 
184
 void CpuStatPrivate::timeout()
185
 {
186
+#ifdef HAVE_SYSCTL_H
187
+    if ( (mMonitoring == CpuStat::LoadOnly)
188
+      || (mMonitoring == CpuStat::LoadAndFrequency) )
189
+    {
190
+        size_t cp_size = sizeof(long) * CPUSTATES * GetCpu();
191
+        long *cp_times = (long *)malloc(cp_size);
192
+        Values current;
193
+        int cpuNumber = mSource.midRef(3).toInt();
194
+        if (sysctl(mib,2, cp_times, &cp_size, NULL, 0) < 0)
195
+            free(cp_times);
196
+
197
+        current.user = static_cast<ulong>(cp_times[CP_USER+cpuNumber*CPUSTATES]);
198
+        current.nice = static_cast<ulong>(cp_times[CP_NICE+cpuNumber*CPUSTATES]);
199
+        current.system = static_cast<ulong>(cp_times[CP_SYS+cpuNumber*CPUSTATES]);
200
+        current.idle = static_cast<ulong>(cp_times[CP_IDLE+cpuNumber*CPUSTATES]);
201
+        current.other = static_cast<ulong>(cp_times[CP_INTR+cpuNumber*CPUSTATES]);
202
+        current.total = current.user + current.nice + current.system+current.idle+current.other;
203
+
204
+        float sumDelta = static_cast<float>(current.total - mPrevious.total);
205
+
206
+        if ((mPrevious.total != 0) && ((sumDelta < mIntervalMin) || (sumDelta > mIntervalMax)))
207
+        {
208
+            if (mMonitoring == CpuStat::LoadAndFrequency)
209
+                emit update(0.0, 0.0, 0.0, 0.0, 0.0, 0);
210
+            else
211
+                emit update(0.0, 0.0, 0.0, 0.0, 0.0);
212
+
213
+            mPrevious.clear();
214
+        }
215
+        else
216
+        {
217
+            if (mMonitoring == CpuStat::LoadAndFrequency)
218
+            {
219
+                ulong freq = 0;
220
+
221
+                freq = CurrentFreq();
222
+                if (freq > 0)
223
+                {
224
+                    emit update(
225
+                        static_cast<float>(current.user - mPrevious.user ) / sumDelta,
226
+                        static_cast<float>(current.nice - mPrevious.nice ) / sumDelta,
227
+                        static_cast<float>(current.system - mPrevious.system ) / sumDelta,
228
+                        static_cast<float>(current.idle - mPrevious.idle ) / sumDelta,
229
+                        static_cast<float>(current.other - mPrevious.other ) / sumDelta,
230
+                        freq);
231
+                }
232
+                else
233
+                {
234
+                    emit update(
235
+                        static_cast<float>(current.user - mPrevious.user ) / sumDelta,
236
+                        static_cast<float>(current.nice - mPrevious.nice ) / sumDelta,
237
+                        static_cast<float>(current.system - mPrevious.system ) / sumDelta,
238
+                        static_cast<float>(current.idle - mPrevious.idle ) / sumDelta,
239
+                        static_cast<float>(current.other - mPrevious.other ) / sumDelta);
240
+                }
241
+            }
242
+            else
243
+            {
244
+
245
+                emit update(
246
+                    static_cast<float>(current.user - mPrevious.user ) / sumDelta,
247
+                    static_cast<float>(current.nice - mPrevious.nice ) / sumDelta,
248
+                    static_cast<float>(current.system - mPrevious.system ) / sumDelta,
249
+                    static_cast<float>(current.idle - mPrevious.idle ) / sumDelta,
250
+                    static_cast<float>(current.other - mPrevious.other ) / sumDelta);
251
+            }
252
+
253
+            mPrevious = current;
254
+        }
255
+
256
+        free(cp_times);
257
+    }
258
+    else
259
+    {
260
+        ulong freq = 0;
261
+
262
+        freq = CurrentFreq();
263
+        if (freq > 0)
264
+            emit update(freq);
265
+    }
266
+#else
267
     if ( (mMonitoring == CpuStat::LoadOnly)
268
       || (mMonitoring == CpuStat::LoadAndFrequency) )
269
     {
270
@@ -258,6 +457,7 @@ void CpuStatPrivate::timeout()
271
         }
272
         emit update(freq);
273
     }
274
+#endif
275
 }
276
 
277
 QString CpuStatPrivate::defaultSource()
278
@@ -301,10 +501,15 @@ CpuStat::CpuStat(QObject *parent)
279
 {
280
     impl = new CpuStatPrivate(this);
281
     baseimpl = impl;
282
-
283
+#ifdef HAVE_SYSCTL_H
284
+    connect(impl, SIGNAL(update(float,float,float,float,float,ulong)), this, SIGNAL(update(float,float,float,float,float,ulong)));
285
+    connect(impl, SIGNAL(update(float,float,float,float,float)), this, SIGNAL(update(float,float,float,float,float)));
286
+    connect(impl, SIGNAL(update(ulong)), this, SIGNAL(update(ulong)));
287
+#else
288
     connect(impl, SIGNAL(update(float,float,float,float,float,uint)), this, SIGNAL(update(float,float,float,float,float,uint)));
289
     connect(impl, SIGNAL(update(float,float,float,float)), this, SIGNAL(update(float,float,float,float)));
290
     connect(impl, SIGNAL(update(uint)), this, SIGNAL(update(uint)));
291
+#endif
292
 }
293
 
294
 CpuStat::~CpuStat()
(-)sysutils/libsysstat/files/patch-cpustat.h (+52 lines)
Line 0 Link Here
1
--- cpustat.h.orig	2016-12-10 23:50:29 UTC
2
+++ cpustat.h
3
@@ -27,6 +27,11 @@
4
 #ifndef LIBSYSSTAT__CPU_STAT__INCLUDED
5
 #define LIBSYSSTAT__CPU_STAT__INCLUDED
6
 
7
+#ifdef HAVE_CONFIG_H
8
+#include "config.h"
9
+#endif
10
+
11
+#include <cstdio>
12
 
13
 #include <QtCore/QObject>
14
 
15
@@ -35,6 +40,12 @@
16
 
17
 namespace SysStat {
18
 
19
+#ifdef HAVE_SYSCTL_H
20
+    char *GetFirstFragment(char *string, const char *delim);
21
+    int GetCpu(void);
22
+    ulong CurrentFreq(void);
23
+#endif
24
+
25
 class CpuStatPrivate;
26
 
27
 class SYSSTATSHARED_EXPORT CpuStat : public BaseStat
28
@@ -52,13 +63,23 @@ public:
29
 
30
     void updateSources();
31
 
32
+#ifdef HAVE_SYSCTL_H
33
     uint minFreq(const QString &source) const;
34
     uint maxFreq(const QString &source) const;
35
 
36
 signals:
37
-    void update(float user, float nice, float system, float other, float frequencyRate, uint frequency);
38
+    void update(float user, float nice, float system, float idle, float other, ulong frequency);
39
+    void update(float user, float nice, float system, float idle, float other);
40
+    void update(ulong frequency);
41
+#else
42
+    ulong minFreq(const QString &source) const;
43
+    ulong maxFreq(const QString &source) const;
44
+
45
+signals:
46
+    void update(float user, float nice, float system, float frequencyRate, uint frequency);
47
     void update(float user, float nice, float system, float other);
48
     void update(uint frequency);
49
+#endif
50
 
51
     void monitoringChanged(Monitoring);
52
 
(-)sysutils/libsysstat/files/patch-cpustat__p.h (+73 lines)
Line 0 Link Here
1
--- cpustat_p.h.orig	2016-12-10 23:50:29 UTC
2
+++ cpustat_p.h
3
@@ -27,6 +27,9 @@
4
 #ifndef LIBSYSSTAT__CPU_STAT__PRIVATE__INCLUDED
5
 #define LIBSYSSTAT__CPU_STAT__PRIVATE__INCLUDED
6
 
7
+#ifdef HAVE_CONFIG_H
8
+#include "config.h"
9
+#endif
10
 
11
 #include <QtCore/QObject>
12
 #include <QtCore/QtGlobal>
13
@@ -52,6 +55,15 @@ public:
14
     CpuStat::Monitoring monitoring() const;
15
     void setMonitoring(CpuStat::Monitoring value);
16
 
17
+#ifdef HAVE_SYSCTL_H
18
+    ulong minFreq(const QString &source) const;
19
+    ulong maxFreq(const QString &source) const;
20
+
21
+signals:
22
+    void update(float user, float nice, float system, float idle, float other);
23
+    void update(ulong frequency);
24
+    void update(float user, float nice, float system, float idle, float other, ulong frequency);
25
+#else
26
     uint minFreq(const QString &source) const;
27
     uint maxFreq(const QString &source) const;
28
 
29
@@ -59,6 +71,7 @@ signals:
30
     void update(float user, float nice, float system, float other);
31
     void update(uint frequency);
32
     void update(float user, float nice, float system, float other, float frequencyRate, uint frequency);
33
+#endif
34
 
35
 private slots:
36
     void timeout();
37
@@ -74,22 +87,35 @@ private:
38
     {
39
         Values();
40
 
41
+#ifdef HAVE_SYSCTL_H
42
+        ulong user;
43
+        ulong nice;
44
+        ulong system;
45
+        ulong idle;
46
+        ulong other;
47
+        ulong total;
48
+#else
49
         qulonglong user;
50
         qulonglong nice;
51
         qulonglong system;
52
         qulonglong idle;
53
         qulonglong other;
54
         qulonglong total;
55
+#endif
56
 
57
         void sum();
58
 
59
         void clear();
60
     } Values;
61
     Values mPrevious;
62
-
63
+    int mib[2];
64
     CpuStat::Monitoring mMonitoring;
65
 
66
+#ifdef HAVE_SYSCTL_H
67
+    typedef QMap<QString, QPair<ulong, ulong> > Bounds;
68
+#else
69
     typedef QMap<QString, QPair<uint, uint> > Bounds;
70
+#endif
71
     Bounds mBounds;
72
 
73
     int mUserHz;
(-)sysutils/libsysstat/files/patch-memstat.cpp (+134 lines)
Line 0 Link Here
1
--- memstat.cpp.orig	2016-12-10 23:50:29 UTC
2
+++ memstat.cpp
3
@@ -23,6 +23,24 @@
4
 **
5
 ** END_COMMON_COPYRIGHT_HEADER */
6
 
7
+#ifdef HAVE_CONFIG_H
8
+#include "config.h"
9
+#endif
10
+
11
+#include <cstdio>
12
+
13
+#if defined(HAVE_KVM_H) && defined(HAVE_SYSCTL_H)
14
+extern "C"
15
+{
16
+    #include <paths.h>
17
+    #include <unistd.h>
18
+    #include <fcntl.h>
19
+
20
+    #include <kvm.h>
21
+    #include <sys/types.h>
22
+    #include <sys/sysctl.h>
23
+}
24
+#endif
25
 
26
 #include "memstat.h"
27
 #include "memstat_p.h"
28
@@ -30,6 +48,45 @@
29
 
30
 namespace SysStat {
31
 
32
+#ifdef HAVE_SYSCTL_H
33
+int SwapDevices()
34
+{
35
+    int buf;
36
+    size_t len = sizeof(int);
37
+
38
+    if (sysctlbyname("vm.nswapdev", &buf, &len, NULL, 0) < 0)
39
+        return 0;
40
+    else
41
+        return buf;
42
+}
43
+
44
+qulonglong MemGetByBytes(QString property)
45
+{
46
+    qulonglong buf=0;
47
+    size_t len = sizeof(qulonglong);
48
+
49
+    std::string s = property.toStdString();
50
+    const char *name = s.c_str();
51
+
52
+    if (sysctlbyname(name, &buf, &len, NULL, 0) < 0)
53
+        return 0;
54
+    else
55
+        return buf;
56
+}
57
+
58
+qulonglong MemGetByPages(QString name)
59
+{
60
+    qulonglong res = 0;
61
+
62
+
63
+    res = MemGetByBytes(name);
64
+    if (res > 0)
65
+        res = res * getpagesize();
66
+
67
+    return res;
68
+}
69
+#endif
70
+
71
 MemStatPrivate::MemStatPrivate(MemStat *parent)
72
     : BaseStatPrivate(parent)
73
 {
74
@@ -51,6 +108,40 @@ void MemStatPrivate::timeout()
75
     qulonglong memBuffers = 0;
76
     qulonglong memCached = 0;
77
     qulonglong swapTotal = 0;
78
+
79
+#ifdef HAVE_SYSCTL_H
80
+    memTotal = MemGetByBytes("hw.physmem");
81
+    memFree = MemGetByPages("vm.stats.vm.v_free_count");
82
+    memBuffers = MemGetByBytes("vfs.bufspace");
83
+    memCached = MemGetByPages("vm.stats.vm.v_inactive_count");
84
+#endif
85
+
86
+#ifdef HAVE_KVM_H
87
+    qulonglong swapUsed = 0;
88
+    kvm_t *kd;
89
+    struct kvm_swap kswap[16]; /* size taken from pstat/pstat.c */
90
+
91
+    kd = kvm_open(NULL, _PATH_DEVNULL, NULL, O_RDONLY, "kvm_open");
92
+    if (kd == NULL)
93
+        kvm_close(kd);
94
+
95
+    if (kvm_getswapinfo(kd, kswap, (sizeof(kswap) / sizeof(kswap[0])), SWIF_DEV_PREFIX) > 0)
96
+    {
97
+        int swapd = SwapDevices();
98
+        /* TODO: loop over swap devives */
99
+        if (swapd >= 1)
100
+        {
101
+            swapTotal = static_cast<qulonglong>(kswap[0].ksw_total * getpagesize());
102
+            swapUsed = static_cast<qulonglong>(kswap[0].ksw_used * getpagesize());
103
+        }
104
+
105
+        kvm_close(kd);
106
+    }
107
+    else
108
+        kvm_close(kd);
109
+#endif
110
+
111
+#ifndef HAVE_SYSCTL_H
112
     qulonglong swapFree = 0;
113
 
114
     foreach (QString row, readAllFile("/proc/meminfo").split(QChar('\n'), QString::SkipEmptyParts))
115
@@ -72,6 +163,7 @@ void MemStatPrivate::timeout()
116
         else if(tokens[0] == "SwapFree:")
117
             swapFree = tokens[1].toULong();
118
     }
119
+#endif
120
 
121
     if (mSource == "memory")
122
     {
123
@@ -89,7 +181,11 @@ void MemStatPrivate::timeout()
124
     {
125
         if (swapTotal)
126
         {
127
+#ifndef HAVE_KVM_H
128
             float swapUsed_d = static_cast<float>(swapTotal - swapFree) / static_cast<float>(swapTotal);
129
+#else
130
+            float swapUsed_d = static_cast<float>(swapUsed) / static_cast<float>(swapTotal);
131
+#endif
132
 
133
             emit swapUpdate(swapUsed_d);
134
         }
(-)sysutils/libsysstat/files/patch-memstat.h (+25 lines)
Line 0 Link Here
1
--- memstat.h.orig	2016-12-10 23:50:29 UTC
2
+++ memstat.h
3
@@ -27,6 +27,9 @@
4
 #ifndef LIBSYSSTAT__MEM_STAT__INCLUDED
5
 #define LIBSYSSTAT__MEM_STAT__INCLUDED
6
 
7
+#ifdef HAVE_CONFIG_H
8
+#include "config.h"
9
+#endif
10
 
11
 #include <QtCore/QObject>
12
 
13
@@ -35,6 +38,12 @@
14
 
15
 namespace SysStat {
16
 
17
+#if defined(HAVE_SYSCTL_H) && defined(HAVE_KVM_H)
18
+    int SwapDevices();
19
+    qulonglong MemGetByBytes(const QString property);
20
+    qulonglong MemGetByPages(const QString property);
21
+#endif
22
+
23
 class MemStatPrivate;
24
 
25
 class SYSSTATSHARED_EXPORT MemStat : public BaseStat
(-)sysutils/libsysstat/files/patch-netstat.cpp (+125 lines)
Line 0 Link Here
1
--- netstat.cpp.orig	2016-12-10 23:50:29 UTC
2
+++ netstat.cpp
3
@@ -23,6 +23,23 @@
4
 **
5
 ** END_COMMON_COPYRIGHT_HEADER */
6
 
7
+#ifdef HAVE_CONFIG_H
8
+#include "config.h"
9
+#endif
10
+
11
+#include <cstdio>
12
+
13
+#if defined(HAVE_SYSCTL_H) && defined(HAVE_IF_H)
14
+extern "C"
15
+{
16
+    #include <net/if.h>
17
+    #include <net/if_mib.h>
18
+    #include <net/if_types.h>
19
+    #include <sys/socket.h> /* PF_LINK */
20
+    #include <sys/types.h>
21
+    #include <sys/sysctl.h>
22
+}
23
+#endif
24
 
25
 #include "netstat.h"
26
 #include "netstat_p.h"
27
@@ -37,7 +54,7 @@ NetStatPrivate::NetStatPrivate(NetStat *
28
 
29
     connect(mTimer, SIGNAL(timeout()), SLOT(timeout()));
30
 
31
-
32
+#ifndef HAVE_SYSCTL_H
33
     QStringList rows(readAllFile("/proc/net/dev").split(QChar('\n'), QString::SkipEmptyParts));
34
 
35
     rows.erase(rows.begin(), rows.begin() + 2);
36
@@ -50,6 +67,30 @@ NetStatPrivate::NetStatPrivate(NetStat *
37
 
38
         mSources.append(tokens[0].trimmed());
39
     }
40
+#else
41
+    int count;
42
+    size_t len;
43
+    int cntifmib[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_SYSTEM, IFMIB_IFCOUNT };// net.link.generic.system.ifcount;
44
+    len = sizeof(int);
45
+    if (sysctl(cntifmib, 5, &count, &len, NULL, 0) < 0)
46
+        perror("sysctl");
47
+
48
+
49
+    struct ifmibdata ifmd;
50
+    size_t len1 = sizeof(ifmd);
51
+    for (int i=1; i<=count;i++) {
52
+        int name[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_IFDATA, i, IFDATA_GENERAL };
53
+
54
+        if (sysctl(name, 6, &ifmd, &len1, NULL, 0) < 0) {
55
+            perror("sysctl");
56
+        }
57
+        if ((ifmd.ifmd_data.ifi_type == IFT_ETHER) || (ifmd.ifmd_data.ifi_type == IFT_IEEE80211)) {
58
+        const char *iface = ifmd.ifmd_name;
59
+        mSources.append(QString::fromLatin1(iface));
60
+        }
61
+    }
62
+
63
+#endif
64
 }
65
 
66
 NetStatPrivate::~NetStatPrivate()
67
@@ -58,6 +99,50 @@ NetStatPrivate::~NetStatPrivate()
68
 
69
 void NetStatPrivate::timeout()
70
 {
71
+#if defined(HAVE_IF_H) && defined(HAVE_SYSCTL_H)
72
+    int count;
73
+    size_t len;
74
+    int name[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_SYSTEM, IFMIB_IFCOUNT };
75
+    struct ifmibdata ifmd;
76
+
77
+    len = sizeof(int);
78
+    if (sysctl(name, 5, &count, &len, NULL, 0) < 0)
79
+        return;
80
+
81
+    for (int i = 1; i <= count; i++)
82
+    {
83
+        len = sizeof(ifmd);
84
+        int name[] = { CTL_NET, PF_LINK, NETLINK_GENERIC, IFMIB_IFDATA, i, IFDATA_GENERAL };
85
+
86
+        if (sysctl(name, 6, &ifmd, &len, NULL, 0) < 0)
87
+            break;
88
+
89
+        if ((ifmd.ifmd_data.ifi_type == IFT_ETHER) || (ifmd.ifmd_data.ifi_type == IFT_IEEE80211))
90
+        {
91
+            const char *iface = ifmd.ifmd_name;
92
+            QString interfaceName = QString::fromLatin1(iface);
93
+            if ((ifmd.ifmd_data.ifi_link_state == LINK_STATE_UP) && (ifmd.ifmd_data.ifi_ipackets > 0))
94
+            {
95
+
96
+
97
+                Values current;
98
+                current.received = ifmd.ifmd_data.ifi_ibytes;
99
+                current.transmitted = ifmd.ifmd_data.ifi_obytes;
100
+
101
+                if (!mPrevious.contains(interfaceName))
102
+                    mPrevious.insert(interfaceName, Values());
103
+                const Values &previous = mPrevious[interfaceName];
104
+
105
+                if (interfaceName == mSource)
106
+                    emit update((( current.received - previous.received ) * 1000 ) / mTimer->interval(), (( current.transmitted - previous.transmitted ) * 1000 ) / mTimer->interval());
107
+
108
+                mPrevious[interfaceName] = current;
109
+            } else if(interfaceName == mSource)
110
+                emit(update(0,0));
111
+
112
+        }
113
+    }
114
+#else
115
     QStringList rows(readAllFile("/proc/net/dev").split(QChar('\n'), QString::SkipEmptyParts));
116
 
117
 
118
@@ -99,6 +184,7 @@ void NetStatPrivate::timeout()
119
 
120
         mPrevious[interfaceName] = current;
121
     }
122
+#endif
123
 }
124
 
125
 QString NetStatPrivate::defaultSource()
(-)sysutils/libsysstat/pkg-descr (+4 lines)
Line 0 Link Here
1
Qt-based library to query system information like CPU, memory usage and
2
network traffic.
3
4
WWW: http://lxqt.org/
(-)sysutils/libsysstat/pkg-plist (+20 lines)
Line 0 Link Here
1
include/sysstat-qt5/SysStat/BaseStat
2
include/sysstat-qt5/SysStat/CpuStat
3
include/sysstat-qt5/SysStat/Global
4
include/sysstat-qt5/SysStat/MemStat
5
include/sysstat-qt5/SysStat/NetStat
6
include/sysstat-qt5/SysStat/Version
7
include/sysstat-qt5/basestat.h
8
include/sysstat-qt5/cpustat.h
9
include/sysstat-qt5/memstat.h
10
include/sysstat-qt5/netstat.h
11
include/sysstat-qt5/sysstat_global.h
12
include/sysstat-qt5/version.h
13
lib/libsysstat-qt5.so
14
lib/libsysstat-qt5.so.0
15
lib/libsysstat-qt5.so.%%VERSION%%
16
libdata/pkgconfig/sysstat-qt5.pc
17
share/cmake/sysstat-qt5/sysstat-qt5-config-version.cmake
18
share/cmake/sysstat-qt5/sysstat-qt5-config.cmake
19
share/cmake/sysstat-qt5/sysstat-qt5-targets-%%CMAKE_BUILD_TYPE%%.cmake
20
share/cmake/sysstat-qt5/sysstat-qt5-targets.cmake

Return to bug 229296