Line data Source code
1 : /* Copyright 2014 Lorenz Hüdepohl
2 : *
3 : * This file is part of ftimings.
4 : *
5 : * ftimings is free software: you can redistribute it and/or modify
6 : * it under the terms of the GNU Lesser General Public License as published by
7 : * the Free Software Foundation, either version 3 of the License, or
8 : * (at your option) any later version.
9 : *
10 : * ftimings is distributed in the hope that it will be useful,
11 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 : * GNU Lesser General Public License for more details.
14 : *
15 : * You should have received a copy of the GNU Lesser General Public License
16 : * along with ftimings. If not, see <http://www.gnu.org/licenses/>.
17 : */
18 :
19 : #include <stdio.h>
20 : #include <unistd.h>
21 :
22 0 : long ftimings_resident_set_size() {
23 0 : long rss = 0L;
24 0 : FILE* fp = NULL;
25 0 : if ((fp = fopen( "/proc/self/statm", "r" )) == NULL ) {
26 0 : return 0L;
27 : }
28 0 : if (fscanf(fp, "%*s%ld", &rss) != 1) {
29 0 : fclose(fp);
30 0 : return (size_t)0L; /* Can't read? */
31 : }
32 0 : fclose(fp);
33 0 : return rss * sysconf( _SC_PAGESIZE);
34 : }
|