| 90 | } |
| 91 | |
| 92 | bool CallGenerationTask::run() |
| 93 | { |
| 94 | int calls_to_open = 0; |
| 95 | |
| 96 | if (quitting) { |
| 97 | delete this; |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | if (paused) { |
| 102 | setPaused(); |
| 103 | return true; |
| 104 | } |
| 105 | |
| 106 | unsigned long long current_calls = main_scenario->stats->GetStat(CStat::CPT_C_CurrentCall); |
| 107 | unsigned long long total_calls = main_scenario->stats->GetStat(CStat::CPT_C_IncomingCallCreated) + main_scenario->stats->GetStat(CStat::CPT_C_OutgoingCallCreated); |
| 108 | |
| 109 | if (users >= 0) { |
| 110 | calls_to_open = users - current_calls; |
| 111 | } else { |
| 112 | float calls_per_ms = rate/rate_period_ms; |
| 113 | unsigned int ms_since_last_rate_change = clock_tick - last_rate_change_time; |
| 114 | unsigned int expected_total_calls = ms_since_last_rate_change * calls_per_ms; |
| 115 | calls_to_open = expected_total_calls - calls_since_last_rate_change; |
| 116 | } |
| 117 | |
| 118 | if (total_calls + calls_to_open > stop_after) { |
| 119 | calls_to_open = stop_after - total_calls; |
| 120 | } |
| 121 | |
| 122 | /* We base our scheduling on the number of calls made since the last rate |
| 123 | * change, but if we reduce the number of calls we open in order to keep |
| 124 | * within the limit, that throws this calculation off and brings CPU% up to |
| 125 | * 100%. To avoid this, we increment calls_since_last_rate_change here. */ |
| 126 | |
| 127 | calls_since_last_rate_change += calls_to_open; |
| 128 | |
| 129 | if (open_calls_allowed && (current_calls + calls_to_open > open_calls_allowed)) { |
| 130 | calls_to_open = open_calls_allowed - current_calls; |
| 131 | } |
| 132 | |
| 133 | if (calls_to_open <= 0) { |
| 134 | calls_to_open = 0; |
| 135 | } |
| 136 | |
| 137 | unsigned int start_clock = getmilliseconds(); |
| 138 | |
| 139 | |
| 140 | while(calls_to_open--) { |
| 141 | /* Associate a user with this call, if we are in users mode. */ |
| 142 | int userid = 0; |
| 143 | if (users >= 0) { |
| 144 | userid = freeUsers.back(); |
| 145 | freeUsers.pop_back(); |
| 146 | } |
| 147 | |
| 148 | // Adding a new outgoing call |
| 149 | main_scenario->stats->computeStat(CStat::E_CREATE_OUTGOING_CALL); |
nothing calls this directly
no test coverage detected