mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 10:12:54 +08:00
Add statistics for Live
usage
This commit is contained in:
parent
56b06f34f0
commit
c7947b3489
@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using osu.Framework.Development;
|
||||
using osu.Framework.Statistics;
|
||||
using Realms;
|
||||
|
||||
#nullable enable
|
||||
@ -14,7 +15,7 @@ namespace osu.Game.Database
|
||||
/// Provides a method of working with realm objects over longer application lifetimes.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The underlying object type.</typeparam>
|
||||
public class RealmLive<T> : ILive<T> where T : RealmObject, IHasGuidPrimaryKey
|
||||
public class RealmLive<T> : RealmLive, ILive<T> where T : RealmObject, IHasGuidPrimaryKey
|
||||
{
|
||||
public Guid ID { get; }
|
||||
|
||||
@ -65,6 +66,7 @@ namespace osu.Game.Database
|
||||
}
|
||||
|
||||
perform(retrieveFromID(r, ID));
|
||||
USAGE_ASYNC.Value++;
|
||||
});
|
||||
}
|
||||
|
||||
@ -86,6 +88,7 @@ namespace osu.Game.Database
|
||||
return realm.Run(r =>
|
||||
{
|
||||
var returnData = perform(retrieveFromID(r, ID));
|
||||
USAGE_ASYNC.Value++;
|
||||
|
||||
if (returnData is RealmObjectBase realmObject && realmObject.IsManaged)
|
||||
throw new InvalidOperationException(@$"Managed realm objects should not exit the scope of {nameof(PerformRead)}.");
|
||||
@ -108,6 +111,7 @@ namespace osu.Game.Database
|
||||
var transaction = t.Realm.BeginWrite();
|
||||
perform(t);
|
||||
transaction.Commit();
|
||||
WRITES.Value++;
|
||||
});
|
||||
}
|
||||
|
||||
@ -131,10 +135,14 @@ namespace osu.Game.Database
|
||||
Debug.Assert(ThreadSafety.IsUpdateThread);
|
||||
|
||||
if (dataIsFromUpdateThread && !data.Realm.IsClosed)
|
||||
{
|
||||
USAGE_UPDATE_IMMEDIATE.Value++;
|
||||
return;
|
||||
}
|
||||
|
||||
dataIsFromUpdateThread = true;
|
||||
data = retrieveFromID(realm.Realm, ID);
|
||||
USAGE_UPDATE_REFETCH.Value++;
|
||||
}
|
||||
|
||||
private T retrieveFromID(Realm realm, Guid id)
|
||||
@ -157,4 +165,12 @@ namespace osu.Game.Database
|
||||
|
||||
public override string ToString() => PerformRead(i => i.ToString());
|
||||
}
|
||||
|
||||
public class RealmLive
|
||||
{
|
||||
protected static readonly GlobalStatistic<int> WRITES = GlobalStatistics.Get<int>(@"Realm", @"Live writes");
|
||||
protected static readonly GlobalStatistic<int> USAGE_UPDATE_IMMEDIATE = GlobalStatistics.Get<int>(@"Realm", @"Live update read (fast)");
|
||||
protected static readonly GlobalStatistic<int> USAGE_UPDATE_REFETCH = GlobalStatistics.Get<int>(@"Realm", @"Live update read (slow)");
|
||||
protected static readonly GlobalStatistic<int> USAGE_ASYNC = GlobalStatistics.Get<int>(@"Realm", @"Live async read");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user