| 402 | } |
| 403 | |
| 404 | bool PROFILING::show_profiles() |
| 405 | { |
| 406 | QUERY_PROFILE *prof; |
| 407 | List<Item> field_list; |
| 408 | MEM_ROOT *mem_root= thd->mem_root; |
| 409 | SELECT_LEX *sel= thd->lex->first_select_lex(); |
| 410 | SELECT_LEX_UNIT *unit= &thd->lex->unit; |
| 411 | ha_rows idx; |
| 412 | Protocol *protocol= thd->protocol; |
| 413 | void *iterator; |
| 414 | DBUG_ENTER("PROFILING::show_profiles"); |
| 415 | |
| 416 | field_list.push_back(new (mem_root) |
| 417 | Item_return_int(thd, "Query_ID", 10, |
| 418 | MYSQL_TYPE_LONG), |
| 419 | mem_root); |
| 420 | field_list.push_back(new (mem_root) |
| 421 | Item_return_int(thd, "Duration", |
| 422 | TIME_FLOAT_DIGITS - 1, |
| 423 | MYSQL_TYPE_DOUBLE), |
| 424 | mem_root); |
| 425 | field_list.push_back(new (mem_root) Item_empty_string(thd, "Query", 40), |
| 426 | mem_root); |
| 427 | |
| 428 | if (protocol->send_result_set_metadata(&field_list, |
| 429 | Protocol::SEND_NUM_ROWS | |
| 430 | Protocol::SEND_EOF)) |
| 431 | DBUG_RETURN(TRUE); |
| 432 | |
| 433 | unit->set_limit(sel); |
| 434 | |
| 435 | for (iterator= history.new_iterator(), idx= 1; |
| 436 | iterator != NULL; |
| 437 | iterator= history.iterator_next(iterator), idx++) |
| 438 | { |
| 439 | prof= history.iterator_value(iterator); |
| 440 | |
| 441 | double query_time_usecs= prof->m_end_time_usecs - prof->m_start_time_usecs; |
| 442 | |
| 443 | if (unit->lim.check_offset(idx)) |
| 444 | continue; |
| 445 | if (idx > unit->lim.get_select_limit()) |
| 446 | break; |
| 447 | |
| 448 | protocol->prepare_for_resend(); |
| 449 | protocol->store((uint32)(prof->profiling_query_id)); |
| 450 | protocol->store_double(query_time_usecs/(1000.0*1000), |
| 451 | (uint32) TIME_FLOAT_DIGITS-1); |
| 452 | if (prof->query_source != NULL) |
| 453 | protocol->store(prof->query_source, strlen(prof->query_source), |
| 454 | system_charset_info); |
| 455 | else |
| 456 | protocol->store_null(); |
| 457 | |
| 458 | if (protocol->write()) |
| 459 | DBUG_RETURN(TRUE); |
| 460 | } |
| 461 | my_eof(thd); |
no test coverage detected