* updated libkomparediff2 (21.12.1 -> 21.12.2), untested
[t2-trunk.git] / package / base / embutils / free.patch
blob4d4eaf0987870709b6c47fc11272f4f2aff022ac
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/.../embutils/free.patch
5 # Copyright (C) 2004 - 2006 The T2 SDE Project
6 #
7 # More information can be found in the files COPYING and README.
8 #
9 # This patch file is dual-licensed. It is available under the license the
10 # patched project is licensed under, as long as it is an OpenSource license
11 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
12 # of the GNU General Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at your option) any later
14 # version.
15 # --- T2-COPYRIGHT-NOTE-END ---
17 A memory foodprint overview can be quite handy.
19 Rene Rebe <rene@exactcode.de>
21 --- ./Makefile~ 2006-08-03 12:54:04.000000000 +0200
22 +++ ./Makefile 2006-11-05 11:43:25.000000000 +0100
23 @@ -12,7 +12,8 @@
24 domainname id ln mv cp yes which cat rm wc ls whoami mkfifo head install \
25 sosrm soscp sosmv sosln soslns md5sum sleep2 allinone uniq tr mesg du \
26 uuencode uudecode nohup nice cmp mktemp truncate strings test date \
27 -printenv chrootuid renice
28 +printenv chrootuid renice \
29 +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,89 @@
36 +#include <unistd.h>
37 +#include <fcntl.h>
38 +#include <sys/vfs.h>
39 +#include <stdlib.h>
41 +/* Rene Rebe <rene@exactcode.de>
42 + * TODO: maybe support some options ... */
44 +#include "fmt_str.c"
45 +#include "fmt_ulong.c"
46 +#include "fmt_ulongpadright.c"
48 +int main(int argc, char* argv[]) {
49 + int fd=open("/proc/meminfo",O_RDONLY);
50 + char buf[4096];
51 + int len=read(fd,buf,4096);
52 + char *line, *max;
54 + struct meminfo_t {
55 + const char* tag;
56 + int val;} meminfo [] = {
57 + "MemTotal", 0,
58 + "MemFree", 0,
59 + "Buffers", 0,
60 + "Cached", 0,
61 + "SwapTotal", 0,
62 + "SwapFree", 0,
63 + 0, 0};
65 + line = buf;
66 + max = buf + len;
67 + while (line < max)
68 + {
69 + struct meminfo_t* i = &meminfo[0];
70 + char* tmp2 = strchr(line, ' ');
71 + *(--tmp2) = 0;
73 + for (;i->tag; i++) {
74 + if ( strcmp(line, i->tag) == 0 ) {
75 + tmp2++; while (*tmp2 == ' ') tmp2++;
76 + line = tmp2;
77 + tmp2 = strchr(tmp2, '\n');
78 + *tmp2 = 0;
79 + i->val = atol(line);
80 + line = tmp2 + 1;
81 + break;
82 + }
83 + }
84 + if (i->tag == 0)
85 + line = strchr(tmp2 + 1, '\n') + 1;
86 + }
88 + len = 0;
89 + len+=fmt_str (buf+len," total used free shared buffers cached\n");
91 + len+=fmt_str (buf+len, "Mem: ");
92 + len+=fmt_ulongpadright(buf+len,meminfo[0].val,10);
93 + buf[len]=' '; ++len;
94 + len+=fmt_ulongpadright(buf+len,meminfo[0].val - meminfo[1].val,10);
95 + buf[len]=' '; ++len;
96 + len+=fmt_ulongpadright(buf+len,meminfo[1].val,10);
97 + buf[len]=' '; ++len;
98 + len+=fmt_ulongpadright(buf+len,0,10);
99 + buf[len]=' '; ++len;
100 + len+=fmt_ulongpadright(buf+len,meminfo[2].val,10);
101 + buf[len]=' '; ++len;
102 + len+=fmt_ulongpadright(buf+len,meminfo[3].val,10);
103 + buf[len]='\n'; ++len;
105 + len += fmt_str (buf+len, "-/+ buffers/cache: ");
107 + int bc = meminfo[2].val + meminfo[3].val;
108 + len+=fmt_ulongpadright(buf+len,meminfo[0].val - meminfo[1].val - bc,10);
109 + buf[len]=' '; ++len;
110 + len+=fmt_ulongpadright(buf+len,meminfo[2].val + bc,10);
111 + buf[len]='\n'; ++len;
114 + len+=fmt_str (buf+len, "Swap: ");
115 + len+=fmt_ulongpadright(buf+len,meminfo[4].val,10);
116 + buf[len]=' '; ++len;
117 + len+=fmt_ulongpadright(buf+len,meminfo[4].val - meminfo[5].val,10);
118 + buf[len]=' '; ++len;
119 + len+=fmt_ulongpadright(buf+len,meminfo[5].val,10);
120 + buf[len] = 0;
121 + puts(buf);
123 + return 0;