Skip to content

Commit 3dd8c35

Browse files
konraddysputvlussenburgjasoncdavis0
authored
Version 3.3.0 (#56)
## Version 3.3.0 - `BacktraceReport` stack trace now includes the file name of the stack frame. - Performance improvements: - JSON algorithm performance improvements - avoid analyzing data types. - improved library attributes management. - improved Unity logs management. - Support for Low Memory error reports on Anrdoid and iOS (these are sometimes referred to as OOM or Out Of Memory errors). If a low memory situation is detected, backtrace-unity will attempt to generate and submit a native error report to the Backtrace instance. The report will have the `error.type` value of `Low Memory`. - New support for hang detection on Android and iOS. If a game experiences non responsiviness after 5 seconds, backtrace-unity will generate an error report to the Backtrace instance. The report will have the `error.type` value of `Hang`. * Allocation improvements * Native attributes improvement * Removed try/catch block * Added filename to stack frames * Records operation improvements * Fixed db.count * Improved JSON algorithm * Fixed invalid preprocesor editor directive * Removed not used meta file * Modified complex annotations * Stack frame optimization * Style changes * Unit tests update * Make backtrace unity message class variables readonly * update environment variables checks * Source code property update + few small improvements to decrease gc alloc/speed up plugin * Update BacktraceDatabaseAttachmentManager.cs Compilation failed on MacOS building for Windows x64 * Inlcuded removed namespace * Fixed line endings * Prevents from returning empty file name - return instead libary name * support for filename - . * Guessing library name improvements * Guessing library name improvements * Fixed line engings * OOM/Anr support (#57) * iOS support * OOM + ANRs Android * Squashed commit of the following: commit d61fb8f Author: kdysput <konrad.dysput@gmail.com> Date: Wed Jan 20 12:33:27 2021 +0100 Guessing library name improvements commit 40e3bdc Author: kdysput <konrad.dysput@gmail.com> Date: Wed Jan 20 12:08:48 2021 +0100 Guessing library name improvements commit 3971dbc Author: kdysput <konrad.dysput@gmail.com> Date: Tue Jan 19 19:23:25 2021 +0100 support for filename - . commit 963e0f3 Author: kdysput <konrad.dysput@gmail.com> Date: Tue Jan 19 16:52:53 2021 +0100 Prevents from returning empty file name - return instead libary name commit ec7ab38 Author: kdysput <konrad.dysput@gmail.com> Date: Tue Jan 19 16:03:17 2021 +0100 Fixed line endings commit ec8bca2 Author: kdysput <konrad.dysput@gmail.com> Date: Tue Jan 19 15:59:23 2021 +0100 Inlcuded removed namespace commit 4b0a686 Author: Vincent Lussenburg <vlussenburg@users.noreply.github.com> Date: Fri Jan 15 15:12:31 2021 -0700 Update BacktraceDatabaseAttachmentManager.cs Compilation failed on MacOS building for Windows x64 * Enable ANR dection on iOS * OOM/ANR - Android full tests + code refactor * Enable ANR via UI * Check if database is enabled * Fixed line endings * Fixed line endings * Fixed line endings * Fixed line endings * Changelog and readme update * Update CHANGELOG.md * Error.type attributes support * Consistent line ending * Update CHANGELOG.md * updated error.type attribute for hangs * Update README.md * Squashed commit of the following: commit 356df35 Author: jasoncdavis0 <jdavis@backtrace.io> Date: Sun Jan 10 18:04:32 2021 -0500 Update README.md commit aaa5054 Author: jasoncdavis0 <jdavis@backtrace.io> Date: Mon Dec 21 11:45:38 2020 -0500 Update README.md commit f3d9884 Author: jasoncdavis0 <jdavis@backtrace.io> Date: Fri Dec 11 08:16:15 2020 -0500 Added section on Log Error Sampling commit dfe66e0 Author: jasoncdavis0 <jdavis@backtrace.io> Date: Fri Dec 11 07:51:12 2020 -0500 Adding info about debug.logerrors Details on the 5 classes of Errors backtrace captures. Details up to Best Practices. commit f6b9237 Author: jasoncdavis0 <jdavis@backtrace.io> Date: Wed Dec 9 15:52:08 2020 -0500 Update CHANGELOG.md commit 142face Author: jasoncdavis0 <jdavis@backtrace.io> Date: Wed Dec 9 15:50:08 2020 -0500 Update CHANGELOG.md updated text to refer to Debug.LogError Co-authored-by: Vincent Lussenburg <vlussenburg@users.noreply.github.com> Co-authored-by: jasoncdavis0 <jdavis@backtrace.io>
1 parent 356df35 commit 3dd8c35

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1635
-748
lines changed
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Backtrace Unity Release Notes
22

3+
## Version 3.3.0
4+
- `BacktraceReport` stack trace now includes the file name of the stack frame.
5+
- Performance improvements:
6+
- JSON algorithm performance improvements - avoid analyzing data types.
7+
- improved library attributes management.
8+
- improved Unity logs management.
9+
- Support for Low Memory error reports on Anrdoid and iOS (these are sometimes referred to as OOM or Out Of Memory errors). If a low memory situation is detected, backtrace-unity will attempt to generate and submit a native error report to the Backtrace instance. The report will have the `error.type` value of `Low Memory`.
10+
- New support for hang detection on Android and iOS. If a game experiences non responsiviness after 5 seconds, backtrace-unity will generate an error report to the Backtrace instance. The report will have the `error.type` value of `Hang`.
11+
12+
313
## Version 3.2.6
414
- `BacktraceClient` will apply sampling only to errors lacking exception information.
515
- Fixed annotations nullable value.

Editor/BacktraceClientConfigurationEditor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public override void OnInspectorGUI()
2626
#else
2727
settings.IgnoreSslValidation = false;
2828
#endif
29-
#if UNITY_ANDROID
29+
#if UNITY_ANDROID || UNITY_IOS
3030
settings.HandleANR = EditorGUILayout.Toggle(BacktraceConfigurationLabels.LABEL_HANDLE_ANR, settings.HandleANR);
3131
#endif
3232
settings.GameObjectDepth = EditorGUILayout.IntField(BacktraceConfigurationLabels.LABEL_GAME_OBJECT_DEPTH, settings.GameObjectDepth);

Editor/BacktraceConfigurationEditor.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,16 @@ public override void OnInspectorGUI()
4141
serializedObject.FindProperty("IgnoreSslValidation"),
4242
new GUIContent(BacktraceConfigurationLabels.LABEL_IGNORE_SSL_VALIDATION));
4343
#endif
44-
#if UNITY_ANDROID
44+
#if UNITY_ANDROID || UNITY_IOS
4545
EditorGUILayout.PropertyField(
4646
serializedObject.FindProperty("HandleANR"),
4747
new GUIContent(BacktraceConfigurationLabels.LABEL_HANDLE_ANR));
4848

49-
EditorGUILayout.PropertyField(
50-
serializedObject.FindProperty("SymbolsUploadToken"),
51-
new GUIContent(BacktraceConfigurationLabels.LABEL_SYMBOLS_UPLOAD_TOKEN));
49+
#if UNITY_2019_2_OR_NEWER && UNITY_ANDROID
50+
EditorGUILayout.PropertyField(
51+
serializedObject.FindProperty("SymbolsUploadToken"),
52+
new GUIContent(BacktraceConfigurationLabels.LABEL_SYMBOLS_UPLOAD_TOKEN));
53+
#endif
5254
#endif
5355
EditorGUILayout.PropertyField(
5456
serializedObject.FindProperty("UseNormalizedExceptionMessage"),

Editor/Native/Android/SymbolsUpload.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ private string ConvertSymbols(string symbolsArchive)
134134

135135
private string GetPathToSymbolsArchive(BuildReport report)
136136
{
137-
var archiveName = string.Format("{0}-{1}-v{2}.symbols.zip", Path.GetFileNameWithoutExtension(report.summary.outputPath), PlayerSettings.bundleVersion, PlayerSettings.Android.bundleVersionCode);
137+
var archiveName = string.Format("{0}-{1}-v{2}.symbols.zip", Path.GetFileNameWithoutExtension(report.summary.outputPath), PlayerSettings.bundleVersion, PlayerSettings.Android.bundleVersionCode.ToString());
138138
return Path.Combine(Directory.GetParent(report.summary.outputPath).FullName, archiveName);
139139

140140
}

README.md

+15-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
[github release]: (https://github.com/backtrace-labs/backtrace-labs/)
1010

11-
- [Features Summary <a name="features-summary"></a>](#features-summary--a-name--features-summary----a-)
11+
- [Features Summary](#features-summary)
1212
- [Prerequisites](#prerequisites)
1313
- [Platforms Supported](#platforms-supported)
14-
- [Setup <a name="installation"></a>](#setup--a-name--installation----a-)
14+
- [Setup](#installation)
1515
- [Android Specific information](#android-specific-information)
1616
- [iOS Specific information](#ios-specific-information)
1717
- [Data Privacy](#data-privacy)
@@ -69,7 +69,7 @@ Game Consoles - PlayStation4, Xbox One, Nintendo Switch
6969
There are some differences in capabilities that backtrace-unity provides based on the platform. Major capabilities are summarized as follows:
7070
* All Platforms - Errors, Unhandled Exceptions, Handled Exceptions, Custom Indexable Metadata, File Attachments*, Last N Log Lines, Automatic attachment of Screenshots, Client Side Deduplication Rules*, Client Side Submission Filtering, Client Side Submission Limits, Performance Diagnostics, Offline Database*(Except Nintendo Switch)
7171
* Android -Identified by attribute uname.sysname = Android; ANRs (Hangs), Native Process and Memory Information, Java Exception Handler (Plugins, Exported Game in Android Studio), NDK crashes.
72-
* iOS - Identified by attribute uname.sysname = IOS; Native Engine and Plugin Crashes.
72+
* iOS - Identified by attribute uname.sysname = IOS; ANRs (Hangs), Native Engine and Plugin Crashes.
7373
* WebGL - Identified by attribute uname.sysname = WebGL. The attribute device.model is currently used to share the browser information. Note that stacktraces for WebGL errors are only available if you choose to enable them in the Publishing Settings / Enable Exceptions drop down. More details in https://docs.unity3d.com/Manual/webgl-building.html
7474
* Switch - Identified by attribute uname.sysname = Switch. Note that the attribute GUID is regenerated with each Switch restart (It is not an accurate count of number of Users or Devices. It is a count of Switch Sessions). Note that the current release does no support Offline Database or related features.
7575
* PlayStation4 - Identified by attribute uname.sysname = PS4
@@ -154,7 +154,7 @@ The following is a reference guide to the Backtrace Client fields:
154154
- Collect last n game logs: Collect last n number of logs generated by game.
155155
- Enabled performance statistics: Allows `BacktraceClient` to measure execution time and include performance information as report attributes.
156156
- Ignore SSL validation: Unity by default will validate ssl certificates. By using this option you can avoid ssl certificates validation. However, if you don't need to ignore ssl validation, please set this option to false.
157-
- Handle ANR (Application not responding) - this options is available only in Android build. It allows to catch ANR (application not responding) events happened to your game in Android devices. In this release, ANR is set to detect after 5 seconds. This will be configurable in a future release.
157+
- Handle ANR (Application not responding) - this options is available only in Android and iOS build. It allows to catch ANR (application not responding) events happened to your game in Android/iOS devices. In this release, ANR is set to detect after 5 seconds. This will be configurable in a future release.
158158
- Enable Database: When this setting is toggled, the backtrace-unity plugin will configure an offline database that will store reports if they can't be submitted do to being offline or not finding a network. When toggled on, there are a number of Database settings to configure.
159159
- Backtrace Database path: This is the path to directory where the Backtrace database will store reports on your game. You can use interpolated strings SUCH AS
160160
`${Application.persistentDataPath}/backtrace/database` to dynamically look up a known directory structure to use. NOTE: Backtrace database will remove all existing files in the database directory upion first initialization.
@@ -178,9 +178,12 @@ The backtrace-unity library includes support for capturing Android NDK crashes a
178178

179179
system.memory usage related information including memfree, swapfree, and vmalloc.used is now available. Additional VM details and voluntary / nonvountary ctxt switches are included.
180180

181-
## ANR
181+
## ANRs and Hangs
182182

183-
When configuring the backtrace-unity client for an Android deployment, programmers will have a toggle available in backtrace-unity GUI in the Unity Editor to enable or disable ANR reports. This will use the default of 5 seconds.
183+
When configuring the backtrace-unity client for an Android deployment, programmers will have a toggle available in backtrace-unity GUI in the Unity Editor to enable or disable ANR or Hang reports. This will use the default of 5 seconds. The `error.type` for these reports will be `Hang`.
184+
185+
## Low Memory Reports
186+
Backtrace can detect low memory situations for a game running in Unity on Android devices, and attempt to generate an error report with an associated dump object for further investigation. The `error.type` for these reports wiill be `Low Memory`.
184187

185188
## Symbols upload
186189

@@ -204,6 +207,12 @@ The backtrace-unity library includes support for capturing native iOS crashes as
204207

205208
system and vm usage related information including system.memory.free, system.memory.used, system.memory.total, system.memory.active, system.memory.inactive, system.memory.wired are avaialble.
206209

210+
## Hangs
211+
When configuring the backtrace-unity client for an iOS deployment, programmers will have a toggle available in backtrace-unity GUI in the Unity Editor to enable or disable ANR or Hang reports. This will use the default of 5 seconds. The `error.type` for these reports will be `Hang`.
212+
213+
## Low Memory Reports
214+
Backtrace can detect low memory situations for a game running in Unity on iOS devices, and attempt to generate an error report with an associated dump object for further investigation. The `error.type` for these reports wiill be `Low Memory`.
215+
207216
## Native Crashes
208217
When configuring the backtrace-unity client for an iOS deployment in the Unity Editor, programmers will have a toggle to enable or disable `Capture native crashes`. If this is enabled, the backtrace-unity client will ensure the crash report is generated, stored locally, and uploaded upon next game start. Unity crash reporter might prevent Backtrace Crash reporte from sending crashes to Backtrace. To be sure Backtrace is able to collect and send data please set "Enable CrashReport API" to false.
209218
![Enable symbols](./Documentation~/images/Disable-ios-unity-crash-reporter.png)

Runtime/BacktraceClient.cs

+81-27
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class BacktraceClient : MonoBehaviour, IBacktraceClient
2020
{
2121
public BacktraceConfiguration Configuration;
2222

23-
public const string VERSION = "3.2.6";
23+
public const string VERSION = "3.3.0";
2424
public bool Enabled { get; private set; }
2525

2626
/// <summary>
@@ -288,10 +288,12 @@ public static BacktraceClient Initialize(BacktraceConfiguration configuration, D
288288
}
289289
var backtrackGameObject = new GameObject(gameObjectName, typeof(BacktraceClient), typeof(BacktraceDatabase));
290290
BacktraceClient backtraceClient = backtrackGameObject.GetComponent<BacktraceClient>();
291-
BacktraceDatabase backtraceDatabase = backtrackGameObject.GetComponent<BacktraceDatabase>();
292-
293-
backtraceDatabase.Configuration = configuration;
294291
backtraceClient.Configuration = configuration;
292+
if (configuration.Enabled)
293+
{
294+
BacktraceDatabase backtraceDatabase = backtrackGameObject.GetComponent<BacktraceDatabase>();
295+
backtraceDatabase.Configuration = configuration;
296+
}
295297
backtrackGameObject.SetActive(true);
296298
backtraceClient.Refresh();
297299
backtraceClient.SetAttributes(attributes);
@@ -371,12 +373,15 @@ public void Refresh()
371373
DontDestroyOnLoad(gameObject);
372374
_instance = this;
373375
}
374-
Database = GetComponent<BacktraceDatabase>();
375-
if (Database != null)
376+
if (Configuration.Enabled)
376377
{
377-
Database.Reload();
378-
Database.SetApi(BacktraceApi);
379-
Database.SetReportWatcher(_reportLimitWatcher);
378+
Database = GetComponent<BacktraceDatabase>();
379+
if (Database != null)
380+
{
381+
Database.Reload();
382+
Database.SetApi(BacktraceApi);
383+
Database.SetReportWatcher(_reportLimitWatcher);
384+
}
380385
}
381386

382387
_nativeClient = NativeClientFactory.GetNativeClient(Configuration, name);
@@ -400,10 +405,23 @@ private void Awake()
400405
Refresh();
401406
}
402407

408+
/// <summary>
409+
/// Update native client internal ANR timer.
410+
/// </summary>
411+
private void Update()
412+
{
413+
_nativeClient?.UpdateClientTime(Time.time);
414+
}
415+
403416
private void OnDestroy()
404417
{
405418
Enabled = false;
406419
Application.logMessageReceived -= HandleUnityMessage;
420+
#if UNITY_ANDROID || UNITY_IOS
421+
Application.lowMemory -= HandleLowMemory;
422+
_nativeClient?.Disable();
423+
#endif
424+
407425
}
408426

409427
/// <summary>
@@ -495,7 +513,7 @@ private void SendReport(BacktraceReport report, Action<BacktraceResult> sendCall
495513
/// <param name="report">Backtrace Report</param>
496514
/// <param name="sendCallback">Coroutine callback</param>
497515
/// <returns>IEnumerator</returns>
498-
private IEnumerator CollectDataAndSend(BacktraceReport report, Action<BacktraceResult> sendCallback = null)
516+
private IEnumerator CollectDataAndSend(BacktraceReport report, Action<BacktraceResult> sendCallback)
499517
{
500518
var queryAttributes = new Dictionary<string, string>();
501519
var stopWatch = EnablePerformanceStatistics
@@ -520,7 +538,7 @@ private IEnumerator CollectDataAndSend(BacktraceReport report, Action<BacktraceR
520538
}
521539
BacktraceDatabaseRecord record = null;
522540

523-
if (Database != null)
541+
if (Database != null && Database.Enabled())
524542
{
525543
yield return new WaitForEndOfFrame();
526544
if (EnablePerformanceStatistics)
@@ -542,7 +560,7 @@ record = Database.Add(data);
542560

543561
if (record.Duplicated)
544562
{
545-
record.Dispose();
563+
record.Unlock();
546564
yield break;
547565
}
548566
}
@@ -551,24 +569,28 @@ record = Database.Add(data);
551569
yield break;
552570
}
553571
}
554-
555-
yield return new WaitForEndOfFrame();
556572
if (EnablePerformanceStatistics)
557573
{
558574
stopWatch.Restart();
559575
}
560576
// avoid serializing data twice
561577
// if record is here we should try to send json data that are available in record
562-
// otherwise we can still use BacktraceData.ToJson().
578+
// otherwise we can still use BacktraceData.ToJson().
563579
string json = record != null
564580
? record.BacktraceDataJson()
565581
: data.ToJson();
566582

583+
567584
if (EnablePerformanceStatistics)
568585
{
569586
stopWatch.Stop();
570587
queryAttributes["performance.json"] = stopWatch.GetMicroseconds();
571588
}
589+
yield return new WaitForEndOfFrame();
590+
if (string.IsNullOrEmpty(json))
591+
{
592+
yield break;
593+
}
572594

573595
//backward compatibility
574596
if (RequestHandler != null)
@@ -586,18 +608,15 @@ record = Database.Add(data);
586608
{
587609
if (record != null)
588610
{
589-
record.Dispose();
611+
record.Unlock();
590612
if (Database != null && result.Status != BacktraceResultStatus.ServerError && result.Status != BacktraceResultStatus.NetworkError)
591613
{
592614
Database.Delete(record);
593615
}
594616
}
595617
//check if there is more errors to send
596618
//handle inner exception
597-
HandleInnerException(report, (BacktraceResult innerResult) =>
598-
{
599-
result.InnerExceptionResult = innerResult;
600-
});
619+
HandleInnerException(report);
601620

602621
if (sendCallback != null)
603622
{
@@ -606,6 +625,7 @@ record = Database.Add(data);
606625
}));
607626
}
608627

628+
609629
/// <summary>
610630
/// Collect additional report information from client and convert report to backtrace data
611631
/// </summary>
@@ -629,12 +649,22 @@ private BacktraceData SetupBacktraceData(BacktraceReport report)
629649

630650
report.AssignSourceCodeToReport(sourceCode);
631651

632-
var reportAttributes = _nativeClient == null
633-
? _clientAttributes
634-
: _nativeClient.GetAttributes().Merge(_clientAttributes);
635-
636652
// pass copy of dictionary to prevent overriding client attributes
637-
return report.ToBacktraceData(new Dictionary<string, string>(reportAttributes), GameObjectDepth);
653+
var result = report.ToBacktraceData(null, GameObjectDepth);
654+
655+
// add native attributes to client report
656+
if (_nativeClient != null)
657+
{
658+
_nativeClient.GetAttributes(result.Attributes.Attributes);
659+
}
660+
661+
// apply client attributes
662+
foreach (var attribute in _clientAttributes)
663+
{
664+
result.Attributes.Attributes[attribute.Key] = attribute.Value;
665+
}
666+
667+
return result;
638668
}
639669

640670
#if UNITY_ANDROID
@@ -665,8 +695,32 @@ private void CaptureUnityMessages()
665695
if (Configuration.HandleUnhandledExceptions || Configuration.NumberOfLogs != 0)
666696
{
667697
Application.logMessageReceived += HandleUnityMessage;
698+
#if UNITY_ANDROID || UNITY_IOS
699+
Application.lowMemory += HandleLowMemory;
700+
#endif
701+
}
702+
}
703+
704+
#if UNITY_ANDROID || UNITY_IOS
705+
internal void HandleLowMemory()
706+
{
707+
if (!Enabled)
708+
{
709+
Debug.LogWarning("Please enable BacktraceClient first.");
710+
return;
711+
}
712+
const string lowMemoryMessage = "OOMException: Out of memory detected.";
713+
_backtraceLogManager.Enqueue(new BacktraceUnityMessage(lowMemoryMessage, string.Empty, LogType.Error));
714+
715+
// try to send report about OOM from managed layer if native layer is disabled.
716+
bool nativeSendResult = _nativeClient != null ? _nativeClient.OnOOM() : false;
717+
if (!nativeSendResult)
718+
{
719+
var oom = new BacktraceUnhandledException(lowMemoryMessage, string.Empty);
720+
SendUnhandledException(oom);
668721
}
669722
}
723+
#endif
670724

671725
/// <summary>
672726
/// Catch Unity logger data and create Backtrace reports for log type that represents exception or error
@@ -838,12 +892,12 @@ private bool ShouldSendReport(BacktraceReport report)
838892
/// if inner exception exists, client should send report twice - one with current exception, one with inner exception
839893
/// </summary>
840894
/// <param name="report">current report</param>
841-
private void HandleInnerException(BacktraceReport report, Action<BacktraceResult> callback)
895+
private void HandleInnerException(BacktraceReport report)
842896
{
843897
var innerExceptionReport = report.CreateInnerReport();
844898
if (innerExceptionReport != null && ShouldSendReport(innerExceptionReport))
845899
{
846-
SendReport(innerExceptionReport, callback);
900+
SendReport(innerExceptionReport);
847901
}
848902
}
849903

0 commit comments

Comments
 (0)