diff options
author | Gabriel Burt <gabriel.burt@gmail.com> | 2010-03-01 16:49:53 -0800 |
---|---|---|
committer | Gabriel Burt <gabriel.burt@gmail.com> | 2010-03-01 16:49:53 -0800 |
commit | c88ee9c92286b5426edf8da01e364d3aaa1b5e2b (patch) | |
tree | aac238072b30d1be184684151d11e31212b55f0c /extras | |
parent | e166a3ac0fdece6d1b869193df00c122ac479bf5 (diff) |
[extras/metrics] Better analysis
Diffstat (limited to 'extras')
-rw-r--r-- | extras/metrics/Makefile.am | 1 | ||||
-rw-r--r-- | extras/metrics/MetaMetrics.cs | 16 | ||||
-rw-r--r-- | extras/metrics/Metric.cs | 158 | ||||
-rw-r--r-- | extras/metrics/metrics.csproj | 2 |
4 files changed, 170 insertions, 7 deletions
diff --git a/extras/metrics/Makefile.am b/extras/metrics/Makefile.am index 99e080aed..037276679 100644 --- a/extras/metrics/Makefile.am +++ b/extras/metrics/Makefile.am @@ -4,6 +4,7 @@ LINK = $(LINK_HYENA_DEPS) SOURCES = \ Database.cs \ Main.cs \ + Metric.cs \ MetaMetrics.cs \ MultiUserSample.cs diff --git a/extras/metrics/MetaMetrics.cs b/extras/metrics/MetaMetrics.cs index 00ce9a3ed..41bc060bb 100644 --- a/extras/metrics/MetaMetrics.cs +++ b/extras/metrics/MetaMetrics.cs @@ -88,7 +88,7 @@ namespace metrics public class MetaMetrics { - string fmt = "{0,20:N1}"; + string fmt = "{0,20}"; public MetaMetrics (HyenaSqliteConnection db) { @@ -114,6 +114,7 @@ namespace metrics Console.WriteLine (" {0,-5}: {1,-20}", reader.Get<long> (0), reader.Get<string> (1)); } } + Console.WriteLine (); }; var numeric_slice = new MetricSampleModel (latest_samples.Cache, db, @@ -123,10 +124,10 @@ namespace metrics numeric_slice.Cache.AggregatesUpdated += (reader) => { Console.WriteLine (String.Format (" Users: {0}", fmt), reader[5]); - Console.WriteLine (String.Format (" Min: {0}", fmt), reader[1]); - Console.WriteLine (String.Format (" Avg: {0}", fmt), reader[3]); - Console.WriteLine (String.Format (" Median: {0}", fmt), reader[4]); - Console.WriteLine (String.Format (" Max: {0}", fmt), reader[2]); + Console.WriteLine (String.Format (" Min: {0}", fmt), Metric.ToString (numeric_slice.MetricName, reader[1])); + Console.WriteLine (String.Format (" Avg: {0}", fmt), Metric.ToString (numeric_slice.MetricName, reader[3])); + Console.WriteLine (String.Format (" Median: {0}", fmt), Metric.ToString (numeric_slice.MetricName, reader[4])); + Console.WriteLine (String.Format (" Max: {0}", fmt), Metric.ToString (numeric_slice.MetricName, reader[2])); Console.WriteLine (); }; @@ -162,10 +163,11 @@ namespace metrics if (name.EndsWith ("BuildTime")) return "datetime"; - if (name.EndsWith ("LongSqliteCommand") || name.EndsWith ("At")) + if (name.EndsWith ("LongSqliteCommand") || name.EndsWith ("At") || name.StartsWith ("Assemblies/") || + name.EndsWith ("child_sort_id") || name.EndsWith ("separate_by_type") || name.EndsWith ("expanded")) return null; return "string"; } } -}
\ No newline at end of file +} diff --git a/extras/metrics/Metric.cs b/extras/metrics/Metric.cs new file mode 100644 index 000000000..105cc2fe4 --- /dev/null +++ b/extras/metrics/Metric.cs @@ -0,0 +1,158 @@ +// +// Metric.cs +// +// Author: +// Gabriel Burt <gabriel.burt@gmail.com> +// +// Copyright (c) 2010 Novell, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Linq; + +using Hyena; +using Hyena.Metrics; +using Hyena.Data.Sqlite; +using Hyena.Json; +using Mono.Data.Sqlite; +using System.Collections.Generic; +using Hyena.Query; + +namespace metrics +{ + public class Metric + { + static Metric () + { + var time = new Func<double, string> (d => String.Format ("{0:N0}", SqliteUtils.FromDbFormat (typeof(DateTime), d))); + var duration = new Func<double, string> (d => String.Format ("{0:N0}", TimeSpan.FromMilliseconds (d))); + var duration_s = new Func<double, string> (d => String.Format ("{0:N0}", TimeSpan.FromSeconds (d))); + var px = new Func<double, string> (d => String.Format ("{0:N0} px", d)); + + Add ( + "/AvgBitRate", new Func<double, string> (d => String.Format ("{0:N0} kbps", d)), + "/AvgScore", + "/BpmTrackCount", + "/ComposerTrackCount", + "/ErrorTrackCount", + "/GroupingTrackCount", + "/LicenseUriTrackCount", + "/RatedTrackCount", + "/TotalFileSize", new Func<double, string> (d => new FileSizeQueryValue ((long)d).ToUserQuery ()), + "/TotalPlayCount", + "/TotalPlaySeconds", duration_s, + "/TotalSkipCount", + "/TrackCount", + "/UnplayedTrackCount", + + "Banshee/BuildTime", time, + "Banshee/Configuration/browser/position", px, + + "Banshee/Configuration/player_window/height", px, + "Banshee/Configuration/player_window/source_view_row_height", px, + "Banshee/Configuration/player_window/source_view_row_padding", px, + "Banshee/Configuration/player_window/source_view_width", px, + "Banshee/Configuration/player_window/width", px, + + "Banshee/Configuration/player_window/x_pos", + "Banshee/Configuration/player_window/y_pos", + + "Banshee/Configuration/plugins.mtp/albumart_max_width", px, + + "Banshee/Configuration/plugins.play_queue/played_songs_number", + "Banshee/Configuration/plugins.play_queue/upcoming_songs_number", + + "Banshee/Display/NScreens", + + "Banshee/Screen/Height", px, + "Banshee/Screen/Width", px, + "Banshee/Screen/NMonitors", + "Banshee/ShutdownAt", time, + "Banshee/StartedAt", time, + "Env/Processor Count", + + "Banshee/RunDuration", duration + ); + } + + private static List<Metric> metrics = new List<Metric> (); + private static Func<double, string> num_func = new Func<double, string> (d => String.Format ("{0,20:N1}", d)); + + private static void Add (params object [] args) + { + for (int i = 0; i < args.Length; i++) { + string key = (string)args[i]; + Func<double, string> func = null; + if (i < args.Length - 1) { + func = args[i + 1] as Func<double, string>; + if (func != null) { + i++; + } + } + + metrics.Add (new Metric (key, func ?? num_func)); + } + } + + public static string ToString (string key, object d) + { + return ToString (key, Convert.ToDouble (d)); + } + + public static string ToString (string key, double d) + { + var metric = metrics.FirstOrDefault (m => m.Matching (key)); + if (metric != null) { + return metric.ToString (d); + } else { + return num_func (d); + } + } + + private string key; + private bool ends_with; + private Func<double, string> func; + + public Metric (string key, Func<double, string> func) + { + this.key = key; + this.func = func; + this.ends_with = key[0] == '/'; + } + + public string ToString (double val) + { + try { + return func (val); + } catch (Exception e) { + return e.Message; + } + } + + public bool Matching (string key) + { + if (ends_with) { + return key.EndsWith (this.key); + } else { + return key == this.key; + } + } + } +} diff --git a/extras/metrics/metrics.csproj b/extras/metrics/metrics.csproj index 836241079..dd698accc 100644 --- a/extras/metrics/metrics.csproj +++ b/extras/metrics/metrics.csproj @@ -30,12 +30,14 @@ </PropertyGroup> <ItemGroup> <Reference Include="System" /> + <Reference Include="System.Core" /> </ItemGroup> <ItemGroup> <Compile Include="MultiUserSample.cs" /> <Compile Include="MetaMetrics.cs" /> <Compile Include="Main.cs" /> <Compile Include="Database.cs" /> + <Compile Include="Metric.cs" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\src\Libraries\Hyena\Hyena.csproj"> |