Skip to content

Commit

Permalink
Fixed Memory Tab, new functions using inex-usage Library libgtop2
Browse files Browse the repository at this point in the history
  • Loading branch information
eloaders committed Jan 20, 2014
1 parent 9dc677f commit 765ab4d
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 66 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PKG_INSTALL = apt-get install
AS_ROOT = sudo
CFLAGS = -g -Wall
CC_OPTS_LIBCPUID = $(shell pkg-config libcpuid --cflags --libs)
CC_OPTS_LIBGTOP = $(shell pkg-config libgtop-2.0 --cflags --libs)
GBC = /usr/bin/gbc3
GBCOPTS = -eagtpmv
GBA = gba3
Expand Down Expand Up @@ -51,12 +52,13 @@ dependency_build ?= git \
x11-utils \
mesa-utils \
hostname \
libcpuid11
libcpuid11 \
libgtop2-dev

make:
@printf "\033[1;31mCompile edid-decode as inex-decode \033[0m$1\n"
$(CC) -o inex-edid edid-decode.c $(CFLAGS) $(additional_confflags)
$(CC) -o inex-usage getusage.c $(CFLAGS) $(additional_confflags)
$(CC) -o inex-usage getusage.c $(CC_OPTS_LIBGTOP) $(additional_confflags)
$(CC) -o inex-cpuid cpu.c -static $(CC_OPTS_LIBCPUID) $(additional_confflags)
@printf "\033[1;31mCompile src/i-nex stage 1 \033[0m$1\n"
$(GBC) $(GBCOPTS) src/i-nex
Expand Down
5 changes: 3 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Build-Depends: debhelper (>= 7),
pkg-config, dpkg-dev (>= 1.14.17),
debhelper (>= 5.0.0),
libcpuid11,
libgtop2-dev (>= 2.22.3),
gambas3-dev (>= 3.0.90),
gambas3-dev (<< 3.99.0),
gambas3-gb-image (>= 3.0.90),
Expand Down Expand Up @@ -48,9 +49,9 @@ Depends: ${shlibs:Depends},
gambas3-gb-desktop (>= 3.0.90),
gambas3-gb-desktop (<< 3.99.0),
gambas3-gb-form-stock (>= 3.4.0),
dpkg (>= 1.15), grep (>= 2.5),
libgtop2-7 (>= 2.22.3),
grep (>= 2.5),
mount (>= 2.17),
procps,
x11-xserver-utils (>= 7.5),
lsb-release (>= 4.0),
bash (>= 4.1),
Expand Down
70 changes: 53 additions & 17 deletions getusage.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,63 @@
#include <unistd.h>
#include <malloc.h>
#include <sys/sysinfo.h>
#include <stdio.h>
#include <glibtop.h>
#include <glibtop/cpu.h>
#include <glibtop/mem.h>
#include <glibtop/proclist.h>
get_cpu(glibtop_cpu *cpustruct) {
glibtop_get_cpu(cpustruct);
return 100 - (float)cpustruct->idle / (float)cpustruct->total * 100;
}
int main() {
int days, hours, mins;
struct sysinfo sys_info;
struct mallinfo sys_infoggg;
if(sysinfo(&sys_info) != 0)
perror("sysinfo");
long long physMemUsed = sys_info.totalram - sys_info.freeram;
//Multiply in next statement to avoid int overflow on right hand side...
physMemUsed *= sys_info.mem_unit;
long long totalVirtualMem = sys_info.totalram;
//Add other values in next statement to avoid int overflow on right hand side...
glibtop_init();
glibtop_cpu cpu;
glibtop_mem memory;
glibtop_proclist proclist;
glibtop_get_cpu (&cpu);
glibtop_get_mem(&memory);
glibtop_cpu cpustruct;

struct sysinfo sys_info;

long long physMemUsed = sys_info.totalram - sys_info.freeram;
long long totalVirtualMem = sys_info.totalram;
unsigned long total_bytes;
unsigned int sleepfor = 5000;
int days, hours, mins;
float usagess;

usagess = get_cpu(&cpustruct);

if(sysinfo(&sys_info) != 0)
perror("sysinfo");

physMemUsed *= sys_info.mem_unit;
totalVirtualMem += sys_info.totalswap;
totalVirtualMem *= sys_info.mem_unit;
unsigned long total_bytes;
total_bytes = sys_info.mem_unit * sys_info.totalram;
days = sys_info.uptime / 86400;
hours = (sys_info.uptime / 3600) - (days * 24);
mins = (sys_info.uptime / 60) - (days * 1440) - (hours * 60);
total_bytes = sys_info.mem_unit * sys_info.totalram;

days = sys_info.uptime / 86400;
hours = (sys_info.uptime / 3600) - (days * 24);
mins = (sys_info.uptime / 60) - (days * 1440) - (hours * 60);

printf("{\n");
printf(" \"CPU_TOTAL\": %ld ,\n", (unsigned long)cpu.total);
printf(" \"CPU_USER\": %ld ,\n", (unsigned long)cpu.user);
printf(" \"CPU_NICE\": %ld ,\n", (unsigned long)cpu.nice);
printf(" \"CPU_SYS\": %ld ,\n", (unsigned long)cpu.sys);
printf(" \"CPU_IDLE\": %ld ,\n", (unsigned long)cpu.idle);
printf(" \"CPU_FREQUENCES\": %ld ,\n", (unsigned long)cpu.frequency);
printf(" \"CPU_USEGE\": %.2f ,\n", usagess);
printf(" \"MEMORY_TOTAL\": %ld ,\n", (unsigned long)memory.total/(1024*1024));
printf(" \"MEMORY_USED\": %ld ,\n", (unsigned long)memory.used/(1024*1024));
printf(" \"MEMORY_FREE\": %ld ,\n", (unsigned long)memory.free/(1024*1024));
printf(" \"MEMORY_SHARED\": %ld ,\n", (unsigned long)memory.shared/(1024*1024));
printf(" \"MEMORY_BUFFERED\": %ld ,\n", (unsigned long)memory.buffer/(1024*1024));
printf(" \"MEMORY_CACHED\": %ld ,\n", (unsigned long)memory.cached/(1024*1024));
printf(" \"MEMORY_USER\": %ld ,\n", (unsigned long)memory.user/(1024*1024));
printf(" \"MEMORY_LOCKED\": %ld ,\n", (unsigned long)memory.locked/(1024*1024));
printf(" \"UPTIME_DAYS\": %d ,\n", days);
printf(" \"UPTIME_HOURS\": %d ,\n", hours);
printf(" \"UPTIME_MINUTES\": %d ,\n", mins);
Expand All @@ -44,7 +81,6 @@ int main() {
printf(" \"TOTAL_VIRTUAL_MEM\": %llu ,\n", totalVirtualMem /1024/1024);
printf(" \"NUMBER_OF_PROCESSES\": %d \n", sys_info.procs);
printf("}\n");

/*printf("total usable main memory is %lu B, %lu MB\n", total_bytes/1024/1024, total_bytes/1024/1024);
printf("The number of pages of physical memory: %ld bytes\n", sysconf(_SC_PAGESIZE));
printf("The maximum number of simultaneous processes per user ID: %ld\n", sysconf(_SC_CHILD_MAX));
Expand Down
9 changes: 5 additions & 4 deletions src/i-nex/.settings
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[Bookmarks]
CFlags=[9]
Finfosys=[]

[Breakpoints]
Count=0
Expand All @@ -24,9 +25,9 @@ SearchComment=False
SearchString=True

[OpenFile]
Active=1
File[1]=".src/Finfosys.form"
File[2]=".src/Global.class:199.7"
Active=3
File[3]=".src/About.form"
File[4]=".src/About.class:19.0"
File[5]=".src/battery.module:136.82"
Expand All @@ -49,7 +50,7 @@ File[21]=".src/net.module:2.19"
File[22]="Data/report-ng.sh:5.3"
File[23]=".src/Distribution_Detect.module:13.1"
File[24]=".src/FFlags.module:2.19"
File[25]=".src/Finfosys.class:950.31"
File[25]=".src/Finfosys.class:608.3"
File[26]=".src/FDF.form"
File[27]=".src/FDF.class:26.6"
File[28]=".src/FNET_R_T.form"
Expand Down Expand Up @@ -80,14 +81,14 @@ File[52]=".src/Reports/MDRIVES_REPORT.module:12.40"
File[53]=".src/FInputDate.form"
File[54]=".src/MInit.module:25.23"
File[55]=".src/FEDID.form"
File[56]=".src/FEDID.class:25.0"
File[56]=".src/FEDID.class:83.25"
File[57]=".src/Logger.class:2.19"
File[58]=".src/Formatter.module:2.19"
File[59]=".src/FDirDialog.class:2.19"
File[60]=".src/FFileDialog.class:2.19"
File[61]=".src/FInputDate.class:2.19"
File[62]=".src/FDIMM.form"
File[63]=".src/FDIMM.class:80.1"
File[63]=".src/FDIMM.class:64.23"
Count=63

[Watches]
Expand Down
26 changes: 10 additions & 16 deletions src/i-nex/.src/Finfosys.class
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ Public Sub bios()

Exec ["cat", "/sys/devices/virtual/dmi/id/bios_vendor"] Wait To TextLabel5.Text
Exec ["cat", "/sys/devices/virtual/dmi/id/bios_version"] Wait To TextLabel6.Text
Exec ["cat", "/sys/devices/virtual/dmi/id/bios_date"] Wait To TextLabel7.Text
Exec ["cat", "/sys/devices/virtual/dmi/id/bios_date"] Wait To TextLabel14.Text

Exec ["cat", "/sys/devices/virtual/dmi/id/chassis_vendor"] Wait To TextLabel8.Text
Exec ["cat", "/sys/devices/virtual/dmi/id/chassis_version"] Wait To TextLabel9.Text
Expand All @@ -361,7 +361,7 @@ Public Sub bios()

TextLabel5.Text = "Bios Vendor: " & Replace(TextLabel5.Text, "\n", "")
TextLabel6.Text = "Bios Version: " & Replace(TextLabel6.Text, "\n", "")
TextLabel14.Text = "Bios Date: " & Replace(TextLabel7.Text, "\n", "")
TextLabel14.Text = "Bios Date: " & Replace(TextLabel14.Text, "\n", "")

TextLabel8.Text = "Chassis Vendor: " & Replace(TextLabel8.Text, "\n", "")
TextLabel9.Text = "Chassis Version: " & Replace(TextLabel9.Text, "\n", "")
Expand Down Expand Up @@ -595,23 +595,13 @@ Public Sub dospam_uptime()
Shell "users | tr ' ' '\n' | wc -l" Wait To Users
Exec [ChkPrm.ChkExecDir("inex-usage")] Wait To USAGE_BUFFER
USAGE = JSON.Decode(USAGE_BUFFER)
Shell "free -m | awk {'print $4'} | sed -n '2p'" Wait To freee
Shell "free -m | awk {'print $7'} | sed -n '2p'" Wait To cached
Shell "free -m | grep - | awk {'print $3'}" To usedonthistime
Shell "free -m | grep - | awk {'print $3'}" To dospam
Shell "free -m | grep Mem | awk {'print $2'}" Wait To totpam
dospam = Replace(Replace(dospam, " ", ""), "\n", "")
totpam = Replace(Replace(totpam, " ", ""), "\n", "")
usedonthistime = Replace(usedonthistime, "\n", "")
cached = Replace(cached, "\n", "")
freee = Replace(freee, "\n", "")
Label85.Text = "Total: " & Int(USAGE["TOTAL_RAM"]) & " MB"
Label86.Text = "Used: " & Int(Int(USAGE["TOTAL_RAM"]) - Int(USAGE["FREE_RAM"])) & " MB"
Label87.Text = "Free: " & freee & " MB"
Label87.Text = "Free: " & Int(USAGE["MEMORY_FREE"]) & " MB"
Label88.Text = "Shared: " & Int(USAGE["SHARED_RAM"]) & " MB"
Label89.Text = "Buffers: " & Int(USAGE["BUFFERED_RAM"]) & " MB"
Label90.Text = "Cached: " & cached & " MB"
TextLabel7.Text = "Ram used: " & usedonthistime & " MB"
Label90.Text = "Cached: " & Int(USAGE["MEMORY_CACHED"]) & " MB"
Label223.Text = "Ram used: " & Int(USAGE["MEMORY_USER"]) & " MB"
Label91.Text = "SWAP Total: " & Int(USAGE["TOTAL_SWAP"]) & " MB " ""
TextLabel15.Text = "Physical Memory Used: " & Int(USAGE["PHYS_MEM_USED"]) & " MB " ""
TextLabel24.Text = "SWAP memory used: " & Int(Int(USAGE["TOTAL_SWAP"]) - Int(USAGE["FREE_SWAP"])) & " MB"
Expand All @@ -624,7 +614,11 @@ Public Sub dospam_uptime()
", " & Int(USAGE["LOAD_AVG_5MIN"]) & " " &
", " & Int(USAGE["LOAD_AVG_15MIN"])
Try ProgressBar6.Value = Int(USAGE["PHYS_MEM_USED"]) / Int(USAGE["TOTAL_VIRTUAL_MEM"])
Try ProgressBar1.Value = Int(CFloat(dospam)) / Int(CFloat(totpam))
'Try ProgressBar1.Value = Int(CFloat(dospam)) / Int(CFloat(totpam))
Try ProgressBar7.Value = Int(USAGE["LOAD_AVG_1MIN"]) / Int(100)
Try ProgressBar8.Value = Int(USAGE["LOAD_AVG_5MIN"]) / Int(100)
Try ProgressBar9.Value = Int(USAGE["LOAD_AVG_15MIN"]) / Int(100)
Try ProgressBar1.Value = Int(USAGE["MEMORY_USER"]) / Int(USAGE["MEMORY_TOTAL"])
Try ProgressBar4.Value = Int(Int(USAGE["TOTAL_SWAP"]) - Int(USAGE["FREE_SWAP"])) / Int(USAGE["TOTAL_SWAP"])

End
Expand Down
87 changes: 62 additions & 25 deletions src/i-nex/.src/Finfosys.form
Original file line number Diff line number Diff line change
Expand Up @@ -1584,22 +1584,18 @@
Text = ("Memory")
Picture = Picture["AppIcons/Finfosys/utilities-system-monitor.png"]
{ ProgressBar1 ProgressBar
Move(0,245,469,21)
Move(140,308,329,21)
}
{ ProgressBar4 ProgressBar
Move(0,287,469,21)
}
{ TextLabel7 TextLabel
Move(0,224,469,21)
Font = Font["Bold,8"]
Text = ("N/A")
Alignment = Align.Center
Move(140,329,329,21)
}
{ TextLabel24 TextLabel
Move(0,266,469,21)
Move(0,329,140,21)
Font = Font["Bold,8"]
Padding = 1
Text = ("N/A")
Alignment = Align.Center
Alignment = Align.Left
Border = Border.Raised
}
{ Separator5 Separator
Move(0,217,469,14)
Expand All @@ -1609,7 +1605,7 @@
Text = ("MTRR")
}
{ Label176 Label
Move(7,448,343,21)
Move(0,455,343,21)
Font = Font["Bold,8"]
Padding = 3
Text = ("Label176")
Expand All @@ -1621,64 +1617,105 @@
Picture = Picture["AppIcons/gtk-yes.png"]
}
{ ProgressBar6 ProgressBar
Move(0,329,469,21)
}
{ TextLabel15 TextLabel
Move(0,308,469,21)
Font = Font["Bold,8"]
Text = ("TextLabel15")
Alignment = Align.Center
Move(140,350,329,21)
}
{ Label85 Label
Move(7,357,189,21)
Move(0,371,189,21)
Font = Font["Bold,8"]
Expand = True
Padding = 3
Border = Border.Raised
}
{ Label86 Label
Move(7,378,189,21)
Move(0,392,189,21)
Font = Font["Bold,8"]
Expand = True
Padding = 3
Border = Border.Raised
}
{ Label87 Label
Move(7,399,189,21)
Move(0,413,189,21)
Font = Font["Bold,8"]
Expand = True
Padding = 3
Border = Border.Raised
}
{ Label88 Label
Move(7,420,189,21)
Move(0,434,189,21)
Font = Font["Bold,8"]
Expand = True
Padding = 3
Border = Border.Raised
}
{ Label89 Label
Move(196,357,189,21)
Move(189,371,154,21)
Font = Font["Bold,8"]
Expand = True
Padding = 3
Border = Border.Raised
}
{ Label90 Label
Move(196,378,189,21)
Move(189,392,154,21)
Font = Font["Bold,8"]
Expand = True
Padding = 3
Alignment = Align.Left
Border = Border.Raised
}
{ Label91 Label
Move(196,399,189,21)
Move(189,434,154,21)
Font = Font["Bold,8"]
Expand = True
Padding = 3
Border = Border.Raised
}
{ ProgressBar7 ProgressBar
Move(112,245,357,21)
Label = False
}
{ ProgressBar8 ProgressBar
Move(112,266,357,21)
Label = False
}
{ ProgressBar9 ProgressBar
Move(112,287,357,21)
Label = False
}
{ Label220 Label
Move(0,245,112,21)
Font = Font["Bold,8"]
Padding = 3
Text = ("LOAD_AVG_1MIN")
Border = Border.Raised
}
{ Label221 Label
Move(0,266,112,21)
Font = Font["Bold,8"]
Padding = 3
Text = ("LOAD_AVG_5MIN")
Border = Border.Raised
}
{ Label222 Label
Move(0,287,112,21)
Font = Font["Bold,8"]
Text = ("LOAD_AVG_15MIN")
Border = Border.Raised
}
{ Label223 Label
Move(0,308,140,21)
Font = Font["Bold,8"]
Padding = 3
Text = ("Label223")
Border = Border.Raised
}
{ TextLabel15 TextLabel
Move(0,350,140,21)
Font = Font["Bold,8"]
Padding = 1
Text = ("TextLabel15")
Alignment = Align.Left
Border = Border.Raised
}
Index = 8
Text = ("Network")
Picture = Picture["AppIcons/Finfosys/network-wired.png"]
Expand Down

0 comments on commit 765ab4d

Please sign in to comment.