Skip to content

Commit 05c88ad

Browse files
committed
add example of manual profiling
1 parent 55abee0 commit 05c88ad

File tree

1 file changed

+25
-0
lines changed
  • docs/platforms/apple/common/profiling

1 file changed

+25
-0
lines changed

docs/platforms/apple/common/profiling/index.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,31 @@ See the subsections below to learn about the various ways the profiler can be st
5555
5656
By default, the profiler can only be started and stopped manually with calls to `SentrySDK.startProfiler` and `SentrySDK.stopProfiler`. All code that executes on all threads in between those calls will be recorded. The configurations shown above demonstrate configuring manual profiling mode.
5757
58+
For example, if you wanted to profile everything that happens after starting a network request, and then updating a table view with the contents of the response, you could do is as follows (assuming you've already started the Sentry SDK with the options as shown above):
59+
60+
```swift {tabTitle:Swift}
61+
import Sentry
62+
63+
struct MyModel: Codable {
64+
// fields...
65+
}
66+
var model: MyModel?
67+
var tableView: UITableView!
68+
69+
@IBAction func updateTable() {
70+
SentrySDK.startProfiler()
71+
URLSession.shared.dataTask(with: URLRequest(url: URL(string: "https://my.domain.tld/endpoint")!)) { data, response, error in
72+
self.model = try! JSONDecoder().decode(MyModel.self, from: data!)
73+
DispatchQueue.main.async {
74+
self.tableView.reloadData()
75+
SentrySDK.stopProfiler()
76+
}
77+
}
78+
}
79+
```
80+
81+
This would capture every stacktrace on every thread involved with performing the network request, decoding the response and rebuilding the cells in the table view.
82+
5883
### Trace Lifecycle
5984

6085
The profiler can be configured to start when a new root span is started where none already exist, and stopped when there are no root spans remaining. For this mode, you must set the `SentryProfileOptions.lifecycle` property to `SentryProfileLifecycleTrace` and ensure some traces will be sampled:

0 commit comments

Comments
 (0)