revert previous commit
[moon.git] / perf / perf-suite-runner / DrtItem.cs
blob4d88132f8354e40ca4bcb93f6f21c98669a0cb5d
1 /*
2 * Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
4 * Contact:
5 * Moonlight List (moonlight-list@lists.ximian.com)
6 *
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use,
11 * copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following
14 * conditions:
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
30 using System;
31 using System.Xml;
32 using System.IO;
33 using System.Diagnostics;
35 namespace PerfSuiteRunner {
37 public class DrtItem {
39 public int StartTime = 0;
40 public int EndTime = 5000;
41 public int Interval = 40;
42 public int Timeout = 35000;
43 public int Runs = 3;
44 public int Width = 400;
45 public int Height = 400;
46 public string InputFile = String.Empty;
47 public string UniqueId = String.Empty;
48 public string Name = String.Empty;
50 public static string ItemsDirectory = "perf-suite-set";
52 public string FullFileName {
53 get {
54 return String.Format ("{0}/{1}", ItemsDirectory, InputFile);
58 /* CONSTRUCTOR */
59 public DrtItem (XmlNode node)
61 if (node.Attributes ["startTime"] != null)
62 StartTime = Convert.ToInt32 (node.Attributes ["startTime"].Value);
64 if (node.Attributes ["endTime"] != null)
65 EndTime = Convert.ToInt32 (node.Attributes ["endTime"].Value);
67 if (node.Attributes ["interval"] != null)
68 Interval = Convert.ToInt32 (node.Attributes ["interval"].Value);
70 if (node.Attributes ["inputFile"] != null)
71 InputFile = node.Attributes ["inputFile"].Value;
73 if (node.Attributes ["uniqueId"] != null)
74 UniqueId = node.Attributes ["uniqueId"].Value;
76 if (node.Attributes ["name"] != null)
77 Name = node.Attributes ["name"].Value;
79 if (node.Attributes ["timeout"] != null)
80 Timeout = Convert.ToInt32 (node.Attributes ["timeout"].Value);
82 if (node.Attributes ["runs"] != null)
83 Runs = Convert.ToInt32 (node.Attributes ["runs"].Value);
85 if (node.Attributes ["width"] != null)
86 Width = Convert.ToInt32 (node.Attributes ["width"].Value);
88 if (node.Attributes ["height"] != null)
89 Height = Convert.ToInt32 (node.Attributes ["height"].Value);
92 public bool IsValid ()
94 if (StartTime < 0)
95 return false;
97 if (EndTime < 0)
98 return false;
100 if (EndTime < StartTime)
101 return false;
103 if (InputFile == String.Empty)
104 return false;
106 if (UniqueId == String.Empty)
107 return false;
109 if (Interval < 0)
110 return false;
112 if (Name == String.Empty)
113 return false;
115 if (Timeout < 1000)
116 return false;
118 if (Width < 1 || Height < 1)
119 return false;
121 if (Runs < 1)
122 return false;
124 return true;
127 public DrtResult Run ()
129 DrtResult result = null;
130 Process proc = new Process ();
132 try {
133 string tmpFileName = Path.GetTempFileName ();
135 string arguments = String.Format ("-f \"{0}\" -s \"{1}\" -e \"{2}\" -i \"{3}\" -n \"{4}\" -r \"{5}\" -t \"{6}\" -w \"{7}\" -h \"{8}\"",
136 FullFileName,
137 StartTime,
138 EndTime,
139 Interval,
140 Runs,
141 tmpFileName,
142 Timeout,
143 Width,
144 Height);
146 proc.EnableRaisingEvents = false;
147 proc.StartInfo.FileName = "perf-tool";
148 proc.StartInfo.Arguments = arguments;
149 proc.Start();
150 proc.WaitForExit();
152 if (proc.ExitCode == 0)
153 result = new DrtResult (tmpFileName);
154 } catch {
155 result = null;
156 } finally {
157 proc.Close ();
158 proc.Dispose ();
161 return result;
164 public override string ToString ()
166 return String.Format ("{0} - {1}", UniqueId, Name);