@@ -89,7 +89,7 @@ public static function collect(Query $query)
89
89
'query ' => $ query ,
90
90
'string ' => $ queryString ,
91
91
'duplicate ' => in_array ($ queryString , array_column (static ::$ queries , 'string ' , null ), true ),
92
- 'trace ' => debug_backtrace (),
92
+ 'trace ' => debug_backtrace (DEBUG_BACKTRACE_IGNORE_ARGS ),
93
93
];
94
94
}
95
95
}
@@ -134,23 +134,46 @@ public function display(): array
134
134
$ data ['queries ' ] = array_map (static function (array $ query ) {
135
135
$ isDuplicate = $ query ['duplicate ' ] === true ;
136
136
137
- // Find the first line that doesn't include `system` in the backtrace
138
- $ line = [];
139
-
140
- foreach ($ query ['trace ' ] as &$ traceLine ) {
141
- // Clean up the file paths
142
- $ traceLine ['file ' ] = str_ireplace (APPPATH , 'APPPATH/ ' , $ traceLine ['file ' ]);
143
- $ traceLine ['file ' ] = str_ireplace (SYSTEMPATH , 'SYSTEMPATH/ ' , $ traceLine ['file ' ]);
144
- if (defined ('VENDORPATH ' )) {
145
- // VENDORPATH is not defined unless `vendor/autoload.php` exists
146
- $ traceLine ['file ' ] = str_ireplace (VENDORPATH , 'VENDORPATH/ ' , $ traceLine ['file ' ]);
137
+ foreach ($ query ['trace ' ] as $ index => &$ line ) {
138
+ // simplify file and line
139
+ if (isset ($ line ['file ' ])) {
140
+ $ line ['file ' ] = clean_path ($ line ['file ' ]) . ': ' . $ line ['line ' ];
141
+ unset($ line ['line ' ]);
142
+ } else {
143
+ $ line ['file ' ] = '[internal function] ' ;
144
+ }
145
+
146
+ // simplify function call
147
+ if (isset ($ line ['class ' ])) {
148
+ $ line ['function ' ] = $ line ['class ' ] . $ line ['type ' ] . $ line ['function ' ];
149
+ unset($ line ['class ' ], $ line ['type ' ]);
147
150
}
148
- $ traceLine ['file ' ] = str_ireplace (ROOTPATH , 'ROOTPATH/ ' , $ traceLine ['file ' ]);
149
151
150
- if (strpos ($ traceLine ['file ' ], 'SYSTEMPATH ' ) !== false ) {
151
- continue ;
152
+ if (strrpos ($ line ['function ' ], '{closure} ' ) === false ) {
153
+ $ line ['function ' ] .= '() ' ;
154
+ }
155
+
156
+ $ line ['function ' ] = str_repeat (chr (0xC2 ) . chr (0xA0 ), 8 ) . $ line ['function ' ];
157
+
158
+ // add index numbering padded with nonbreaking space
159
+ $ indexPadded = str_pad (sprintf ('%d ' , $ index + 1 ), 3 , ' ' , STR_PAD_LEFT );
160
+ $ indexPadded = preg_replace ('/\s/ ' , chr (0xC2 ) . chr (0xA0 ), $ indexPadded );
161
+
162
+ $ line ['index ' ] = $ indexPadded . str_repeat (chr (0xC2 ) . chr (0xA0 ), 4 );
163
+ }
164
+
165
+ // remove the caller trace which is duplicated as the last item
166
+ array_pop ($ query ['trace ' ]);
167
+
168
+ // Find the first line that doesn't include `system` in the backtrace
169
+ $ firstNonSystemLine = '' ;
170
+
171
+ foreach ($ query ['trace ' ] as $ line ) {
172
+ if (strpos ($ line ['file ' ], 'SYSTEMPATH ' ) === false ) {
173
+ $ firstNonSystemLine = $ line ['file ' ];
174
+
175
+ break ;
152
176
}
153
- $ line = empty ($ line ) ? $ traceLine : $ line ;
154
177
}
155
178
156
179
return [
@@ -159,8 +182,7 @@ public function display(): array
159
182
'duration ' => ((float ) $ query ['query ' ]->getDuration (5 ) * 1000 ) . ' ms ' ,
160
183
'sql ' => $ query ['query ' ]->debugToolbarDisplay (),
161
184
'trace ' => $ query ['trace ' ],
162
- 'trace-file ' => str_replace (ROOTPATH , '/ ' , $ line ['file ' ] ?? '' ),
163
- 'trace-line ' => $ line ['line ' ] ?? '' ,
185
+ 'trace-file ' => $ firstNonSystemLine ,
164
186
'qid ' => md5 ($ query ['query ' ] . microtime ()),
165
187
];
166
188
}, static ::$ queries );
0 commit comments