~ubuntu-branches/ubuntu/karmic/moon/karmic

« back to all changes in this revision

Viewing changes to perf/perf-suite-generator/GraphGenerator.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-14 12:01:08 UTC
  • Revision ID: james.westby@ubuntu.com-20090214120108-06539vb25vhbd8bn
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
 
3
 *
 
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:
 
15
 * 
 
16
 * The above copyright notice and this permission notice shall be
 
17
 * included in all copies or substantial portions of the Software.
 
18
 * 
 
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.
 
27
 *
 
28
 */
 
29
 
 
30
using System;
 
31
using System.Collections.Generic;
 
32
using PerfSuiteLib;
 
33
using Cairo;
 
34
 
 
35
namespace PerfSuiteGenerator {
 
36
 
 
37
        public static class GraphGenerator {
 
38
 
 
39
                public static void GenerateGraph (List <ResultDbEntry> resultList, string filename)
 
40
                {
 
41
                        // FIXME Exception if more than 50 results...
 
42
 
 
43
                        ImageSurface surface = new ImageSurface (Format.Rgb24, 103, 52);
 
44
                        Context context = new Context (surface);
 
45
 
 
46
                        // Fill with grad
 
47
                        LinearGradient grad = new LinearGradient (0.0, 0.0, 0.0, 52.0);
 
48
                        grad.AddColorStopRgb (0.0, new Color  (1.0, 1.0, 1.0));
 
49
                        grad.AddColorStopRgb (1.0, new Color  (0.8, 0.8, 0.9));
 
50
                        context.Pattern = grad;
 
51
                        context.Paint ();
 
52
 
 
53
                        // Frame
 
54
                        context.SetSourceRGB (0, 0, 0);
 
55
                        context.LineWidth = 1.0;
 
56
                        context.Rectangle (0.5, 0.5, 102.0, 51.0);
 
57
                        context.Stroke ();
 
58
 
 
59
                        long denominator = (long) (FindBiggestResult (resultList) * 1.2);
 
60
 
 
61
                        context.LineWidth = 1.5;
 
62
 
 
63
                        // FIXME Reverse to copy
 
64
                        resultList.Reverse ();
 
65
 
 
66
                        double x = 100.5 - ((resultList.Count - 1) * 2.0);
 
67
                        bool hasPrevResult = false;
 
68
                        long prevResult = 0;
 
69
 
 
70
                        foreach (ResultDbEntry entry in resultList) {
 
71
 
 
72
                                if (entry.Failure) {
 
73
                                        x += 2.0;
 
74
                                        continue;
 
75
                                }
 
76
 
 
77
                                double sz = ((double) entry.Time / denominator) * 50.0;
 
78
 
 
79
                                if (hasPrevResult && UtilFu.GetValueDifference (prevResult, entry.Time) > 0.1)
 
80
                                        context.SetSourceRGB (1.0, 0.0, 0.0);
 
81
                                else if (hasPrevResult && UtilFu.GetValueDifference (prevResult, entry.Time) < -0.1)
 
82
                                        context.SetSourceRGB (0.0, 1.0, 0.0);
 
83
                                else
 
84
                                        context.SetSourceRGB (0.4, 0.4, 0.4);
 
85
 
 
86
                                context.MoveTo (x, 51);
 
87
                                context.LineTo (x, 51 - sz);
 
88
                                context.Stroke ();
 
89
 
 
90
                                x += 2.0;
 
91
 
 
92
                                hasPrevResult = true;
 
93
                                prevResult = entry.Time;
 
94
                        }
 
95
 
 
96
                        surface.WriteToPng (filename);
 
97
 
 
98
                        resultList.Reverse ();
 
99
                        ((IDisposable) context).Dispose ();
 
100
                        ((IDisposable) surface).Dispose ();
 
101
                }
 
102
 
 
103
                private static long FindBiggestResult (List <ResultDbEntry> resultList)
 
104
                {
 
105
                        long biggest = 0;
 
106
                        foreach (ResultDbEntry entry in resultList) 
 
107
                                biggest = Math.Max (biggest, entry.Time);
 
108
 
 
109
                        return biggest;
 
110
                }
 
111
 
 
112
        }
 
113
}
 
114
 
 
115