[hyena] Store sample data by category too
- From: Gabriel Burt <gburt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [hyena] Store sample data by category too
- Date: Wed, 26 May 2010 02:33:15 +0000 (UTC)
commit 9c744cd74f30618bb22c628f7bf21ffc7006902e
Author: Gabriel Burt <gabriel burt gmail com>
Date: Fri Feb 12 07:27:30 2010 -0800
Store sample data by category too
Also, add assembly name/version default metrics.
src/Hyena/Hyena.Metrics/DbSampleStore.cs | 2 +-
src/Hyena/Hyena.Metrics/MemorySampleStore.cs | 2 +-
src/Hyena/Hyena.Metrics/Metric.cs | 14 ++++++++++++++
src/Hyena/Hyena.Metrics/MetricsCollection.cs | 12 ++++++------
src/Hyena/Hyena.Metrics/Sample.cs | 2 +-
5 files changed, 23 insertions(+), 9 deletions(-)
---
diff --git a/src/Hyena/Hyena.Metrics/DbSampleStore.cs b/src/Hyena/Hyena.Metrics/DbSampleStore.cs
index ff6a9f3..dc37d35 100644
--- a/src/Hyena/Hyena.Metrics/DbSampleStore.cs
+++ b/src/Hyena/Hyena.Metrics/DbSampleStore.cs
@@ -46,7 +46,7 @@ namespace Hyena.Metrics
public IEnumerable<Sample> GetFor (Metric metric)
{
- return FetchAllMatching ("MetricName = ? ORDER BY Stamp ASC", metric.Name);
+ return FetchAllMatching ("MetricName = ? ORDER BY Stamp ASC", metric.FullName);
}
public void Clear ()
diff --git a/src/Hyena/Hyena.Metrics/MemorySampleStore.cs b/src/Hyena/Hyena.Metrics/MemorySampleStore.cs
index 00ad1a4..274fe1c 100644
--- a/src/Hyena/Hyena.Metrics/MemorySampleStore.cs
+++ b/src/Hyena/Hyena.Metrics/MemorySampleStore.cs
@@ -46,7 +46,7 @@ namespace Hyena.Metrics
public IEnumerable<Sample> GetFor (Metric metric)
{
- return this[metric.Name];
+ return this[metric.FullName];
}
}
}
diff --git a/src/Hyena/Hyena.Metrics/Metric.cs b/src/Hyena/Hyena.Metrics/Metric.cs
index 3d26ab8..1eb3048 100644
--- a/src/Hyena/Hyena.Metrics/Metric.cs
+++ b/src/Hyena/Hyena.Metrics/Metric.cs
@@ -32,6 +32,10 @@ namespace Hyena.Metrics
{
public sealed class Metric : IDisposable
{
+ public string FullName {
+ get { return String.Format ("{0}.{1}", Category, Name); }
+ }
+
public string Category { get; private set; }
public string Name { get; private set; }
public bool IsEventDriven { get; private set; }
@@ -46,6 +50,12 @@ namespace Hyena.Metrics
this.store = store;
sample_func = sampleFunc;
IsEventDriven = isEventDriven;
+
+ if (!isEventDriven) {
+ // Take the sample and forget the delegate so it can be GC'd
+ TakeSample ();
+ sample_func = null;
+ }
}
public void Dispose ()
@@ -54,6 +64,10 @@ namespace Hyena.Metrics
public void TakeSample ()
{
+ if (sample_func == null) {
+ throw new InvalidOperationException ("sampleFunc is null. Are you calling TakeSample on a non-event-driven metric?");
+ }
+
store.Add (new Sample (this, sample_func ()));
}
}
diff --git a/src/Hyena/Hyena.Metrics/MetricsCollection.cs b/src/Hyena/Hyena.Metrics/MetricsCollection.cs
index 33ca22c..f2eb02e 100644
--- a/src/Hyena/Hyena.Metrics/MetricsCollection.cs
+++ b/src/Hyena/Hyena.Metrics/MetricsCollection.cs
@@ -52,11 +52,6 @@ namespace Hyena.Metrics
{
var metric = new Metric (category, metricName, Store, sampleFunc, isEventDriven);
Add (metric);
-
- if (!metric.IsEventDriven) {
- metric.TakeSample ();
- }
-
return metric;
}
@@ -95,6 +90,11 @@ namespace Hyena.Metrics
Add ("Env", ".NET Runtime Version", () => System.Environment.Version);
Add ("Env", "Debugging", () => ApplicationContext.Debugging);
Add ("Env", "CultureInfo", () => System.Globalization.CultureInfo.CurrentCulture.Name);
+
+ foreach (var asm in AppDomain.CurrentDomain.GetAssemblies ()) {
+ var name = asm.GetName ();
+ Add ("Assemblies", name.Name, () => name.Version);
+ }
}
}
-}
+}
\ No newline at end of file
diff --git a/src/Hyena/Hyena.Metrics/Sample.cs b/src/Hyena/Hyena.Metrics/Sample.cs
index 5cab6a2..14ea375 100644
--- a/src/Hyena/Hyena.Metrics/Sample.cs
+++ b/src/Hyena/Hyena.Metrics/Sample.cs
@@ -48,7 +48,7 @@ namespace Hyena.Metrics
public Sample (Metric metric, object value)
{
- MetricName = metric.Name;
+ MetricName = metric.FullName;
Stamp = DateTime.Now;
Value = value == null ? "" : value.ToString ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]