@@ -175,11 +175,8 @@ void QUERY_PROFILE::set_query_source(char *query_source_arg,
175
175
176
176
QUERY_PROFILE::~QUERY_PROFILE ()
177
177
{
178
- PROFILE_ENTRY *entry;
179
- List_iterator<PROFILE_ENTRY> it (entries);
180
- while ((entry= it++) != NULL )
181
- delete entry;
182
- entries.empty ();
178
+ while (! entries.is_empty ())
179
+ delete entries.pop ();
183
180
184
181
if (query_source != NULL )
185
182
my_free (query_source, MYF (0 ));
@@ -191,7 +188,6 @@ void QUERY_PROFILE::status(const char *status_arg,
191
188
{
192
189
THD *thd= profiling->thd ;
193
190
PROFILE_ENTRY *prof;
194
- MEM_ROOT *saved_mem_root;
195
191
DBUG_ENTER (" QUERY_PROFILE::status" );
196
192
197
193
/* Blank status. Just return, and thd->proc_info will be set blank later. */
@@ -210,22 +206,6 @@ void QUERY_PROFILE::status(const char *status_arg,
210
206
if (unlikely ((thd->query_id != server_query_id) && !thd->spcont ))
211
207
reset ();
212
208
213
- /*
214
- In order to keep the profile information between queries (i.e. from
215
- SELECT to the following SHOW PROFILE command) the following code is
216
- necessary to keep the profile from getting freed automatically when
217
- mysqld cleans up after the query.
218
-
219
- The "entries" list allocates is memory from the current thd's mem_root.
220
- We substitute our mem_root temporarily so that we intercept those
221
- allocations into our own mem_root.
222
-
223
- The thd->mem_root structure is freed after each query is completed,
224
- so temporarily override it.
225
- */
226
- saved_mem_root= thd->mem_root ;
227
- thd->mem_root = &profiling->mem_root ;
228
-
229
209
if (function_arg && file_arg)
230
210
{
231
211
if ((profile_end= prof= new PROFILE_ENTRY (this , status_arg, function_arg,
@@ -238,9 +218,6 @@ void QUERY_PROFILE::status(const char *status_arg,
238
218
entries.push_back (prof);
239
219
}
240
220
241
- /* Restore mem_root */
242
- thd->mem_root = saved_mem_root;
243
-
244
221
DBUG_VOID_RETURN;
245
222
}
246
223
@@ -252,11 +229,8 @@ void QUERY_PROFILE::reset()
252
229
server_query_id= profiling->thd ->query_id ; /* despite name, is global */
253
230
profile_start.collect ();
254
231
255
- PROFILE_ENTRY *entry;
256
- List_iterator<PROFILE_ENTRY> it (entries);
257
- while ((entry= it++) != NULL )
258
- delete entry;
259
- entries.empty ();
232
+ while (! entries.is_empty ())
233
+ delete entries.pop ();
260
234
}
261
235
DBUG_VOID_RETURN;
262
236
}
@@ -344,10 +318,14 @@ bool QUERY_PROFILE::show(uint options)
344
318
struct rusage *last_rusage= &(profile_start.rusage );
345
319
#endif
346
320
347
- List_iterator<PROFILE_ENTRY> it (entries);
348
321
PROFILE_ENTRY *entry;
349
- while ((entry= it++) != NULL )
322
+ void *iterator;
323
+ for (iterator= entries.new_iterator ();
324
+ iterator != NULL ;
325
+ iterator= entries.iterator_next (iterator))
350
326
{
327
+ entry= entries.iterator_value (iterator);
328
+
351
329
#ifdef HAVE_GETRUSAGE
352
330
struct rusage *rusage = &(entry->rusage );
353
331
#endif
@@ -463,24 +441,15 @@ bool QUERY_PROFILE::show(uint options)
463
441
PROFILING::PROFILING ()
464
442
:profile_id_counter(0 ), keeping(1 ), current(NULL ), last(NULL )
465
443
{
466
- init_sql_alloc (&mem_root,
467
- PROFILE_ALLOC_BLOCK_SIZE,
468
- PROFILE_ALLOC_PREALLOC_SIZE);
469
444
}
470
445
471
446
PROFILING::~PROFILING ()
472
447
{
473
- QUERY_PROFILE *prof;
474
-
475
- List_iterator<QUERY_PROFILE> it (history);
476
- while ((prof= it++) != NULL )
477
- delete prof;
478
- history.empty ();
448
+ while (! history.is_empty ())
449
+ delete history.pop ();
479
450
480
451
if (current != NULL )
481
452
delete current;
482
-
483
- free_root (&mem_root, MYF (0 ));
484
453
}
485
454
486
455
void PROFILING::status_change (const char *status_arg,
@@ -505,7 +474,6 @@ void PROFILING::status_change(const char *status_arg,
505
474
506
475
void PROFILING::store ()
507
476
{
508
- MEM_ROOT *saved_mem_root;
509
477
DBUG_ENTER (" PROFILING::store" );
510
478
511
479
/* Already stored */
@@ -517,22 +485,8 @@ void PROFILING::store()
517
485
}
518
486
519
487
while (history.elements > thd->variables .profiling_history_size )
520
- {
521
- QUERY_PROFILE *tmp= history.pop ();
522
- delete tmp;
523
- }
524
-
525
- /*
526
- Switch out memory roots so that we're sure that we keep what we need
527
-
528
- The "history" list implementation allocates its memory in the current
529
- thd's mem_root. We substitute our mem_root temporarily so that we
530
- intercept those allocations into our own mem_root.
531
- */
488
+ delete history.pop ();
532
489
533
- saved_mem_root= thd->mem_root ;
534
- thd->mem_root = &mem_root;
535
-
536
490
if (current != NULL )
537
491
{
538
492
if (keeping &&
@@ -556,9 +510,6 @@ void PROFILING::store()
556
510
DBUG_ASSERT (current == NULL );
557
511
current= new QUERY_PROFILE (this , thd->query , thd->query_length );
558
512
559
- /* Restore memory root */
560
- thd->mem_root = saved_mem_root;
561
-
562
513
DBUG_VOID_RETURN;
563
514
}
564
515
@@ -598,9 +549,13 @@ bool PROFILING::show_profiles()
598
549
599
550
unit->set_limit (sel);
600
551
601
- List_iterator<QUERY_PROFILE> it (history);
602
- while ((prof= it++) != NULL )
552
+ void *iterator;
553
+ for (iterator= history.new_iterator ();
554
+ iterator != NULL ;
555
+ iterator= history.iterator_next (iterator))
603
556
{
557
+ prof= history.iterator_value (iterator);
558
+
604
559
String elapsed;
605
560
606
561
PROFILE_ENTRY *ps= &prof->profile_start ;
@@ -651,9 +606,13 @@ bool PROFILING::show(uint options, uint profiling_query_id)
651
606
DBUG_ENTER (" PROFILING::show" );
652
607
QUERY_PROFILE *prof;
653
608
654
- List_iterator<QUERY_PROFILE> it (history);
655
- while ((prof= it++) != NULL )
609
+ void *iterator;
610
+ for (iterator= history.new_iterator ();
611
+ iterator != NULL ;
612
+ iterator= history.iterator_next (iterator))
656
613
{
614
+ prof= history.iterator_value (iterator);
615
+
657
616
if (prof->profiling_query_id == profiling_query_id)
658
617
DBUG_RETURN (prof->show (options));
659
618
}
@@ -681,11 +640,15 @@ int PROFILING::fill_statistics_info(THD *thd, struct st_table_list *tables, Item
681
640
TABLE *table= tables->table ;
682
641
ulonglong row_number= 0 ;
683
642
684
- List_iterator<QUERY_PROFILE> query_it (history);
685
643
QUERY_PROFILE *query;
686
644
/* Go through each query in this thread's stored history... */
687
- while ((query= query_it++) != NULL )
645
+ void *history_iterator;
646
+ for (history_iterator= history.new_iterator ();
647
+ history_iterator != NULL ;
648
+ history_iterator= history.iterator_next (history_iterator))
688
649
{
650
+ query= history.iterator_value (history_iterator);
651
+
689
652
PROFILE_ENTRY *ps= &(query->profile_start );
690
653
double last_time= ps->time_usecs ;
691
654
#ifdef HAVE_GETRUSAGE
@@ -699,16 +662,20 @@ int PROFILING::fill_statistics_info(THD *thd, struct st_table_list *tables, Item
699
662
*/
700
663
ulonglong seq;
701
664
702
- List_iterator<PROFILE_ENTRY> step_it (query-> entries ) ;
665
+ void *entry_iterator ;
703
666
PROFILE_ENTRY *entry;
704
667
/* ...and for each query, go through all its state-change steps. */
705
- for (seq= 0 , entry= step_it++;
706
- entry != NULL ;
668
+ for (seq= 0 , entry_iterator= query->entries .new_iterator ();
669
+ entry_iterator != NULL ;
670
+ entry_iterator= query->entries .iterator_next (entry_iterator),
707
671
#ifdef HAVE_GETRUSAGE
708
672
last_rusage= &(entry->rusage ),
709
673
#endif
710
- seq++, last_time= entry->time_usecs , entry= step_it++, row_number++)
674
+ seq++, last_time= entry->time_usecs , row_number++)
711
675
{
676
+ entry= query->entries .iterator_value (entry_iterator);
677
+
678
+
712
679
/* Set default values for this row. */
713
680
restore_record (table, s->default_values );
714
681
0 commit comments