| 6654 | } |
| 6655 | |
| 6656 | static THREAD_FUNC_RETURN_TYPE THREAD_FUNC_CC |
| 6657 | threadRun(void *arg) |
| 6658 | { |
| 6659 | TState *thread = (TState *) arg; |
| 6660 | CState *state = thread->state; |
| 6661 | pg_time_usec_t start; |
| 6662 | int nstate = thread->nstate; |
| 6663 | int remains = nstate; /* number of remaining clients */ |
| 6664 | socket_set *sockets = alloc_socket_set(nstate); |
| 6665 | int64 thread_start, |
| 6666 | last_report, |
| 6667 | next_report; |
| 6668 | StatsData last, |
| 6669 | aggs; |
| 6670 | |
| 6671 | /* open log file if requested */ |
| 6672 | if (use_log) |
| 6673 | { |
| 6674 | char logpath[MAXPGPATH]; |
| 6675 | char *prefix = logfile_prefix ? logfile_prefix : "pgbench_log"; |
| 6676 | |
| 6677 | if (thread->tid == 0) |
| 6678 | snprintf(logpath, sizeof(logpath), "%s.%d", prefix, main_pid); |
| 6679 | else |
| 6680 | snprintf(logpath, sizeof(logpath), "%s.%d.%d", prefix, main_pid, thread->tid); |
| 6681 | |
| 6682 | thread->logfile = fopen(logpath, "w"); |
| 6683 | |
| 6684 | if (thread->logfile == NULL) |
| 6685 | { |
| 6686 | pg_log_fatal("could not open logfile \"%s\": %m", logpath); |
| 6687 | goto done; |
| 6688 | } |
| 6689 | } |
| 6690 | |
| 6691 | /* explicitly initialize the state machines */ |
| 6692 | for (int i = 0; i < nstate; i++) |
| 6693 | state[i].state = CSTATE_CHOOSE_SCRIPT; |
| 6694 | |
| 6695 | /* READY */ |
| 6696 | THREAD_BARRIER_WAIT(&barrier); |
| 6697 | |
| 6698 | thread_start = pg_time_now(); |
| 6699 | thread->started_time = thread_start; |
| 6700 | thread->conn_duration = 0; |
| 6701 | last_report = thread_start; |
| 6702 | next_report = last_report + (int64) 1000000 * progress; |
| 6703 | |
| 6704 | /* STEADY */ |
| 6705 | if (!is_connect) |
| 6706 | { |
| 6707 | /* make connections to the database before starting */ |
| 6708 | for (int i = 0; i < nstate; i++) |
| 6709 | { |
| 6710 | if ((state[i].con = doConnect()) == NULL) |
| 6711 | { |
| 6712 | /* |
| 6713 | * On connection failure, we meet the barrier here in place of |
no test coverage detected