Changeset 19138 for trunk/FACT++
- Timestamp:
- 08/04/18 20:25:42 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/rootifysql.cc
r19137 r19138 354 354 } 355 355 356 int finish(Database &connection, const uint16_t &verbose, const bool &profiling, const bool &print_connection) 357 { 358 if (verbose>0) 359 { 360 try 361 { 362 const auto resw = 363 connection.query("SHOW WARNINGS").store(); 364 365 if (resw.num_rows()>0) 366 cout << "\n" << resw.num_rows() << " Warning(s) issued:\n\n"; 367 368 for (size_t i=0; i<resw.num_rows(); i++) 369 { 370 const mysqlpp::Row &roww = resw[i]; 371 372 cout << roww["Level"] << '[' << roww["Code"] << "]: "; 373 cout << roww["Message"] << '\n'; 374 } 375 cout << endl; 376 377 } 378 catch (const exception &e) 379 { 380 cerr << "\nSHOW WARNINGS\n\n"; 381 cerr << "SQL query failed:\n" << e.what() << endl; 382 return 6; 383 } 384 } 385 386 if (profiling) 387 { 388 try 389 { 390 const auto N = 391 connection.query("SHOW PROFILES").store().num_rows(); 392 393 const auto resp = 394 connection.query("SHOW PROFILE ALL FOR QUERY "+to_string(verbose?N-1:N)).store(); 395 396 cout << '\n'; 397 cout << left; 398 cout << setw(26) << "Status" << ' '; 399 cout << right; 400 cout << setw(11) << "Duration" << ' '; 401 cout << setw(11) << "CPU User" << ' '; 402 cout << setw(11) << "CPU System" << '\n'; 403 cout << "--------------------------------------------------------------\n"; 404 for (size_t i=0; i<resp.num_rows(); i++) 405 { 406 const mysqlpp::Row &rowp = resp[i]; 407 408 cout << left; 409 cout << setw(26) << rowp["Status"] << ' '; 410 cout << right; 411 cout << setw(11) << rowp["Duration"] << ' '; 412 cout << setw(11) << rowp["CPU_user"] << ' '; 413 cout << setw(11) << rowp["CPU_system"] << '\n'; 414 } 415 cout << "--------------------------------------------------------------\n"; 416 cout << endl; 417 } 418 catch (const exception &e) 419 { 420 cerr << "\nSHOW PROFILE ALL\n\n"; 421 cerr << "SQL query failed:\n" << e.what() << '\n' <<endl; 422 return 11; 423 } 424 } 425 426 if (print_connection) 427 { 428 try 429 { 430 // Exchange _send and _received as it is the view of the server 431 const auto &res1 = connection.query("SHOW STATUS LIKE 'Bytes_%'").store(); 432 cout << left << setw(16) << res1[1]["Variable_name"] << ' ' << Tools::Scientific(res1[0]["Value"]) << endl; 433 cout << left << setw(16) << res1[0]["Variable_name"] << ' ' << Tools::Scientific(res1[1]["Value"]) << endl; 434 cout << endl; 435 } 436 catch (const exception &e) 437 { 438 cerr << "\nSHOW STATUS LIKE 'Bytes_%'\n\n"; 439 cerr << "SQL query failed:\n" << e.what() << endl; 440 return 6; 441 } 442 } 443 444 return 0; 445 446 } 447 356 448 int main(int argc, const char* argv[]) 357 449 { … … 674 766 { 675 767 cerr << "Empty set returned... nothing to write." << endl; 768 finish(connection, verbose, profiling, print_connection); 676 769 return 10; 677 770 } … … 874 967 cout << "(" << Tools::Fractional(sec/count) << "s/row)\n"; 875 968 cout << "--------------------------------------------------------------" << endl; 876 877 try 878 { 879 const auto resw = 880 connection.query("SHOW WARNINGS").store(); 881 882 if (resw.num_rows()>0) 883 cout << "\n" << resw.num_rows() << " Warning(s) issued:\n\n"; 884 885 for (size_t i=0; i<resw.num_rows(); i++) 886 { 887 const mysqlpp::Row &roww = resw[i]; 888 889 cout << roww["Level"] << '[' << roww["Code"] << "]: "; 890 cout << roww["Message"] << '\n'; 891 } 892 cout << endl; 893 894 } 895 catch (const exception &e) 896 { 897 cerr << "\nSHOW WARNINGS\n\n"; 898 cerr << "SQL query failed:\n" << e.what() << endl; 899 return 6; 900 } 901 } 902 903 if (profiling) 904 { 905 try 906 { 907 const auto N = 908 connection.query("SHOW PROFILES").store().num_rows(); 909 910 const auto resp = 911 connection.query("SHOW PROFILE ALL FOR QUERY "+to_string(verbose?N-1:N)).store(); 912 913 cout << '\n'; 914 cout << left; 915 cout << setw(26) << "Status" << ' '; 916 cout << right; 917 cout << setw(11) << "Duration" << ' '; 918 cout << setw(11) << "CPU User" << ' '; 919 cout << setw(11) << "CPU System" << '\n'; 920 cout << "--------------------------------------------------------------\n"; 921 for (size_t i=0; i<resp.num_rows(); i++) 922 { 923 const mysqlpp::Row &rowp = resp[i]; 924 925 cout << left; 926 cout << setw(26) << rowp["Status"] << ' '; 927 cout << right; 928 cout << setw(11) << rowp["Duration"] << ' '; 929 cout << setw(11) << rowp["CPU_user"] << ' '; 930 cout << setw(11) << rowp["CPU_system"] << '\n'; 931 } 932 cout << "--------------------------------------------------------------\n"; 933 cout << endl; 934 } 935 catch (const exception &e) 936 { 937 cerr << "\nSHOW PROFILE ALL\n\n"; 938 cerr << "SQL query failed:\n" << e.what() << '\n' <<endl; 939 return 11; 940 } 941 } 942 943 if (print_connection) 944 { 945 try 946 { 947 // Exchange _send and _received as it is the view of the server 948 const auto &res1 = connection.query("SHOW STATUS LIKE 'Bytes_%'").store(); 949 cout << left << setw(16) << res1[1]["Variable_name"] << ' ' << Tools::Scientific(res1[0]["Value"]) << endl; 950 cout << left << setw(16) << res1[0]["Variable_name"] << ' ' << Tools::Scientific(res1[1]["Value"]) << endl; 951 cout << endl; 952 } 953 catch (const exception &e) 954 { 955 cerr << "\nSHOW STATUS LIKE 'Bytes_%'\n\n"; 956 cerr << "SQL query failed:\n" << e.what() << endl; 957 return 6; 958 } 959 } 960 961 return 0; 969 } 970 971 return finish(connection, verbose, profiling, print_connection); 962 972 }
Note:
See TracChangeset
for help on using the changeset viewer.