示例#1
0
 void PushSnapshot(TopSnapshot top)
 {
     if (top == null)
     {
         return;
     }
     if (this.snapshots.Count >= this.maxSnapshots)
     {
         this.snapshots.RemoveAt(0);
     }
     this.snapshots.Add(top);
     this.onReceived(this, top);
 }
示例#2
0
        void OnOutput(string output)
        {
            if (string.IsNullOrEmpty(output))
            {
                return;
            }

            if (!this.oldStyle && output.StartsWith("tasks", StringComparison.CurrentCultureIgnoreCase) ||
                !this.oldStyle && output.StartsWith("mem:", StringComparison.CurrentCultureIgnoreCase) ||
                this.oldStyle && output.StartsWith("user", StringComparison.CurrentCultureIgnoreCase))
            {
                // はじまり
                if (this.currentTop == null || this.currentTop.CpuByTid.Count > 0)
                {
                    this.PushSnapshot(this.currentTop);
                    this.currentTop = new TopSnapshot(DateTime.Now);
                }
                return;
            }

            if (this.currentTop == null)
            {
                return;
            }

            if (!this.ParseLine(output, out var pid, out var tid, out var cpu))
            {
                return;
            }

            if (cpu <= 0.0f)
            {
                // 以降は全部0%なので無視
                this.PushSnapshot(this.currentTop);
                this.currentTop = null;
            }
            else
            {
                this.currentTop.CpuByPid[pid] = this.currentTop.CpuByPid.TryGetValue(pid, out var pCpu) ? (pCpu + cpu) : cpu;
                this.currentTop.CpuByTid[tid] = cpu;
                this.currentTop.TotalCpu     += cpu;
            }
        }