Z3
Statistics.cs
Go to the documentation of this file.
1/*++
2Copyright (c) 2012 Microsoft Corporation
3
4Module Name:
5
6 Statistics.cs
7
8Abstract:
9
10 Z3 Managed API: Statistics
11
12Author:
13
14 Christoph Wintersteiger (cwinter) 2012-03-22
15
16Notes:
17
18--*/
19
20using System;
21using System.Diagnostics;
22
23
24namespace Microsoft.Z3
25{
26
27 using Z3_context = System.IntPtr;
28 using Z3_stats = System.IntPtr;
32 public class Statistics : Z3Object
33 {
38 public class Entry
39 {
43 readonly public string Key;
47 public uint UIntValue { get { return m_uint; } }
51 public double DoubleValue { get { return m_double; } }
55 public bool IsUInt { get { return m_is_uint; } }
59 public bool IsDouble { get { return m_is_double; } }
60
64 public string Value
65 {
66 get
67 {
68
69 if (IsUInt)
70 return m_uint.ToString();
71 else if (IsDouble)
72 return m_double.ToString();
73 else
74 throw new Z3Exception("Unknown statistical entry type");
75 }
76 }
77
81 public override string ToString()
82 {
83 return Key + ": " + Value;
84 }
85
86 #region Internal
87 readonly private bool m_is_uint = false;
88 readonly private bool m_is_double = false;
89 readonly private uint m_uint = 0;
90 readonly private double m_double = 0.0;
91 internal Entry(string k, uint v)
92 {
93 Key = k;
94 m_is_uint = true;
95 m_uint = v;
96 }
97 internal Entry(string k, double v)
98 {
99 Key = k;
100 m_is_double = true;
101 m_double = v;
102 }
103 #endregion
104 }
105
109 public override string ToString()
110 {
111 return Native.Z3_stats_to_string(Context.nCtx, NativeObject);
112 }
113
117 public uint Size
118 {
119 get { return Native.Z3_stats_size(Context.nCtx, NativeObject); }
120 }
121
125 public Entry[] Entries
126 {
127 get
128 {
129 return NativeEntries(Context.nCtx, NativeObject);
130 }
131 }
132
133 internal static Entry[] NativeEntries(Z3_context ctx, Z3_stats stats)
134 {
135 uint n = Native.Z3_stats_size(ctx, stats);
136 Entry[] res = new Entry[n];
137 for (uint i = 0; i < n; i++)
138 {
139 Entry e;
140 string k = Native.Z3_stats_get_key(ctx, stats, i);
141 if (Native.Z3_stats_is_uint(ctx, stats, i) != 0)
142 e = new Entry(k, Native.Z3_stats_get_uint_value(ctx, stats, i));
143 else if (Native.Z3_stats_is_double(ctx, stats, i) != 0)
144 e = new Entry(k, Native.Z3_stats_get_double_value(ctx, stats, i));
145 else
146 throw new Z3Exception("Unknown data entry value");
147 res[i] = e;
148 }
149 return res;
150 }
151
155 public string[] Keys
156 {
157 get
158 {
159
160 uint n = Size;
161 string[] res = new string[n];
162 for (uint i = 0; i < n; i++)
163 res[i] = Native.Z3_stats_get_key(Context.nCtx, NativeObject, i);
164 return res;
165 }
166 }
167
172 public Entry this[string key]
173 {
174 get
175 {
176 uint n = Size;
177 Entry[] es = Entries;
178 for (uint i = 0; i < n; i++)
179 if (es[i].Key == key)
180 return es[i];
181 return null;
182 }
183 }
184
185 #region Internal
186 internal Statistics(Context ctx, IntPtr obj)
187 : base(ctx, obj)
188 {
189 Debug.Assert(ctx != null);
190 }
191
192 internal class DecRefQueue : IDecRefQueue
193 {
194 public DecRefQueue() : base() { }
195 public DecRefQueue(uint move_limit) : base(move_limit) { }
196 internal override void IncRef(Context ctx, IntPtr obj)
197 {
198 Native.Z3_stats_inc_ref(ctx.nCtx, obj);
199 }
200
201 internal override void DecRef(Context ctx, IntPtr obj)
202 {
203 Native.Z3_stats_dec_ref(ctx.nCtx, obj);
204 }
205 };
206
207 internal override void IncRef(IntPtr o)
208 {
209 Context.Statistics_DRQ.IncAndClear(Context, o);
210 base.IncRef(o);
211 }
212
213 internal override void DecRef(IntPtr o)
214 {
215 Context.Statistics_DRQ.Add(o);
216 base.DecRef(o);
217 }
218 #endregion
219 }
220}
The main interaction with Z3 happens via the Context.
Definition: Context.cs:34
IDecRefQueue Statistics_DRQ
Statistics DRQ
Definition: Context.cs:4953
Statistical data is organized into pairs of [Key, Entry], where every Entry is either a DoubleEntry o...
Definition: Statistics.cs:39
double DoubleValue
The double-value of the entry.
Definition: Statistics.cs:51
readonly string Key
The key of the entry.
Definition: Statistics.cs:43
uint UIntValue
The uint-value of the entry.
Definition: Statistics.cs:47
bool IsDouble
True if the entry is double-valued.
Definition: Statistics.cs:59
bool IsUInt
True if the entry is uint-valued.
Definition: Statistics.cs:55
override string ToString()
The string representation of the Entry.
Definition: Statistics.cs:81
string Value
The string representation of the entry's value.
Definition: Statistics.cs:65
Objects of this class track statistical information about solvers.
Definition: Statistics.cs:33
string[] Keys
The statistical counters.
Definition: Statistics.cs:156
uint Size
The number of statistical data.
Definition: Statistics.cs:118
override string ToString()
A string representation of the statistical data.
Definition: Statistics.cs:109
Entry[] Entries
The data entries.
Definition: Statistics.cs:126
The exception base class for error reporting from Z3
Definition: Z3Exception.cs:32
Internal base class for interfacing with native Z3 objects. Should not be used externally.
Definition: Z3Object.cs:33
Context Context
Access Context object
Definition: Z3Object.cs:120
System.IntPtr Z3_context
Definition: Context.cs:29
System.IntPtr Z3_stats