cgit: Added cgit 0.7.3-c502865 - A CGI for git written in C
[opensde-package-nopast.git] / base / embutils / free.patch
blob2f2c4ace1c1f356f5f9b76adecb962e60ce14fc8
1 # --- SDE-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
4 # Filename: package/.../embutils/free.patch
5 # Copyright (C) 2007 The OpenSDE Project
6 # Copyright (C) 2004 - 2006 The T2 SDE Project
8 # More information can be found in the files COPYING and README.
10 # This patch file is dual-licensed. It is available under the license the
11 # patched project is licensed under, as long as it is an OpenSource license
12 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
13 # of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
15 # version.
16 # --- SDE-COPYRIGHT-NOTE-END ---
18 A memory foodprint overview can be quite handy.
20 Rene Rebe <rene@exactcode.de>
22 --- ./Makefile.orig 2007-03-28 00:46:09.000000000 -0400
23 +++ ./Makefile 2007-03-28 00:46:49.000000000 -0400
24 @@ -12,7 +12,7 @@
25 domainname id ln mv cp yes which cat rm wc ls whoami mkfifo head install \
26 sosrm soscp sosmv sosln soslns md5sum sleep2 allinone uniq tr mesg du \
27 uuencode uudecode nohup nice cmp mktemp truncate strings test date \
28 -printenv chrootuid renice
29 +printenv chrootuid renice free
31 OS:=$(shell uname)
32 ifeq ($(OS),Linux)
33 --- /dev/null 2005-02-03 08:15:19.790903464 +0100
34 +++ embutils-0.17-free/free.c 2005-02-07 01:35:28.941469088 +0100
35 @@ -0,0 +1,90 @@
36 +#include <unistd.h>
37 +#include <fcntl.h>
38 +#include <sys/vfs.h>
39 +#include <stdlib.h>
41 +/* Rene Rebe <rene@exactcode.de>
43 +/* TODO: maybe support some options ... */
45 +#include "fmt_str.c"
46 +#include "fmt_ulong.c"
47 +#include "fmt_ulongpadright.c"
49 +int main(int argc, char* argv[]) {
50 + int fd=open("/proc/meminfo",O_RDONLY);
51 + char buf[4096];
52 + int len=read(fd,buf,4096);
53 + char *line, *max;
55 + struct meminfo_t {
56 + const char* tag;
57 + int val;} meminfo [] = {
58 + "MemTotal", 0,
59 + "MemFree", 0,
60 + "Buffers", 0,
61 + "Cached", 0,
62 + "SwapTotal", 0,
63 + "SwapFree", 0,
64 + 0, 0};
66 + line = buf;
67 + max = buf + len;
68 + while (line < max)
69 + {
70 + struct meminfo_t* i = &meminfo[0];
71 + char* tmp2 = strchr(line, ' ');
72 + *(--tmp2) = 0;
74 + for (;i->tag; i++) {
75 + if ( strcmp(line, i->tag) == 0 ) {
76 + tmp2++; while (*tmp2 == ' ') tmp2++;
77 + line = tmp2;
78 + tmp2 = strchr(tmp2, '\n');
79 + *tmp2 = 0;
80 + i->val = atol(line);
81 + line = tmp2 + 1;
82 + break;
83 + }
84 + }
85 + if (i->tag == 0)
86 + line = strchr(tmp2 + 1, '\n') + 1;
87 + }
89 + len = 0;
90 + len+=fmt_str (buf+len," total used free shared buffers cached\n");
92 + len+=fmt_str (buf+len, "Mem: ");
93 + len+=fmt_ulongpadright(buf+len,meminfo[0].val,10);
94 + buf[len]=' '; ++len;
95 + len+=fmt_ulongpadright(buf+len,meminfo[0].val - meminfo[1].val,10);
96 + buf[len]=' '; ++len;
97 + len+=fmt_ulongpadright(buf+len,meminfo[1].val,10);
98 + buf[len]=' '; ++len;
99 + len+=fmt_ulongpadright(buf+len,0,10);
100 + buf[len]=' '; ++len;
101 + len+=fmt_ulongpadright(buf+len,meminfo[2].val,10);
102 + buf[len]=' '; ++len;
103 + len+=fmt_ulongpadright(buf+len,meminfo[3].val,10);
104 + buf[len]='\n'; ++len;
106 + len += fmt_str (buf+len, "-/+ buffers/cache: ");
108 + int bc = meminfo[2].val + meminfo[3].val;
109 + len+=fmt_ulongpadright(buf+len,meminfo[0].val - meminfo[1].val - bc,10);
110 + buf[len]=' '; ++len;
111 + len+=fmt_ulongpadright(buf+len,meminfo[2].val + bc,10);
112 + buf[len]='\n'; ++len;
115 + len+=fmt_str (buf+len, "Swap: ");
116 + len+=fmt_ulongpadright(buf+len,meminfo[4].val,10);
117 + buf[len]=' '; ++len;
118 + len+=fmt_ulongpadright(buf+len,meminfo[4].val - meminfo[5].val,10);
119 + buf[len]=' '; ++len;
120 + len+=fmt_ulongpadright(buf+len,meminfo[5].val,10);
121 + buf[len] = 0;
122 + puts(buf);
124 + return 0;