Ejemplo n.º 1
0
        public static List<Proc> getProcessTree(PacketStatistic statistic)
        {
            var relations = new Dictionary<int, List<int>>();
            var procs = new Dictionary<int, Proc>();
            var searcher = new ManagementObjectSearcher("select * from win32_process");

            foreach(var res in searcher.Get())
            {
                // res info at https://msdn.microsoft.com/en-us/library/aa394372(v=vs.85).aspx

                int pid = Convert.ToInt32(res["ProcessId"].ToString());
                int ppid = Convert.ToInt32(res["ParentProcessId"].ToString());
                string name = res["Name"].ToString();
                procs[pid] = new Proc() { processId = pid, parentId = ppid, processName = name };

            }

            var dataCount = statistic.refreshData();
            var pc = new ProcessConnection();
            foreach(var con in pc.connections)
            {
                if (con.pid != 0 && procs.ContainsKey(con.pid)) {
                    procs[con.pid].connections.Add(con);
                    if (dataCount.ContainsKey(con))
                    {
                        procs[con.pid].speed += dataCount[con];
                    }

                }

            }

            var children = new HashSet<int>();
            foreach(var res in procs)
            {
                int pid = res.Value.processId;
                int ppid = res.Value.parentId;

                if (ppid != 0 && procs.ContainsKey(ppid))
                {
                    procs[ppid].children.Add(procs[pid]);
                    children.Add(pid);
                }

            }

            var result = new List<Proc>();
            foreach (var res in procs)
            {
                if(!children.Contains(res.Key))
                {
                    result.Add(res.Value);
                }
            }
            return result;
        }
Ejemplo n.º 2
0
        public ProcessForm(int pid, PacketStatistic statistic)
        {
            this.pid = pid;
            this.process = Process.GetProcessById(pid);
            this.statistic = statistic;
            InitializeComponent();
            Tag = new Size(Size.Width, Size.Height);

            foreach (Control ctrl in this.Controls)
            {

                ctrl.Tag = new Tuple<Tuple<double, double>, Size>(
                    new Tuple<double, double>(ctrl.Location.X / (double)Size.Width, ctrl.Location.Y / (double)Size.Height),
                    ctrl.Size);
            }
        }