MCPcopy Create free account
hub / github.com/bloomberg/comdb2 / do_repeat

Function do_repeat

tools/cdb2sql/cdb2sql.cpp:1759–1816  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1757struct winsize win_size;
1758
1759static int do_repeat(char *sql)
1760{
1761 int64_t start_time_ms_tot = 0, run_time_ms_tot = 0;
1762 int start_time_ms, run_time_ms;
1763
1764 /* Trim whitespace and then ignore comments and empty lines. */
1765 while (isspace(*sql))
1766 sql++;
1767
1768 if (sql[0] == '#' || sql[0] == '\0' || (sql[0] == '-' && sql[1] == '-'))
1769 return 0;
1770
1771 if (sql[0] == '@') {
1772 return process_bind(sql);
1773 }
1774
1775 printmode |= DISP_NONE;
1776
1777 ioctl(STDOUT_FILENO, TIOCGWINSZ, &win_size);
1778 int progress_bar_width = win_size.ws_col - 20;
1779 int spaces = 0;
1780 int stars = 0;
1781 float progress_pct = 0;
1782 int last_progress_pct = 0;
1783
1784 /* Execute the query specified number of times */
1785 for (int i = 1; i <= repeat; i++) {
1786 start_time_ms = 0;
1787 run_time_ms = 0;
1788 process_line(sql, 0, NULL, &start_time_ms, &run_time_ms);
1789 start_time_ms_tot += start_time_ms;
1790 run_time_ms_tot += run_time_ms;
1791
1792 progress_pct = ((float)i / repeat) * 100;
1793 if ((int)progress_pct > last_progress_pct) {
1794 last_progress_pct = (int)progress_pct;
1795 stars = (progress_pct * progress_bar_width) / 100;
1796 spaces = progress_bar_width - stars;
1797 printf("executing: [%s%s] %.d%%\r", std::string(stars, '*').c_str(),
1798 std::string(spaces, ' ').c_str(), (int)progress_pct);
1799 fflush(stdout);
1800 }
1801 }
1802 cdb2_clearbindings(cdb2h);
1803
1804 printmode &= (~DISP_NONE);
1805
1806 printf("\n");
1807
1808 /* Print the summary */
1809 if (time_mode) {
1810 printf("summary:\n");
1811 printf(" total prep time %" PRId64 " ms\n", start_time_ms_tot);
1812 printf(" total run time %" PRId64 " ms\n", run_time_ms_tot);
1813 }
1814
1815 return 0;
1816}

Callers 1

mainFunction · 0.85

Calls 3

process_bindFunction · 0.85
cdb2_clearbindingsFunction · 0.85
process_lineFunction · 0.70

Tested by

no test coverage detected