1 /*******************************************************************************
2 * Copyright (c) 2017 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.nativemem.internal.linux;
14 import java.io.BufferedReader;
15 import java.io.IOException;
16 import java.nio.charset.Charset;
17 import java.nio.file.Files;
18 import java.nio.file.Paths;
20 import org.simantics.nativemem.internal.Resource;
23 * @author Tuukka Lehtonen
28 private static final String SELF_STATM = "/proc/self/statm";
29 private static final Charset ASCII = Charset.forName("US-ASCII");
31 public static long getCurrentRSS(Resource r) {
32 try (BufferedReader rdr = Files.newBufferedReader(Paths.get(SELF_STATM), ASCII)) {
33 String line = rdr.readLine();
34 String[] nums = line.split(" ");
37 long rss = Long.parseLong(nums[0]);
38 long pageSize = r.sysconf(Resource._SC_PAGESIZE);
39 return rss * pageSize;
40 } catch (NumberFormatException e) {
42 } catch (IOException e) {