Skip to content

Commit 416d589

Browse files
Using CultureInfo to display messages
1 parent 7058046 commit 416d589

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

ProcessPerformance/Program.cs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Diagnostics;
4+
using System.Globalization;
45
using System.IO;
56
using System.Linq;
67
using System.Threading.Tasks;
@@ -29,20 +30,37 @@ public static void Main(string[] args)
2930
{
3031
var parameters = ParseArguments(args);
3132
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)"));
3437
while (true)
3538
{
3639
Task.Delay(parameters.IntervalTime).Wait();
3740
var result = reporter.GetPerformanceData();
3841
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)"));
4664
}
4765
}
4866

@@ -80,13 +98,13 @@ private static Parameters ParseArguments(string[] args)
8098
}
8199
}
82100

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" +
84102
"-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" +
87105
"-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" +
90108
"\n";
91109
}
92110
}

ProcessPerformance/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"ProcessPerformance": {
44
"commandName": "Project",
5-
"commandLineArgs": "chrome tomcat neo4j postgres -network:192.168.1.103 -interval:500"
5+
"commandLineArgs": "chrome"
66
}
77
}
88
}

0 commit comments

Comments
 (0)