Skip to content

Commit

Permalink
Merge d454f31 into 881a955
Browse files Browse the repository at this point in the history
  • Loading branch information
armcknight committed Sep 8, 2023
2 parents 881a955 + d454f31 commit b7841c0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixes

- Remove warning about non-portable path to file "SentryDsn.h" (#3270)
- Gather metric readings fully covering the duration of a profile (#3272)

### Features

Expand Down
3 changes: 1 addition & 2 deletions Sources/Sentry/SentryDispatchSourceWrapper.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ - (instancetype)initTimerWithInterval:(uint64_t)interval
_queueWrapper = queueWrapper;
_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queueWrapper.queue);
dispatch_source_set_event_handler(_source, eventHandler);
dispatch_source_set_timer(
_source, dispatch_time(DISPATCH_TIME_NOW, interval), interval, leeway);
dispatch_source_set_timer(_source, dispatch_time(DISPATCH_TIME_NOW, 0), interval, leeway);
dispatch_resume(_source);
}
return self;
Expand Down
17 changes: 12 additions & 5 deletions Sources/Sentry/SentryMetricProfiler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ - (void)start
- (void)stop
{
[_dispatchSource cancel];

// make sure we have a measurement at the end of the profile
[self recordMetrics];
}

- (NSMutableDictionary<NSString *, id> *)serializeBetween:(uint64_t)startSystemTime
Expand Down Expand Up @@ -159,11 +162,15 @@ - (void)registerSampler
queueName:"io.sentry.metric-profiler"
attributes:dispatch_queue_attr_make_with_qos_class(
DISPATCH_QUEUE_CONCURRENT, QOS_CLASS_UTILITY, 0)
eventHandler:^{
[weakSelf recordCPUsage];
[weakSelf recordMemoryFootprint];
[weakSelf recordEnergyUsageEstimate];
}];
eventHandler:^{ [weakSelf recordMetrics]; }];
}

- (void)recordMetrics
{
SENTRY_LOG_DEBUG(@"Recording profiling metrics sample");
[self recordCPUsage];
[self recordMemoryFootprint];
[self recordEnergyUsageEstimate];
}

- (void)recordMemoryFootprint
Expand Down
7 changes: 6 additions & 1 deletion Tests/SentryProfilerTests/SentryProfilerSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ class SentryProfilerSwiftTests: XCTestCase {
systemWrapper.overrides.memoryFootprintError = NSError(domain: "test-error", code: 1)
systemWrapper.overrides.cpuEnergyUsageError = NSError(domain: "test-error", code: 2)
metricTimerFactory?.fire()

// clear out errors for the profile end sample collection
systemWrapper.overrides.cpuUsageError = nil
systemWrapper.overrides.memoryFootprintError = nil
systemWrapper.overrides.cpuEnergyUsageError = nil
}

// app start simulation
Expand Down Expand Up @@ -658,7 +663,7 @@ private extension SentryProfilerSwiftTests {
func assertMetricValue<T: Equatable>(measurements: [String: Any], key: String, numberOfReadings: Int, expectedValue: T? = nil, transaction: Transaction, expectedUnits: String) throws {
let metricContainer = try XCTUnwrap(measurements[key] as? [String: Any])
let values = try XCTUnwrap(metricContainer["values"] as? [[String: Any]])
XCTAssertEqual(values.count, numberOfReadings, "Wrong number of values under \(key)")
XCTAssertEqual(values.count, numberOfReadings + 1, "Wrong number of values under \(key). Need the expected number of samples, plus a profile end reading")

if let expectedValue = expectedValue {
let actualValue = try XCTUnwrap(values[0]["value"] as? T)
Expand Down

0 comments on commit b7841c0

Please sign in to comment.