我必须进行CPU计算:
以下是数据示例:
soft_irq": 0,
"name": "cpu.0",
"vendor": "Intel",
"user": 82133140,
"model": "Xeon",
"total_sockets": 4,
"total_cores": 4,
"nice": 0,
"wait": 0,
"idle": 3349563656,
"total": 3465546889,
"stolen": 0,
"irq": 0,
"sys": 33850093,
"mhz": 2800
计算如下:
PrevIdle = previdle + previowait
Idle = idle + iowait
PrevNonIdle = prevuser + prevnice + prevsystem + previrq + prevsoftirq + prevsteal
NonIdle = user + nice + system + irq + softirq + steal
PrevTotal = PrevIdle + PrevNonIdle
Total = Idle + NonIdle
# differentiate: actual value minus the previous one
totald = Total - PrevTotal
idled = Idle - PrevIdle
CPU_Percentage = (totald - idled)/totald
对一个CPU执行这些计算不是问题。但是,当平均获得四个CPU的CPU_Percentage时,我遇到了一个问题。这是我必须开始使用BigIntegers的地方。太好了,我有BigIntegers,最终可以将数字加起来。现在,问题在于获取CPU_Percentage。
我尝试使用BigRational,但这仅返回d / n或:
"1631300000165310000016688000001654700000000014999983687002958346909299833181999984383 / 16313000001653100000166880000016547"
这没有帮助。
我试图将其转换为浮点数,但是C#返回一个无限符号。
如何获得上述除法的十进制值?