14 unsigned KLONG beyond;
19 unsigned long long inode;
32 ////////////////////////////////////////////////////////////////////////////////
33 // This code will surely make normal programmers cry. I need speed though,
34 // and /proc/*/smaps should make anybody cry. (WTF kind of brain damage...?)
54 #define JTE(o,x) {#x,sizeof(#x)-1,o}
56 void get_smap_sums(struct smap_summary *restrict ss, const char *restrict const filename){
57 static struct ssjt table[] = {
63 JTE( 5,Private_Clean),
64 JTE( 6,Private_Dirty),
73 JTE(-1,default), // KernelPageSize would go here
94 memset(ss,0,sizeof *ss);
95 int fd = open(filename,O_RDONLY);
99 char *nlp = memchr(buf+p1,'\n',p2-p1);
102 // the memmove should never do anything, because the
103 // kernel seems to give us the greatest number of
104 // complete lines of text that fit in a single page
105 // (and thus p2-p1 is zero)
106 memmove(buf,buf+p1,p2-p1);
110 ssize_t rb = read(fd,buf+p1,sizeof buf - p1);
114 nlp = memchr(buf+p1,'\n',p2-p1);
123 //printf("j <%13.13s>\n",s);
124 if(s[0]<'A' || s[0]>'Z')
126 unsigned hash = ( (s[8]&15) + (s[1]&15) ) ^ (s[0]&3);
128 //printf("x %2d <%13.13s>\n",hash,s);
129 if(s[table[hash].len] != ':')
131 //printf("y %2d <%13.13s>\n",hash,s);
132 if(memcmp(table[hash].str,s,table[hash].len))
134 //printf("z %2d <%13.13s>\n",hash,s);
135 s += table[hash].len;
138 unsigned long ul = 0;
148 // if(table[hash].offset == 2)
149 // printf("Pss:%20lu kB\n",ul);
150 unsigned long *ulp = &ss->size + table[hash].offset;
152 // memcpy(ss+table[hash].offset*sizeof(unsigned long), &ul, sizeof(unsigned long));
157 int main(int argc, char *argv[]){
158 struct smap_summary ss;
159 get_smap_sums(&ss, argv[1]);
160 printf("%9lu\n",ss.size);
161 printf("%9lu\n",ss.rss);
162 printf("%9lu\n",ss.pss);
163 printf("%9lu\n",ss.sclean);
164 printf("%9lu\n",ss.sdirty);
165 printf("%9lu\n",ss.pclean);
166 printf("%9lu\n",ss.pdirty);
167 printf("%9lu\n",ss.ref);
168 printf("%9lu\n",ss.swap);