I am using XCUITesting with performance measurement blocks to ensure that certain tasks in the app don’t regress in how long they take to complete. I’m doing this with OS signposts, by logging signposts when the task begins and ends in the app, and then using the XCTOSSignpostMetric in the test to check the time elapsed against the baseline. This works well except for one case: I have a static library that defines a class that does certain work. That class is instantiated with the StaticString signpost name that should be used when it logs signposts. The app passes this StaticString parameter into the static library class’s constructor. In this case, the XCTOSSignpostMetric in the test never detects the signpost being logged. If I hard code a signpost name in the static library as a StaticString literal, it works. If I pass in a StaticString defined outside the static lib, the test doesn’t detect it when it is logged. Either way, I do see the signposts in Instruments. Only XCTOSSignpostMetric seems to not detect it in this non-functioning case. It seems like a bug, but I’m wondering if anyone else has encountered this or can suggest a workaround.
XCTOSSignpostMetric doesn’t detect signposts logged by static library in my app
I'm sorry that I don't have an answer to your question, but instead a question of my own. Could you share a bit more about how you defined custom signposts in your app and then measure those signposts in XCUITests? I'm trying to do the same thing to measure performance of my own app, but the documentation for measuring custom signposts in XCUITest seems to be non-existent.
Any help or sample code you could provide would be greatly appreciated.
I could not find how to measure the performance for MetricKit signpost anywhere. A WWDC19 video suggested to look up documentation on it, but it doesn't exist.
Thankfully, in Instruments, I found that the subcategory for the OSLog
signpost created by MXMetricManager.makeLogHandle(category:)
is com.apple.metrickit.log
. Therefore, in order to measure the performance of your block, you do something like the following:
measure(metrics: [XCTOSSignpostMetric(subsystem: "com.apple.metrickit.log",
category: "My category",
name: "My name")]) {
...
}
I've faced similar issue renaming segnemtnts in my binary using ld64 options like that:
"-Wl,-rename_section,__TEXT,__cstring,__RE_TEXT,__cstring",
"-Wl,-rename_section,__TEXT,__ustring,__RE_TEXT,__ustring",
Measuring mechanism couldn't detect signposts. I believe this is because of address mismatch of strings used as metric name. os_signpost
receives name StaticString
, instead of just String
.
Renaming code segment like that:
"-Wl,-rename_section,__TEXT,__text,__RE_TEXT,__text",
didn't broke metrics collection in my case.