• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- Results.h -----------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef __PerfTestDriver_Results_h__
11 #define __PerfTestDriver_Results_h__
12 
13 #include "lldb/lldb-forward.h"
14 #include <map>
15 #include <string>
16 #include <vector>
17 
18 namespace lldb_perf {
19 
20 class Results
21 {
22 public:
23     class Array;
24     class Dictionary;
25     class Double;
26     class String;
27     class Unsigned;
28 
29     class Result
30     {
31     public:
32         enum class Type
33         {
34             Invalid,
35             Array,
36             Dictionary,
37             Double,
38             String,
39             Unsigned
40         };
41 
Result(Type type,const char * name,const char * description)42         Result (Type type, const char *name, const char *description) :
43             m_name (),
44             m_description(),
45             m_type (type)
46         {
47             if (name && name[0])
48                 m_name = name;
49             if (description && description[0])
50                 m_description = description;
51         }
52 
53         virtual
~Result()54         ~Result()
55         {
56         }
57 
58         virtual void
59         Write (Results &results) = 0;
60 
61         Array *
GetAsArray()62         GetAsArray ()
63         {
64             if (m_type == Type::Array)
65                 return (Array *)this;
66             return NULL;
67         }
68         Dictionary *
GetAsDictionary()69         GetAsDictionary ()
70         {
71             if (m_type == Type::Dictionary)
72                 return (Dictionary *)this;
73             return NULL;
74         }
75         Double *
GetAsDouble()76         GetAsDouble ()
77         {
78             if (m_type == Type::Double)
79                 return (Double *)this;
80             return NULL;
81         }
82 
83         String *
GetAsString()84         GetAsString ()
85         {
86             if (m_type == Type::String)
87                 return (String *)this;
88             return NULL;
89         }
90         Unsigned *
GetAsUnsigned()91         GetAsUnsigned ()
92         {
93             if (m_type == Type::Unsigned)
94                 return (Unsigned *)this;
95             return NULL;
96         }
97 
98         const char *
GetName()99         GetName() const
100         {
101             if (m_name.empty())
102                 return NULL;
103             return m_name.c_str();
104         }
105 
106         const char *
GetDescription()107         GetDescription() const
108         {
109             if (m_description.empty())
110                 return NULL;
111             return m_description.c_str();
112         }
113 
114         Type
GetType()115         GetType() const
116         {
117             return m_type;
118         }
119 
120     protected:
121         std::string m_name;
122         std::string m_description;
123         Type m_type;
124     };
125 
126     typedef std::shared_ptr<Result> ResultSP;
127 
128     class Array : public Result
129     {
130     public:
Array(const char * name,const char * description)131         Array (const char *name, const char *description) :
132             Result (Type::Array, name, description)
133         {
134         }
135 
136         virtual
~Array()137         ~Array()
138         {
139         }
140 
141         ResultSP
142         Append (const ResultSP &result_sp);
143 
144         void
145         ForEach (const std::function <bool (const ResultSP &)> &callback);
146 
147         virtual void
Write(Results & results)148         Write (Results &results)
149         {
150         }
151     protected:
152         typedef std::vector<ResultSP> collection;
153         collection m_array;
154     };
155 
156     class Dictionary : public Result
157     {
158     public:
Dictionary()159         Dictionary () :
160             Result (Type::Dictionary, NULL, NULL)
161         {
162         }
163 
Dictionary(const char * name,const char * description)164         Dictionary (const char *name, const char *description) :
165             Result (Type::Dictionary, name, description)
166         {
167         }
168 
169         virtual
~Dictionary()170         ~Dictionary()
171         {
172         }
173 
174         virtual void
Write(Results & results)175         Write (Results &results)
176         {
177         }
178 
179         void
180         ForEach (const std::function <bool (const std::string &, const ResultSP &)> &callback);
181 
182         ResultSP
183         Add (const char *name, const char *description, const ResultSP &result_sp);
184 
185         ResultSP
186         AddDouble (const char *name, const char *descriptiorn, double value);
187 
188         ResultSP
189         AddUnsigned (const char *name, const char *description, uint64_t value);
190 
191         ResultSP
192         AddString (const char *name, const char *description, const char *value);
193 
194     protected:
195 
196         typedef std::map<std::string, ResultSP> collection;
197         collection m_dictionary;
198     };
199 
200     class String : public Result
201     {
202     public:
String(const char * name,const char * description,const char * value)203         String (const char *name, const char *description, const char *value) :
204             Result (Type::String, name, description),
205             m_string ()
206         {
207             if (value && value[0])
208                 m_string = value;
209         }
210 
211         virtual
~String()212         ~String()
213         {
214         }
215 
216         virtual void
Write(Results & results)217         Write (Results &results)
218         {
219         }
220 
221         const char *
GetValue()222         GetValue () const
223         {
224             return m_string.empty() ? NULL : m_string.c_str();
225         }
226 
227     protected:
228         std::string m_string;
229     };
230 
231     class Double : public Result
232     {
233     public:
Double(const char * name,const char * description,double value)234         Double (const char *name, const char *description, double value) :
235             Result (Type::Double, name, description),
236             m_double (value)
237         {
238         }
239 
240         virtual
~Double()241         ~Double()
242         {
243         }
244 
245         virtual void
Write(Results & results)246         Write (Results &results)
247         {
248         }
249 
250         double
GetValue()251         GetValue () const
252         {
253             return m_double;
254         }
255 
256     protected:
257         double m_double;
258     };
259 
260     class Unsigned : public Result
261     {
262     public:
Unsigned(const char * name,const char * description,uint64_t value)263         Unsigned (const char *name, const char *description, uint64_t value) :
264             Result (Type::Unsigned, name, description),
265             m_unsigned (value)
266         {
267         }
268 
269         virtual
~Unsigned()270         ~Unsigned()
271         {
272         }
273 
274         virtual void
Write(Results & results)275         Write (Results &results)
276         {
277         }
278 
279         uint64_t
GetValue()280         GetValue () const
281         {
282             return m_unsigned;
283         }
284 
285     protected:
286         uint64_t m_unsigned;
287     };
288 
Results()289     Results () :
290         m_results ()
291     {
292     }
293 
~Results()294     ~Results()
295     {
296     }
297 
298     Dictionary &
GetDictionary()299     GetDictionary ()
300     {
301         return m_results;
302     }
303 
304     void
305     Write (const char *path);
306 
307 protected:
308     Dictionary m_results;
309 };
310 
311 } // namespace lldb_perf
312 #endif // #ifndef __PerfTestDriver_Results_h__
313