|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Diagnostics; |
| 4 | +using System.Globalization; |
4 | 5 | using System.IO; |
5 | 6 | using System.Linq; |
6 | 7 | using System.Threading.Tasks; |
@@ -29,20 +30,37 @@ public static void Main(string[] args) |
29 | 30 | { |
30 | 31 | var parameters = ParseArguments(args); |
31 | 32 | var reporter = new PerformanceReporter(parameters.ProcessNames, parameters.NetworkIP); |
32 | | - if(parameters.CSV) |
33 | | - Console.WriteLine($"Process Name(s);Thread(s);CPU (%);Memory (MB);Process Sent (KB);Process Upload Speed (kbps);Process Received (KB);Process Download Speed (kbps)" + (String.IsNullOrEmpty(parameters.NetworkIP)?"":";Network Sent (KB);Network Upload Speed (kbps);Network Received (KB);Network Download Speed (kbps)")); |
| 33 | + |
| 34 | + NumberFormatInfo nfi = new CultureInfo("en-US", false).NumberFormat; |
| 35 | + if (parameters.CSV) |
| 36 | + Console.WriteLine($"Process Name(s),Thread(s),CPU (%),Memory (MB),Process Sent (KB),Process Upload Speed (kbps),Process Received (KB),Process Download Speed (kbps)" + (String.IsNullOrEmpty(parameters.NetworkIP)?"":",Network Sent (KB),Network Upload Speed (kbps),Network Received (KB),Network Download Speed (kbps)")); |
34 | 37 | while (true) |
35 | 38 | { |
36 | 39 | Task.Delay(parameters.IntervalTime).Wait(); |
37 | 40 | var result = reporter.GetPerformanceData(); |
38 | 41 | if(parameters.CSV) |
39 | | - Console.WriteLine($"{String.Join('+', parameters.ProcessNames)};{result.Threads};{ result.ProcessCPUUsage.ToString("0.00")};{result.ProcessMemoryUsage.ToString("N0")};" + |
40 | | - $"{result.ProcessSentData.ToString("N0")};{result.ProcessUploadSpeed.ToString("N0")};{result.ProcessReceivedData.ToString("N0")};{result.ProcessDownloadSpeed.ToString("N0")}" + |
41 | | - (String.IsNullOrEmpty(parameters.NetworkIP) ? "" : $";{result.NetworkSentData.ToString("N0")};{result.NetworkUploadSpeed.ToString("N0")};{result.NetworkReceivedData.ToString("N0")};{result.NetworkDownloadSpeed.ToString("N0")}")); |
42 | | - else |
43 | | - Console.WriteLine($"{String.Join('+', parameters.ProcessNames)} ({result.Threads} ths) = CPU: { result.ProcessCPUUsage.ToString("0.00")} % | Memory: {result.ProcessMemoryUsage.ToString("N0")} MB | " + |
44 | | - $"Process: Sent {result.ProcessSentData.ToString("N0")} KB ({result.ProcessUploadSpeed.ToString("N0")} kbps) - Received {result.ProcessReceivedData.ToString("N0")} KB ({result.ProcessDownloadSpeed.ToString("N0")} kbps)" + |
45 | | - (String.IsNullOrEmpty(parameters.NetworkIP) ? "" : $" | Network: Sent {result.NetworkSentData.ToString("N0")} KB ({result.NetworkUploadSpeed.ToString("N0")} kbps) - Received {result.NetworkReceivedData.ToString("N0")} KB ({result.NetworkDownloadSpeed.ToString("N0")} kbps)")); |
| 42 | + Console.WriteLine($"{String.Join('+', parameters.ProcessNames)}," + |
| 43 | + $"{result.Threads}," + |
| 44 | + $"{ result.ProcessCPUUsage.ToString("P", nfi)}," + |
| 45 | + $"{result.ProcessMemoryUsage.ToString("N0",nfi)}," + |
| 46 | + $"{result.ProcessSentData.ToString("N0",nfi)}," + |
| 47 | + $"{result.ProcessUploadSpeed.ToString("N0", nfi)}," + |
| 48 | + $"{result.ProcessReceivedData.ToString("N0", nfi)}," + |
| 49 | + $"{result.ProcessDownloadSpeed.ToString("N0", nfi)}" + |
| 50 | + (String.IsNullOrEmpty(parameters.NetworkIP) ? "" : $"," + |
| 51 | + $"{result.NetworkSentData.ToString("N0", nfi)}," + |
| 52 | + $"{result.NetworkUploadSpeed.ToString("N0", nfi)}," + |
| 53 | + $"{result.NetworkReceivedData.ToString("N0", nfi)}," + |
| 54 | + $"{result.NetworkDownloadSpeed.ToString("N0", nfi)}")); |
| 55 | + else |
| 56 | + Console.WriteLine($"{String.Join('+', parameters.ProcessNames)} ({result.Threads} ths):" + |
| 57 | + $" CPU: { result.ProcessCPUUsage.ToString("P",nfi)} " + |
| 58 | + $"| Memory: {result.ProcessMemoryUsage.ToString("N0", nfi)} MB " + |
| 59 | + $"| Process: Sent {result.ProcessSentData.ToString("N0", nfi)} KB ({result.ProcessUploadSpeed.ToString("N0", nfi)} kbps) " + |
| 60 | + $"- Received {result.ProcessReceivedData.ToString("N0", nfi)} KB ({result.ProcessDownloadSpeed.ToString("N0", nfi)} kbps)" + |
| 61 | + (String.IsNullOrEmpty(parameters.NetworkIP) ? "" : $" " + |
| 62 | + $"| Network: Sent {result.NetworkSentData.ToString("N0", nfi)} KB ({result.NetworkUploadSpeed.ToString("N0", nfi)} kbps) " + |
| 63 | + $"- Received {result.NetworkReceivedData.ToString("N0", nfi)} KB ({result.NetworkDownloadSpeed.ToString("N0", nfi)} kbps)")); |
46 | 64 | } |
47 | 65 | } |
48 | 66 |
|
@@ -80,13 +98,13 @@ private static Parameters ParseArguments(string[] args) |
80 | 98 | } |
81 | 99 | } |
82 | 100 |
|
83 | | - public const string HELP_MESSAGE = "ProcessPerformance 2021 Computational Reflection Research Group\n" + |
| 101 | + public const string HELP_MESSAGE = "ProcessPerformance 2021 Computational Reflection Research Group.\n" + |
84 | 102 | "-help Displays this usage message.\n" + |
85 | | - "-network:NETWORK_IP Specify the network interface IP (disable by default).\n" + |
86 | | - "-interval:MILISENCONS Specify the interval time in milisecons (default is 1000).\n" + |
| 103 | + "-network:NETWORK_IP Specify the network interface IP (disable by default).\n" + |
| 104 | + "-interval:MILLISECONDS Specify the interval time in milliseconds (default is 1000).\n" + |
87 | 105 | "-csv Specify output format as CSV (disable by default).\n" + |
88 | | - "process_1 ... process_n A list of process names or PIDs (if empty, all running processes are used).\n" + |
89 | | - "\nCtrl + c Is the interrupt signal.\n" + |
| 106 | + "process_1 ... process_n A space-separated list of processes names or PIDs (if empty, all running processes are used).\n" + |
| 107 | + "\nCtrl + c Terminate the execution of the program.\n" + |
90 | 108 | "\n"; |
91 | 109 | } |
92 | 110 | } |
0 commit comments