Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Main.cs « mperfmon - github.com/mono/mono-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 70bf233196ae071e9770c7cf6190b36a68f228cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Main.cs created with MonoDevelop
// User: lupus at 12:08 PM 9/18/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//
using System;
using System.IO;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using Gtk;

namespace mperfmon
{
	class MainClass
	{

		static void Report (Config cfg, string name, string[] args, int start, int count)
		{
			List<string> instances = new List<string> ();
			for (; start < args.Length; ++start)
				instances.Add (args [start]);
			if (instances.Count == 0) {
				Console.WriteLine ("Need to provide instance names.");
				return;
			}
			CounterSet cset = cfg [name];
			if (cset == null) {
				Console.WriteLine ("Unknown counter set: {0}.", name);
				return;
			}
			List<PerformanceCounter> counters = ReportList (cset, instances);
			for (int i = 0; i < count; ++i) {
				Report (counters);
				System.Threading.Thread.Sleep ((int)cfg.Timeout);
			}
		}

		static void Report (List<PerformanceCounter> counters)
		{
			string last_instance = null;
			foreach (PerformanceCounter c in counters) {
				string instance = c.InstanceName;
				if (last_instance != instance) {
					Console.WriteLine ("Report for: {0}", instance);
					last_instance = instance;
				}
				Console.Write ("\t{0}/{1}: ", c.CategoryName, c.CounterName);
				try {
					Console.WriteLine (c.NextValue ());
				} catch (Exception e) {
					Console.WriteLine (e.Message);
				}	
			}
		}
		
		static List<PerformanceCounter> ReportList (CounterSet  cset, List<string> instances)
		{
			List<string> counters = cset.Counters;
			List<PerformanceCounter> pcounters = new List<PerformanceCounter> ();
			foreach (string instance in instances) {
				for (int i = 0; i < counters.Count; i += 2) {
					try {
						PerformanceCounter counter = new PerformanceCounter (counters [i], counters [i + 1], instance);
						pcounters.Add (counter);
					} catch (Exception e) {
						//Console.WriteLine (e.Message);
					}
				}
			}
			return pcounters;
		}

		public static void Main (string[] args)
		{
			string report_name = null;
			int report_args = args.Length;
			int count = 2;
			Config cfg;
			string cfg_file = Path.Combine (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location), "config");

			for (int i = 0; i < args.Length; ++i) {
				if (args [i].StartsWith ("--report=")) {
					report_name = args [i].Substring (9);
					continue;
				} else if (args [i].StartsWith ("--count=")) {
					count = int.Parse (args [i].Substring (8));
					continue;
				} else if (args [i].StartsWith ("--config=")) {
					cfg_file = args [i].Substring (9);
					continue;
				}
				report_args = i;
				break;
			}
	
			cfg = new Config (cfg_file, true);
			if (report_name != null) {
				Report (cfg, report_name, args, report_args, count);
				return;
			}
			Application.Init ();
			MainWindow win = new MainWindow (cfg);
			win.Show ();
			Application.Run ();
		}
	}
}