📄 meminfo.java
字号:
package fr.umlv.projet.procfs;import java.io.File;import java.io.FileNotFoundException;import java.util.Scanner;/** * This class is to read the real time states of memory. * @author MA Xiao Jun & HUANG Wei * */public class Meminfo{ private static String MemTotal; private static String MemFree; private static String Buffers; private static String Cached; private static String SwapCached; private static String Active; private static String Inactive; private static String HighTotal; private static String HighFree; private static String LowTotal; private static String LowFree; private static String SwapTotal; private static String SwapFree; private static String Dirty; private static String Writeback; private static String Mapped; private static String Slab; private static String CommitLimit; private static String Committed_AS; private static String PageTables; private static String VmallocTotal; private static String VmallocUsed; private static String VmallocChunk; private static String HugePages_Total; private static String HugePages_Free; private static String Hugepagesize; static{ try { Scanner sc = new Scanner(new File("/proc/meminfo")); while(sc.hasNext()){ String s = sc.next(); if(s.contains("MemTotal")) MemTotal = sc.next(); if(s.contains("SwapTotal")) SwapTotal = sc.next(); } } catch (FileNotFoundException e) { e.printStackTrace(); } }/** *to save the data of states of memory,like memory free,memory total,swap free,etc. * @param sc the Scanner which is used to read the datas from "/proc/meminfo". */ private static void enregistreData(Scanner sc){ String s = sc.next(); if(s.contains("MemFree")) MemFree = sc.next(); if(s.contains("Buffers")) Buffers = sc.next(); if(s.contains("Cached")) Cached = sc.next(); if(s.contains("SwapCached")) SwapCached = sc.next(); if(s.contains("Active")) Active = sc.next(); if(s.contains("Inactive")) Inactive = sc.next(); if(s.contains("HighTotal")) HighTotal = sc.next(); if(s.contains("HighFree")) HighFree = sc.next(); if(s.contains("LowTotal")) LowTotal = sc.next(); if(s.contains("LowFree")) LowFree = sc.next();// if(s.contains("SwapTotal"))// SwapTotal = sc.next(); if(s.contains("SwapFree")) SwapFree = sc.next(); if(s.contains("Dirty")) Dirty = sc.next(); if(s.contains("Writeback")) Writeback = sc.next(); if(s.contains("Mapped")) Mapped = sc.next(); if(s.contains("Slab")) Slab = sc.next(); if(s.contains("CommitLimit")) CommitLimit = sc.next(); if(s.contains("Committed_AS")) Committed_AS = sc.next(); if(s.contains("PageTables")) PageTables = sc.next(); if(s.contains("VmallocTotal")) VmallocTotal = sc.next(); if(s.contains("VmallocUsed")) VmallocUsed = sc.next(); if(s.contains("VmallocChunk")) VmallocChunk = sc.next(); if(s.contains("HugePages_Total")) HugePages_Total = sc.next(); if(s.contains("HugePages_Free")) HugePages_Free = sc.next(); if(s.contains("Hugepagesize")) Hugepagesize = sc.next(); } /** * to refresh and save the information of the real time states of memory. */ public static void update(){ try { Scanner sc = new Scanner(new File("/proc/meminfo")); while(sc.hasNext()){ enregistreData(sc); } } catch (FileNotFoundException e) { e.printStackTrace(); } } /** * Return information of Active. * @return value of Active. */ public static String getActive() { return Active; } /** * Return information of Buffers. * @return value of Buffers. */ public static String getBuffers() { return Buffers; } /** * Return information of Cached. * @return value of Cached. */ public static String getCached() { return Cached; } /** * Return information of CommitLimit * @return value of CommitLimit */ public static String getCommitLimit() { return CommitLimit; } /** * Return information of Committed_As * @return value of CommitLimit. */ public static String getCommitted_AS() { return Committed_AS; } /** * Return information of Dirty * @return value of Dirty. */ public static String getDirty() { return Dirty; } /** * Return information of HighFree. * @return value of HighFree. */ public static String getHighFree() { return HighFree; } /** * Return information of HighTotal. * @return value of HighTotal. */ public static String getHighTotal() { return HighTotal; } /** * Return information of HugePages_Free. * @return value of HighPages_Free. */ public static String getHugePages_Free() { return HugePages_Free; } /** * Return information of HugePages_Total. * @return value of HighPages_Total. */ public static String getHugePages_Total() { return HugePages_Total; } /** * Return size of HugePages. * @return size of HighPages. */ public static String getHugepagesize() { return Hugepagesize; } /** * Return information of Inactive. * @return value of Inactive. */ public static String getInactive() { return Inactive; } /** * Return information of LowFree. * @return value of LowFree. */ public static String getLowFree() { return LowFree; } /** * Return information of LowTotal. * @return value of LowTotal. */ public static String getLowTotal() { return LowTotal; } /** * Return information of Mapped * @return value of Mapped */ public static String getMapped() { return Mapped; } /** * Return information of free memory. * @return value of free memory. */ public static String getMemFree() { return MemFree; } /** * Return information of total memory. * @return value of total memory. */ public static String getMemTotal() { return MemTotal; } /** * Return information of PageTables. * @return value of PageTables. */ public static String getPageTables() { return PageTables; } /** * Return information of Slab. * @return value of Slab. */ public static String getSlab() { return Slab; } /** * Return information of SwapCached. * @return value of SwayCached. */ public static String getSwapCached() { return SwapCached; } /** * Return information of SwapFree. * @return value of SwapFree. */ public static String getSwapFree() { return SwapFree; } /** * Return information of SwapTotal. * @return value of SwapTotal. */ public static String getSwapTotal() { return SwapTotal; } /** * Return information of VmallocChunk. * @return value of VmallocChunk. */ public static String getVmallocChunk() { return VmallocChunk; } /** * Return information of VmallocTotal. * @return value of VmallocTotal. */ public static String getVmallocTotal() { return VmallocTotal; } /** * Return information of VmallocUsed. * @return value of VmallocUsed. */ public static String getVmallocUsed() { return VmallocUsed; } /** * Return information of Writeback. * @return value of Writeback. */ public static String getWriteback() { return Writeback; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -