RAM    


using UnityEngine;
using System.Collections;

public class RamTest : MonoBehaviour {

    void Start () {
        InvokeRepeating ("Refresh", 0, 1);
    }

    void Refresh(){
        RamInfo.Update ();
    }

    void OnGUI () {
        GUILayout.Space (20);
        GUILayout.Label (RamInfo.all);
        GUILayout.Space (5);
        GUILayout.Label ("全部記憶體:" + RamInfo.memtotal/1000 + " MB");
        GUILayout.Label ("已用記憶體:" + RamInfo.active/1000 + " MB");
        GUILayout.Label ("可用記憶體:" + (RamInfo.memtotal - RamInfo.active)/1000 + " MB");
        GUILayout.Space (5);
        GUILayout.Label ("記憶體使用率:" + (((float)RamInfo.active/RamInfo.memtotal)*100).ToString("0.0") + " %");
    }

}





using System.IO;
using System.Text.RegularExpressions;

public class RamInfo {

    public static readonly string dataPath = "/proc/meminfo";

    public static string all = "";
    public static int memtotal = 0;
    public static int active = 0;

    // -----------------------------------------------------

    public static string [] GetMemInfoArray(){
        return File.ReadAllLines (dataPath);
    }

    public static int Update(){
        all = "";
        foreach(string data in GetMemInfoArray()){
            string title = data.Split(' ')[0].ToLower();
            if(title == "memtotal:"){
                memtotal = GetNumber(data);
            }else if(title == "active:"){
                active = GetNumber(data);
            }
            all += data + "\n";
        }
        return -1;
    }

    public static int GetNumber(string data){
        return int.Parse(new Regex(@"\d+").Match(data).Value);
    }
}

arrow
arrow
    全站熱搜

    黃彥霖 發表在 痞客邦 留言(0) 人氣()