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

Config.cs « mperfmon - github.com/mono/mono-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 54b5f4302e5ee020d1258cb40df23e474636172b (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Config.cs created with MonoDevelop
// User: lupus at 12:03 PM 9/20/2008
//
// To change standard headers go to Edit->Preferences->Coding->Standard Headers
//

using System;
using System.Xml;
using System.Collections.Generic;

namespace mperfmon
{

	public class CounterSet {
		string name;
		List<string> counters;
		bool is_system;

		// add an id to each counter: counters with the same id are put
		// in the same graph
		public CounterSet (string name, List<string> counters, bool is_system)
		{
			this.name = name;
			this.is_system = is_system;
			this.counters = new List<string> (counters);
		}

		public bool IsSystem {
			get {return is_system;}
		}

		public string Name {
			get {return name;}
			set {name = value;}
		}

		public List<string> Counters {
			get {return counters;}
		}
	}
	
	public class Config
	{
		string filename;
		uint timeout = 1000;
		public List<CounterSet> sets = new List<CounterSet> ();

		public Config(string filename, bool system)
		{
			Load (filename, system);
		}

		public void Load (string file, bool system)
		{
			XmlTextReader reader = new XmlTextReader (file);
			string set_name = null;
			List<string> counters = new List<string> ();

			while (reader.Read ()) {
				if (reader.NodeType == XmlNodeType.Element) {
					string name = reader.Name;
					if (name == "mperfmon")
						continue;
					if (name == "update") {
						for (int i = 0; i < reader.AttributeCount; ++i) {
							reader.MoveToAttribute (i);
							if (reader.Name == "interval") {
								timeout = uint.Parse (reader.Value);
							}
						}
						continue;
					}
					if (name == "set") {
						for (int i = 0; i < reader.AttributeCount; ++i) {
							reader.MoveToAttribute (i);
							if (reader.Name == "name") {
								set_name = reader.Value;
							}
						}
						continue;
					}
					if (name == "counter") {
						string cat = null, counter = null;
						for (int i = 0; i < reader.AttributeCount; ++i) {
							reader.MoveToAttribute (i);
							if (reader.Name == "cat") {
								cat = reader.Value;
							} else if (reader.Name == "name") {
								counter = reader.Value;
							}
						}
						if (cat != null && counter != null) {
							counters.Add (cat);
							counters.Add (counter);
						}
						continue;
					}
				} else if (reader.NodeType == XmlNodeType.EndElement) {
					if (reader.Name == "set") {
						sets.Add (new CounterSet (set_name, counters, system));
						set_name = null;
						counters.Clear ();
					}
				}
			}
		}

		public uint Timeout {
			get {return timeout;}
			set {timeout =  value;}
		}

		public CounterSet this [string name] {
			get {
				foreach (CounterSet c in sets) {
					if (c.Name == name)
						return c;
				}
				return null;
			}
		}
	}
}