-
-
Notifications
You must be signed in to change notification settings - Fork 220
iOS native profiling #2930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iOS native profiling #2930
Changes from all commits
3f8f036
cd43974
fad8eff
c2adb5a
0aa3bf1
ba4982a
fb13b03
efa4552
4533cd9
4e18597
1727f44
bf8e17d
e5383e2
221439c
cf734bd
5bfcdf0
6d4f658
8246932
5d12ed0
67c54fa
7fce737
f91846a
5acfdc2
e728541
c56da69
4a92fac
6772bc1
07eb383
37ca589
6364fd0
20807ab
539cc8a
1f93d19
bf11364
a17b3a0
0c4ebc3
45617e7
f030857
24d1656
c2e63ec
1dddef1
fb339d9
25099ba
2b78e3b
e5a069a
ed6dd63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ on: | |
- release/* | ||
pull_request: | ||
paths-ignore: | ||
- '**.md' | ||
- "**.md" | ||
|
||
jobs: | ||
build: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ public override bool FinishedLaunching(UIApplication application, NSDictionary l | |
{ | ||
o.Debug = true; | ||
o.Dsn = "https://[email protected]/5428537"; | ||
o.TracesSampleRate = 1.0; | ||
o.ProfilesSampleRate = 1.0; | ||
}); | ||
|
||
// create a new window instance based on the screen size | ||
|
@@ -50,6 +52,43 @@ public override bool FinishedLaunching(UIApplication application, NSDictionary l | |
// throw new Exception("Test Unhandled Managed Exception"); | ||
// SentrySdk.CauseCrash(CrashType.Native); | ||
|
||
{ | ||
var tx = SentrySdk.StartTransaction("app", "run"); | ||
var count = 10; | ||
for (var i = 0; i < count; i++) | ||
{ | ||
FindPrimeNumber(100000); | ||
} | ||
|
||
tx.Finish(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
private static long FindPrimeNumber(int n) | ||
{ | ||
int count = 0; | ||
long a = 2; | ||
while (count < n) | ||
{ | ||
long b = 2; | ||
int prime = 1;// to check if found a prime | ||
while (b * b <= a) | ||
{ | ||
if (a % b == 0) | ||
{ | ||
prime = 0; | ||
break; | ||
} | ||
b++; | ||
} | ||
if (prime > 0) | ||
{ | ||
count++; | ||
} | ||
a++; | ||
} | ||
return (--a); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using Sentry.Extensibility; | ||
using Sentry.Internal; | ||
using Sentry.Cocoa.Extensions; | ||
using Sentry.Cocoa.Facades; | ||
|
||
namespace Sentry.Cocoa; | ||
|
||
internal class CocoaProfiler : ITransactionProfiler | ||
{ | ||
private readonly SentryOptions _options; | ||
private readonly SentryId _traceId; | ||
private readonly CocoaSdk.SentryId _cocoaTraceId; | ||
private readonly ulong _startTimeNs; | ||
private ulong _endTimeNs; | ||
private readonly SentryStopwatch _stopwatch; | ||
|
||
public CocoaProfiler(SentryOptions options, ulong startTimeNs, SentryId traceId, CocoaSdk.SentryId cocoaTraceId) | ||
{ | ||
_stopwatch = SentryStopwatch.StartNew(); | ||
_options = options; | ||
_startTimeNs = startTimeNs; | ||
_traceId = traceId; | ||
_cocoaTraceId = cocoaTraceId; | ||
_options.LogDebug("Trace {0} profile start timestamp: {1} ns", _traceId, _startTimeNs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to pass in the actual timestamp here and then turn this into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand, but this is what the native profiler works with so when you're actually "debugging" based on the log output (that's why it's |
||
} | ||
|
||
/// <inheritdoc /> | ||
public void Finish() | ||
{ | ||
if (_endTimeNs == 0) | ||
{ | ||
_endTimeNs = _startTimeNs + (ulong)_stopwatch.ElapsedNanoseconds; | ||
_options.LogDebug("Trace {0} profile end timestamp: {1} ns", _traceId, _endTimeNs); | ||
bitsandfoxes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
public ISerializable? Collect(Transaction transaction) | ||
{ | ||
// TODO change return type of CocoaSDKs CollectProfileBetween to NSMutableDictionary | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need a ticket there not to forget this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've already made the change in sentry-cocoa and it's merged but I've missed last-week's release so I'm keeping as is with hopes this gets resolved before the PR is merged. If not, I'll create an issue |
||
var payload = SentryCocoaHybridSdk.CollectProfileBetween(_startTimeNs, _endTimeNs, _cocoaTraceId)?.MutableCopy() as NSMutableDictionary; | ||
if (payload is null) | ||
{ | ||
_options.LogWarning("Trace {0} collected profile payload is null", _traceId); | ||
return null; | ||
} | ||
_options.LogDebug("Trace {0} profile payload collected", _traceId); | ||
|
||
var payloadTx = payload["transaction"]?.MutableCopy() as NSMutableDictionary; | ||
if (payloadTx is null) | ||
{ | ||
_options.LogWarning("Trace {0} collected profile payload doesn't have transaction information", _traceId); | ||
return null; | ||
} | ||
|
||
payloadTx["id"] = transaction.EventId.ToString().ToNSString(); | ||
payloadTx["trace_id"] = _traceId.ToString().ToNSString(); | ||
payloadTx["name"] = transaction.Name.ToNSString(); | ||
payload["transaction"] = payloadTx; | ||
payload["timestamp"] = transaction.StartTimestamp.ToString("o", CultureInfo.InvariantCulture).ToNSString(); | ||
return new SerializableNSObject(payload); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using Sentry.Internal; | ||
using Sentry.Cocoa.Extensions; | ||
|
||
namespace Sentry.Cocoa; | ||
|
||
internal class CocoaProfilerFactory : ITransactionProfilerFactory | ||
{ | ||
private readonly SentryOptions _options; | ||
|
||
internal CocoaProfilerFactory(SentryOptions options) | ||
{ | ||
_options = options; | ||
} | ||
|
||
/// <inheritdoc /> | ||
public ITransactionProfiler? Start(ITransactionTracer tracer, CancellationToken cancellationToken) | ||
{ | ||
var traceId = tracer.TraceId.ToCocoaSentryId(); | ||
var startTime = SentryCocoaHybridSdk.StartProfilerForTrace(traceId); | ||
return new CocoaProfiler(_options, startTime, tracer.TraceId, traceId); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.