[banshee] [Banshee.Metrics] Add static Started/Stopped events
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [banshee] [Banshee.Metrics] Add static Started/Stopped events
- Date: Fri, 12 Feb 2010 21:57:32 +0000 (UTC)
commit 87f80a4697550705a313b43d11f92f7676ce2210
Author: Gabriel Burt <gabriel burt gmail com>
Date: Fri Feb 12 13:56:08 2010 -0800
[Banshee.Metrics] Add static Started/Stopped events
Allows code elsewhere to add metrics when appropriate.
.../Banshee.Metrics/BansheeMetrics.cs | 34 +++++++++++++++----
1 files changed, 27 insertions(+), 7 deletions(-)
---
diff --git a/src/Core/Banshee.Services/Banshee.Metrics/BansheeMetrics.cs b/src/Core/Banshee.Services/Banshee.Metrics/BansheeMetrics.cs
index 13defe3..ac8685f 100644
--- a/src/Core/Banshee.Services/Banshee.Metrics/BansheeMetrics.cs
+++ b/src/Core/Banshee.Services/Banshee.Metrics/BansheeMetrics.cs
@@ -42,8 +42,12 @@ namespace Banshee.Metrics
public class BansheeMetrics : IDisposable
{
private static BansheeMetrics banshee_metrics;
+
public BansheeMetrics Instance { get { return banshee_metrics; } }
+ public static event System.Action Started;
+ public static event System.Action Stopped;
+
public static void Start ()
{
Log.Information ("Starting collection of anonymous usage data");
@@ -69,7 +73,7 @@ namespace Banshee.Metrics
private MetricsCollection metrics;
private string id_key = "AnonymousUsageData.Userid";
- private Metric shutdown, duration, source_changed;
+ private Metric shutdown, duration, source_changed, sqlite_executed;
private BansheeMetrics ()
{
@@ -98,6 +102,11 @@ namespace Banshee.Metrics
metrics.AddDefaults ();
AddMetrics ();
+ var handler = Started;
+ if (handler != null) {
+ handler ();
+ }
+
// TODO schedule sending the data to the server in some timeout?
// TODO remove this, just for testing
@@ -150,7 +159,10 @@ namespace Banshee.Metrics
duration = Add ("RunDuration", () => DateTime.Now - ApplicationContext.StartedAt, true);
Application.ShutdownRequested += OnShutdownRequested;
- // TODO add Mono.Addins extension point for metric providers?
+ sqlite_executed = Add ("LongSqliteCommand", null, true);
+ HyenaSqliteCommand.CommandExecuted += OnSqliteCommandExecuted;
+ HyenaSqliteCommand.RaiseCommandExecuted = true;
+ HyenaSqliteCommand.RaiseCommandExecutedThresholdMs = 400;
}
public Metric Add (string name, Func<object> func)
@@ -165,9 +177,15 @@ namespace Banshee.Metrics
public void Dispose ()
{
+ var handler = Stopped;
+ if (handler != null) {
+ handler ();
+ }
+
// Disconnect from events we're listening to
ServiceManager.SourceManager.ActiveSourceChanged -= OnActiveSourceChanged;
Application.ShutdownRequested -= OnShutdownRequested;
+ HyenaSqliteCommand.CommandExecuted -= OnSqliteCommandExecuted;
// Delete any collected data
metrics.Store.Clear ();
@@ -187,14 +205,16 @@ namespace Banshee.Metrics
private bool OnShutdownRequested ()
{
- try {
- shutdown.TakeSample ();
- duration.TakeSample ();
- } catch {}
-
+ shutdown.TakeSample ();
+ duration.TakeSample ();
return true;
}
+ private void OnSqliteCommandExecuted (object o, CommandExecutedArgs args)
+ {
+ sqlite_executed.PushSample (String.Format ("{0}ms -- {1}", args.Ms, args.Sql));
+ }
+
#endregion
public static SchemaEntry<bool> EnableCollection = new SchemaEntry<bool> (
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]