Line data Source code
1 : /* Copyright 2014 Andreas Marek, 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 : #include <sys/types.h>
19 : #define _GNU_SOURCE
20 : #include <stdio.h>
21 : #include <unistd.h>
22 : #include <stdlib.h>
23 : #include <string.h>
24 :
25 0 : long ftimings_highwater_mark() {
26 0 : long hwm = 0L;
27 : char line[1024];
28 0 : FILE* fp = NULL;
29 :
30 0 : if ((fp = fopen( "/proc/self/status", "r" )) == NULL ) {
31 0 : return 0L;
32 : }
33 :
34 : /* Read memory size data from /proc/pid/status */
35 0 : while(fgets(line, sizeof line, fp)) {
36 0 : if (sscanf(line, "VmHWM: %ld kB", &hwm) == 1) {
37 0 : break;
38 : }
39 : }
40 0 : fclose(fp);
41 :
42 0 : return hwm * 1024L;
43 : }
|