Enable analytics in UWP sample app
このコミットが含まれているのは:
1 親
c06594c0d0
コミット
66994c6333
11ファイル変更
+139
-20
検索条件に一致するファイルはありません
@@ -9,6 +9,7 @@
|
||||
<Import_RootNamespace>ComputeSharp.SwapChain.Core.Shared</Import_RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Constants\Event.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\RenderingPauseConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Converters\ResolutionScaleConverter.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Models\ComputeShader.cs" />
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace ComputeSharp.SwapChain.Core.Constants;
|
||||
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with the collection of tracked events for analytics.
|
||||
/// </summary>
|
||||
public static class Event
|
||||
{
|
||||
public const string IsDynamicResolutionEnabledChanged = "[SETTINGS] IsDynamicResolutionEnabled";
|
||||
public const string SelectedResolutionScaleChanged = "[SETTINGS] SelectedResolutionScale";
|
||||
public const string SelectedComputeShaderChanged = "[SETTINGS] SelectedComputeShader";
|
||||
public const string IsRenderingPausedChanged = "[SETTINGS] IsRenderingPaused";
|
||||
public const string OpenShaderSelectionPanel = "[SHELL] Open ShaderSelectionPanel";
|
||||
public const string CloseShaderSelectionPanel = "[SHELL] Close ShaderSelectionPanel";
|
||||
public const string RenderingFailedOnMainPanel = "[SHELL] RenderingFailed (main panel)";
|
||||
public const string RenderingFailedOnSelectionPanel = "[SHELL] RenderingFailed (selection panel)";
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
#nullable enable
|
||||
@@ -11,7 +12,7 @@ namespace ComputeSharp.SwapChain.Core.Services;
|
||||
public sealed class DebugAnalyticsService : IAnalyticsService
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public void Log(string title, params (string Property, string Value)[]? data)
|
||||
public void Log(string title, params (string Property, object? Value)[]? data)
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
|
||||
@@ -21,7 +22,28 @@ public sealed class DebugAnalyticsService : IAnalyticsService
|
||||
{
|
||||
foreach (var info in data)
|
||||
{
|
||||
builder.AppendLine($">> {info.Property}: \"{info.Value}\"");
|
||||
builder.AppendLine($">> {info.Property}: \"{info.Value ?? "<NULL>"}\"");
|
||||
}
|
||||
}
|
||||
|
||||
Trace.Write(builder);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Log(string title, Exception exception, params (string Property, object? Value)[]? data)
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
|
||||
builder.AppendLine($"[EXCEPTION]: \"{title}\"");
|
||||
builder.AppendLine($">> Type: \"{exception.GetType()}\"");
|
||||
builder.AppendLine(">> Stack trace");
|
||||
builder.AppendLine(exception.StackTrace);
|
||||
|
||||
if (data is not null)
|
||||
{
|
||||
foreach (var info in data)
|
||||
{
|
||||
builder.AppendLine($">> {info.Property}: \"{info.Value ?? "<NULL>"}\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp.SwapChain.Core.Services;
|
||||
|
||||
@@ -12,5 +14,13 @@ public interface IAnalyticsService
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the event to track.</param>
|
||||
/// <param name="data">The optional event properties.</param>
|
||||
void Log(string title, params (string Property, string Value)[]? data);
|
||||
void Log(string title, params (string Property, object? Value)[]? data);
|
||||
|
||||
/// <summary>
|
||||
/// Logs an exception with a specified title and optional properties.
|
||||
/// </summary>
|
||||
/// <param name="title">The title of the event to track.</param>
|
||||
/// <param name="exception">The exception that has been thrown.</param>
|
||||
/// <param name="data">The optional event properties.</param>
|
||||
void Log(string title, Exception exception, params (string Property, object? Value)[]? data);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using ComputeSharp.SwapChain.Core.Constants;
|
||||
using ComputeSharp.SwapChain.Core.Models;
|
||||
using ComputeSharp.SwapChain.Core.Services;
|
||||
using ComputeSharp.SwapChain.Core.Shaders.Runners;
|
||||
@@ -56,7 +57,13 @@ public sealed class MainViewModel : ObservableObject
|
||||
public bool IsDynamicResolutionEnabled
|
||||
{
|
||||
get => this.isDynamicResolutionEnabled;
|
||||
set => SetProperty(ref this.isDynamicResolutionEnabled, value);
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref this.isDynamicResolutionEnabled, value))
|
||||
{
|
||||
this.analyticsService.Log(Event.IsDynamicResolutionEnabledChanged, (nameof(value), value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int selectedResolutionScale;
|
||||
@@ -67,7 +74,13 @@ public sealed class MainViewModel : ObservableObject
|
||||
public int SelectedResolutionScale
|
||||
{
|
||||
get => this.selectedResolutionScale;
|
||||
private set => SetProperty(ref this.selectedResolutionScale, value);
|
||||
private set
|
||||
{
|
||||
if (SetProperty(ref this.selectedResolutionScale, value))
|
||||
{
|
||||
this.analyticsService.Log(Event.SelectedResolutionScaleChanged, (nameof(value), value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -115,6 +128,8 @@ public sealed class MainViewModel : ObservableObject
|
||||
if (SetProperty(ref this.selectedComputeShader, value) &&
|
||||
value is not null)
|
||||
{
|
||||
this.analyticsService.Log(Event.SelectedComputeShaderChanged, (nameof(value.ShaderRunner), value.ShaderRunner));
|
||||
|
||||
value.IsSelected = true;
|
||||
}
|
||||
}
|
||||
@@ -128,7 +143,13 @@ public sealed class MainViewModel : ObservableObject
|
||||
public bool IsRenderingPaused
|
||||
{
|
||||
get => this.isRenderingPaused;
|
||||
set => SetProperty(ref this.isRenderingPaused, value);
|
||||
set
|
||||
{
|
||||
if (SetProperty(ref this.isRenderingPaused, value))
|
||||
{
|
||||
this.analyticsService.Log(Event.IsRenderingPausedChanged, (nameof(value), value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -25,7 +25,7 @@ public static class AssemblyExtensions
|
||||
|
||||
try
|
||||
{
|
||||
string manifestFilename = $"{assembly.FullName}.{filename.Replace('/', '.').Replace('\\', '.')}";
|
||||
string manifestFilename = $"{assembly.GetName().Name}.{filename.Replace('/', '.').Replace('\\', '.')}";
|
||||
|
||||
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestFilename);
|
||||
using StreamReader reader = new(stream);
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<Identity
|
||||
Name="26577SergioPedri.ComputeSharpSampleApp"
|
||||
Publisher="CN=46C587B2-48EE-4200-9544-40C64534E565"
|
||||
Version="1.0.0.0" />
|
||||
Version="0.0.5.0" />
|
||||
|
||||
<mp:PhoneIdentity PhoneProductId="85b5430e-b15d-4364-a837-e4c49f3f3f77" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
|
||||
|
||||
@@ -48,4 +48,8 @@
|
||||
</uap:VisualElements>
|
||||
</Application>
|
||||
</Applications>
|
||||
|
||||
<Capabilities>
|
||||
<Capability Name="internetClient"/>
|
||||
</Capabilities>
|
||||
</Package>
|
||||
@@ -17,5 +17,10 @@
|
||||
|
||||
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
|
||||
<Application>
|
||||
|
||||
<!-- Shader types need their info preserved for logging -->
|
||||
<Type Name="ComputeSharp.Uwp.ShaderRunner`1" Activate="Required Public" />
|
||||
<Namespace Name="ComputeSharp.SwapChain.Core.Shaders.Runners" Activate="Required Public" />
|
||||
<Namespace Name="ComputeSharp.SwapChain.Shaders" Activate="Required Public" />
|
||||
</Application>
|
||||
</Directives>
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using ComputeSharp.SwapChain.Core.Services;
|
||||
using Microsoft.AppCenter;
|
||||
using Microsoft.AppCenter.Analytics;
|
||||
@@ -28,14 +28,34 @@ public sealed class AppCenterService : IAnalyticsService
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void Log(string title, params (string Property, string Value)[]? data)
|
||||
public void Log(string title, params (string Property, object? Value)[]? data)
|
||||
{
|
||||
IDictionary<string, string>? properties = data?.ToDictionary(
|
||||
pair => pair.Property,
|
||||
pair => pair.Value.Length <= PropertyStringMaxLength
|
||||
? pair.Value
|
||||
: $"|{pair.Value.Substring(pair.Value.Length - PropertyStringMaxLength)}");
|
||||
Analytics.TrackEvent(title, GetProperties(data));
|
||||
}
|
||||
|
||||
Analytics.TrackEvent(title, properties);
|
||||
/// <inheritdoc/>
|
||||
public void Log(string title, Exception exception, params (string Property, object? Value)[]? data)
|
||||
{
|
||||
Crashes.TrackError(exception, GetProperties(data));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the additional logging properties from the input data.
|
||||
/// </summary>
|
||||
/// <param name="data">The optional event properties.</param>
|
||||
/// <returns>The additional logging properties to track.</returns>
|
||||
private static IDictionary<string, string>? GetProperties((string Property, object? Value)[]? data)
|
||||
{
|
||||
return
|
||||
data?.ToDictionary(
|
||||
pair => pair.Property,
|
||||
pair =>
|
||||
{
|
||||
string text = (pair.Value ?? "<NULL>").ToString();
|
||||
|
||||
return text.Length <= PropertyStringMaxLength
|
||||
? text
|
||||
: $"|{text.Substring(text.Length - PropertyStringMaxLength)}";
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@
|
||||
<Grid>
|
||||
|
||||
<!-- Shader preview -->
|
||||
<computesharp:AnimatedComputeShaderPanel ShaderRunner="{x:Bind ShaderRunner}" />
|
||||
<computesharp:AnimatedComputeShaderPanel RenderingFailed="SelectionShaderPanel_RenderingFailed" ShaderRunner="{x:Bind ShaderRunner}" />
|
||||
|
||||
<!--
|
||||
Note: here we have a selection property to work around {x:Bind} not working correctly outside of the
|
||||
@@ -154,6 +154,7 @@
|
||||
Grid.Row="1"
|
||||
IsDynamicResolutionEnabled="{x:Bind ViewModel.IsDynamicResolutionEnabled, Mode=OneWay}"
|
||||
IsPaused="{x:Bind ViewModel.IsRenderingPaused, Mode=OneWay}"
|
||||
RenderingFailed="MainShaderPanel_RenderingFailed"
|
||||
ResolutionScale="{x:Bind converters:ResolutionScaleConverter.ConvertPercentageToScale(ViewModel.SelectedResolutionScale), Mode=OneWay}"
|
||||
ShaderRunner="{x:Bind ViewModel.SelectedComputeShader.ShaderRunner, Mode=OneWay}" />
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using ComputeSharp.SwapChain.Core.Constants;
|
||||
using ComputeSharp.SwapChain.Core.Services;
|
||||
using ComputeSharp.SwapChain.Core.ViewModels;
|
||||
using ComputeSharp.Uwp;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Input;
|
||||
@@ -26,6 +29,8 @@ public sealed partial class MainView : UserControl
|
||||
// Opens the shader selection panel
|
||||
private void OpenShaderSelectionPanelButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Ioc.Default.GetRequiredService<IAnalyticsService>().Log(Event.OpenShaderSelectionPanel);
|
||||
|
||||
Root.Resources.Remove("ShaderSelectionPanel");
|
||||
Root.Children.Add(ShaderSelectionPanel);
|
||||
}
|
||||
@@ -33,6 +38,8 @@ public sealed partial class MainView : UserControl
|
||||
// Hides the shader selection panel
|
||||
private void ShaderSelectionPanel_Tapped(object sender, TappedRoutedEventArgs e)
|
||||
{
|
||||
Ioc.Default.GetRequiredService<IAnalyticsService>().Log(Event.CloseShaderSelectionPanel);
|
||||
|
||||
Root.Children.Remove(ShaderSelectionPanel);
|
||||
}
|
||||
|
||||
@@ -41,4 +48,16 @@ public sealed partial class MainView : UserControl
|
||||
{
|
||||
ShadersListContainerPanel.Height = Math.Round(e.NewSize.Height * 0.35);
|
||||
}
|
||||
|
||||
// Logs rendering failed in the main panel
|
||||
private void MainShaderPanel_RenderingFailed(AnimatedComputeShaderPanel sender, Exception args)
|
||||
{
|
||||
Ioc.Default.GetRequiredService<IAnalyticsService>().Log(Event.RenderingFailedOnMainPanel, args);
|
||||
}
|
||||
|
||||
// Logs rendering failed in a secondary panel
|
||||
private void SelectionShaderPanel_RenderingFailed(AnimatedComputeShaderPanel sender, Exception args)
|
||||
{
|
||||
Ioc.Default.GetRequiredService<IAnalyticsService>().Log(Event.RenderingFailedOnSelectionPanel, args);
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする