Skip to content

Commit

Permalink
Device and gpu protocols updated; public IJsonSerializable (#1063)
Browse files Browse the repository at this point in the history
* Device and gpu protocols updated; public IJsonSerializable

* GpuTests updated

* DeviceTests updated

* Update src/Sentry/Protocol/Device.cs

Co-authored-by: LucasZF <lucas-zimerman1@hotmail.com>

* CHANGELOG

* Update test/Sentry.Tests/Protocol/Context/GpuTests.cs

Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>

* Comment removed

Co-authored-by: LucasZF <lucas-zimerman1@hotmail.com>
Co-authored-by: Bruno Garcia <bruno@brunogarcia.com>
  • Loading branch information
3 people authored Jun 18, 2021
1 parent 2ac97c8 commit 9b32eee
Show file tree
Hide file tree
Showing 6 changed files with 345 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Device and gpu protocols updated; public IJsonSerializable([#1063](https://github.com/getsentry/sentry-dotnet/pull/1063))

### Features

- ASP.NET Core: Option `AdjustStandardEnvironmentNameCasing` to opt-out from lower casing env name. [#1057](https://github.com/getsentry/sentry-dotnet/pull/1057)
Expand Down
5 changes: 4 additions & 1 deletion src/Sentry/IJsonSerializable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@

namespace Sentry
{
internal interface IJsonSerializable
/// <summary>
/// Sentry JsonSerializable.
/// </summary>
public interface IJsonSerializable
{
/// <summary>
/// Writes the object as JSON.
Expand Down
170 changes: 168 additions & 2 deletions src/Sentry/Protocol/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,84 @@ public sealed class Device : IJsonSerializable
/// </example>
public DateTimeOffset? BootTime { get; set; }

/// <summary>
/// Number of "logical processors".
/// </summary>
/// <example>
/// 8
/// </example>
public int? ProcessorCount { get; set; }

/// <summary>
/// CPU description.
/// </summary>
/// <example>
/// Intel(R) Core(TM)2 Quad CPU Q6600 @ 2.40GHz
/// </example>
public string? CpuDescription { get; set; }

/// <summary>
/// Processor frequency in MHz. Note that the actual CPU frequency might vary depending on current load and power
/// conditions, especially on low-powered devices like phones and laptops. On some platforms it's not possible
/// to query the CPU frequency. Currently such platforms are iOS and WebGL.
/// </summary>
/// <example>
/// 2500
/// </example>
public int? ProcessorFrequency { get; set; }

/// <summary>
/// Kind of device the application is running on.
/// </summary>
/// <example>
/// Unknown, Handheld, Console, Desktop
/// </example>
public string? DeviceType { get; set; }

/// <summary>
/// Status of the device's battery.
/// </summary>
/// <example>
/// Unknown, Charging, Discharging, NotCharging, Full
/// </example>
public string? BatteryStatus { get; set; }

/// <summary>
/// Unique device identifier. Depends on the running platform.
/// </summary>
/// <example>
/// iOS: UIDevice.identifierForVendor (UUID)
/// Android: md5 of ANDROID_ID
/// Windows Store Apps: AdvertisingManager::AdvertisingId (possible fallback to HardwareIdentification::GetPackageSpecificToken().Id)
/// Windows Standalone: hash from the concatenation of strings taken from Computer System Hardware Classes
/// </example>
public string? DeviceUniqueIdentifier { get; set; }

/// <summary>
/// Is vibration available on the device?
/// </summary>
public bool? SupportsVibration { get; set; }

/// <summary>
/// Is accelerometer available on the device?
/// </summary>
public bool? SupportsAccelerometer { get; set; }

/// <summary>
/// Is gyroscope available on the device?
/// </summary>
public bool? SupportsGyroscope { get; set; }

/// <summary>
/// Is audio available on the device?
/// </summary>
public bool? SupportsAudio { get; set; }

/// <summary>
/// Is the device capable of reporting its location?
/// </summary>
public bool? SupportsLocationService { get; set; }

/// <summary>
/// Clones this instance.
/// </summary>
Expand Down Expand Up @@ -191,7 +269,18 @@ internal Device Clone()
StorageSize = StorageSize,
Timezone = Timezone,
UsableMemory = UsableMemory,
LowMemory = LowMemory
LowMemory = LowMemory,
ProcessorCount = ProcessorCount,
CpuDescription = CpuDescription,
ProcessorFrequency = ProcessorFrequency,
SupportsVibration = SupportsVibration,
DeviceType = DeviceType,
BatteryStatus = BatteryStatus,
DeviceUniqueIdentifier = DeviceUniqueIdentifier,
SupportsAccelerometer = SupportsAccelerometer,
SupportsGyroscope = SupportsGyroscope,
SupportsAudio = SupportsAudio,
SupportsLocationService = SupportsLocationService
};

/// <inheritdoc />
Expand Down Expand Up @@ -332,6 +421,61 @@ public void WriteTo(Utf8JsonWriter writer)
writer.WriteString("boot_time", bootTime);
}

if (ProcessorCount is {} processorCount)
{
writer.WriteNumber("processor_count", processorCount);
}

if (!string.IsNullOrWhiteSpace(CpuDescription))
{
writer.WriteString("cpu_description", CpuDescription);
}

if (ProcessorFrequency is {} processorFrequency)
{
writer.WriteNumber("processor_frequency", processorFrequency);
}

if (!string.IsNullOrWhiteSpace(DeviceType))
{
writer.WriteString("device_type", DeviceType);
}

if (!string.IsNullOrWhiteSpace(BatteryStatus))
{
writer.WriteString("battery_status", BatteryStatus);
}

if (!string.IsNullOrWhiteSpace(DeviceUniqueIdentifier))
{
writer.WriteString("device_unique_identifier", DeviceUniqueIdentifier);
}

if (SupportsVibration is {} supportsVibration)
{
writer.WriteBoolean("supports_vibration", supportsVibration);
}

if (SupportsAccelerometer is {} supportsAccelerometer)
{
writer.WriteBoolean("supports_accelerometer", supportsAccelerometer);
}

if (SupportsGyroscope is {} supportsGyroscope)
{
writer.WriteBoolean("supports_gyroscope", supportsGyroscope);
}

if (SupportsAudio is {} supportsAudio)
{
writer.WriteBoolean("supports_audio", supportsAudio);
}

if (SupportsLocationService is {} supportsLocationService)
{
writer.WriteBoolean("supports_location_service", supportsLocationService);
}

writer.WriteEndObject();
}

Expand Down Expand Up @@ -383,6 +527,17 @@ public static Device FromJson(JsonElement json)
var screenDensity = json.GetPropertyOrNull("screen_density")?.GetSingle();
var screenDpi = json.GetPropertyOrNull("screen_dpi")?.GetInt32();
var bootTime = json.GetPropertyOrNull("boot_time")?.GetDateTimeOffset();
var processorCount = json.GetPropertyOrNull("processor_count")?.GetInt32();
var cpuDescription = json.GetPropertyOrNull("cpu_description")?.GetString();
var processorFrequency = json.GetPropertyOrNull("processor_frequency")?.GetInt32();
var deviceType = json.GetPropertyOrNull("device_type")?.GetString();
var batteryStatus = json.GetPropertyOrNull("battery_status")?.GetString();
var deviceUniqueIdentifier = json.GetPropertyOrNull("device_unique_identifier")?.GetString();
var supportsVibration = json.GetPropertyOrNull("supports_vibration")?.GetBoolean();
var supportsAccelerometer = json.GetPropertyOrNull("supports_accelerometer")?.GetBoolean();
var supportsGyroscope = json.GetPropertyOrNull("supports_gyroscope")?.GetBoolean();
var supportsAudio = json.GetPropertyOrNull("supports_audio")?.GetBoolean();
var supportsLocationService = json.GetPropertyOrNull("supports_location_service")?.GetBoolean();

return new Device
{
Expand Down Expand Up @@ -410,7 +565,18 @@ public static Device FromJson(JsonElement json)
ScreenResolution = screenResolution,
ScreenDensity = screenDensity,
ScreenDpi = screenDpi,
BootTime = bootTime
BootTime = bootTime,
ProcessorCount = processorCount,
CpuDescription = cpuDescription,
ProcessorFrequency = processorFrequency,
DeviceType = deviceType,
BatteryStatus = batteryStatus,
DeviceUniqueIdentifier = deviceUniqueIdentifier,
SupportsVibration = supportsVibration,
SupportsAccelerometer = supportsAccelerometer,
SupportsGyroscope = supportsGyroscope,
SupportsAudio = supportsAudio,
SupportsLocationService = supportsLocationService
};
}
}
Expand Down
83 changes: 82 additions & 1 deletion src/Sentry/Protocol/Gpu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,39 @@ public sealed class Gpu : IJsonSerializable
/// </example>
public string? NpotSupport { get; set; }

/// <summary>
/// Largest size of a texture that is supported by the graphics hardware.
/// </summary>
public int? MaxTextureSize { get; set; }

/// <summary>
/// Approximate "shader capability" level of the graphics device.
/// </summary>
/// <example>
/// Shader Model 2.0, OpenGL ES 3.0, Metal / OpenGL ES 3.1, 27 (unknown)
/// </example>
public string? GraphicsShaderLevel { get; set; }

/// <summary>
/// Is audio available on the device?
/// </summary>
public bool? SupportsDrawCallInstancing { get; set; }

/// <summary>
/// Is ray tracing available on the device?
/// </summary>
public bool? SupportsRayTracing { get; set; }

/// <summary>
/// Are compute shaders available on the device?
/// </summary>
public bool? SupportsComputeShaders { get; set; }

/// <summary>
/// Are geometry shaders available on the device?
/// </summary>
public bool? SupportsGeometryShaders { get; set; }

/// <summary>
/// Clones this instance.
/// </summary>
Expand All @@ -100,6 +133,12 @@ internal Gpu Clone()
MultiThreadedRendering = MultiThreadedRendering,
Version = Version,
NpotSupport = NpotSupport,
MaxTextureSize = MaxTextureSize,
GraphicsShaderLevel = GraphicsShaderLevel,
SupportsDrawCallInstancing = SupportsDrawCallInstancing,
SupportsRayTracing = SupportsRayTracing,
SupportsComputeShaders = SupportsComputeShaders,
SupportsGeometryShaders = SupportsGeometryShaders
};

/// <inheritdoc />
Expand Down Expand Up @@ -154,6 +193,36 @@ public void WriteTo(Utf8JsonWriter writer)
writer.WriteString("npot_support", NpotSupport);
}

if (MaxTextureSize is {} maxTextureSize)
{
writer.WriteNumber("max_texture_size", maxTextureSize);
}

if (!string.IsNullOrWhiteSpace(GraphicsShaderLevel))
{
writer.WriteString("graphics_shader_level", GraphicsShaderLevel);
}

if (SupportsDrawCallInstancing is {} supportsDrawCallInstancing)
{
writer.WriteBoolean("supports_draw_call_instancing", supportsDrawCallInstancing);
}

if (SupportsRayTracing is {} supportsRayTracing)
{
writer.WriteBoolean("supports_ray_tracing", supportsRayTracing);
}

if (SupportsComputeShaders is {} supportsComputeShaders)
{
writer.WriteBoolean("supports_compute_shaders", supportsComputeShaders);
}

if (SupportsGeometryShaders is {} supportsGeometryShaders)
{
writer.WriteBoolean("supports_geometry_shaders", supportsGeometryShaders);
}

writer.WriteEndObject();
}

Expand All @@ -171,6 +240,12 @@ public static Gpu FromJson(JsonElement json)
var multiThreadedRendering = json.GetPropertyOrNull("multi_threaded_rendering")?.GetBoolean();
var version = json.GetPropertyOrNull("version")?.GetString();
var npotSupport = json.GetPropertyOrNull("npot_support")?.GetString();
var maxTextureSize = json.GetPropertyOrNull("max_texture_size")?.GetInt32();
var graphicsShaderLevel = json.GetPropertyOrNull("graphics_shader_level")?.GetString();
var supportsDrawCallInstancing = json.GetPropertyOrNull("supports_draw_call_instancing")?.GetBoolean();
var supportsRayTracing = json.GetPropertyOrNull("supports_ray_tracing")?.GetBoolean();
var supportsComputeShaders = json.GetPropertyOrNull("supports_compute_shaders")?.GetBoolean();
var supportsGeometryShaders = json.GetPropertyOrNull("supports_geometry_shaders")?.GetBoolean();

return new Gpu
{
Expand All @@ -182,7 +257,13 @@ public static Gpu FromJson(JsonElement json)
ApiType = apiType,
MultiThreadedRendering = multiThreadedRendering,
Version = version,
NpotSupport = npotSupport
NpotSupport = npotSupport,
MaxTextureSize = maxTextureSize,
GraphicsShaderLevel = graphicsShaderLevel,
SupportsDrawCallInstancing = supportsDrawCallInstancing,
SupportsRayTracing = supportsRayTracing,
SupportsComputeShaders = supportsComputeShaders,
SupportsGeometryShaders = supportsGeometryShaders
};
}
}
Expand Down
Loading

0 comments on commit 9b32eee

Please sign in to comment.