@@ -89,6 +89,18 @@ class HomePage extends StatefulWidget {
89
89
}
90
90
91
91
class _HomePageState extends State <HomePage > {
92
+ // Simulate a function regression by making this function slower
93
+ int sumOfSquares (int n) {
94
+ int sum = 0 ;
95
+ for (int i = 0 ; i < n; i++ ) {
96
+ // Artificially slow down the function
97
+ for (int j = 0 ; j < 100 ; j++ ) {
98
+ sum += i * i;
99
+ }
100
+ }
101
+ return sum;
102
+ }
103
+
92
104
_HomePageState () {
93
105
log.info ('Creating HomePageState' );
94
106
}
@@ -102,6 +114,56 @@ class _HomePageState extends State<HomePage> {
102
114
@override
103
115
void initState () {
104
116
super .initState ();
117
+ // Intentionally perform a long-running regex operation on the main thread to trigger Sentry performance issue
118
+ try {
119
+ final largeText = List .generate (
120
+ 100000 ,
121
+ (i) => 'The quick brown fox jumps over the lazy dog. ' ,
122
+ ).join ();
123
+ final regex = RegExp (r'(quick|lazy|dog|fox|jumps|over|brown)' );
124
+ final stopwatch = Stopwatch ()..start ();
125
+ final matches = regex.allMatches (largeText).toList ();
126
+ stopwatch.stop ();
127
+ log.info (
128
+ 'Regex on main thread duration: \x 1B[36m${stopwatch .elapsedMilliseconds }ms\x 1B[0m, matches: ${matches .length }' ,
129
+ );
130
+ } catch (e) {
131
+ log.warning ('Regex error: $e ' );
132
+ }
133
+ // Intentionally call a regressed function to trigger Sentry's Function Regression detector
134
+ try {
135
+ final stopwatch = Stopwatch ()..start ();
136
+ final result = sumOfSquares (1000 );
137
+ stopwatch.stop ();
138
+ log.info (
139
+ 'Function regression demo: sumOfSquares(1000) duration: \x 1B[36m${stopwatch .elapsedMilliseconds }ms\x 1B[0m, result: $result ' ,
140
+ );
141
+ } catch (e) {
142
+ log.warning ('Function regression error: $e ' );
143
+ }
144
+ // Intentionally perform a long-running computation on the main thread to trigger Sentry's Frame Drop detector
145
+ try {
146
+ final stopwatch = Stopwatch ()..start ();
147
+ List <int > numbers = List .generate (10000 , (i) => i);
148
+ List <int > sortedEvenOdd = [];
149
+ for (var n in numbers) {
150
+ if (n % 2 == 0 ) {
151
+ // Insert even numbers before the first odd number
152
+ int i = sortedEvenOdd.indexWhere ((x) => x % 2 == 1 );
153
+ sortedEvenOdd.insert (i == - 1 ? 0 : i, n);
154
+ } else {
155
+ // Insert odd numbers after the last odd number
156
+ int i = sortedEvenOdd.lastIndexWhere ((x) => x % 2 == 1 );
157
+ sortedEvenOdd.insert (i == - 1 ? sortedEvenOdd.length : i + 1 , n);
158
+ }
159
+ }
160
+ stopwatch.stop ();
161
+ log.info (
162
+ 'Frame drop computation on main thread duration: \x 1B[36m${stopwatch .elapsedMilliseconds }ms\x 1B[0m, sorted length: ${sortedEvenOdd .length }' ,
163
+ );
164
+ } catch (e) {
165
+ log.warning ('Frame drop computation error: $e ' );
166
+ }
105
167
WidgetsBinding .instance.addPostFrameCallback ((_) {
106
168
if (mounted) {
107
169
SentryDisplayWidget .of (context).reportFullyDisplayed ();
0 commit comments