/******************************************************************************
 * Function name - user_activity_smooth
 *
 * Description - Simulates user-activities using SMOOTH-MODE
 * Input -       *cctx_array - array of client contexts (related to a certain
 *                             batch of clients)
 * Return Code/Output - On Success - 0, on Error -1
 *******************************************************************************/
int user_activity_smooth (client_context* cctx_array)
{
        batch_context* bctx = cctx_array->bctx;

        if (!bctx)
        {
                fprintf (stderr, "%s - error: bctx is a NULL pointer.\n", __func__);
                return -1;
        }

        if (alloc_init_timer_waiting_queue (bctx->client_num_max + PERIODIC_TIMERS_NUMBER + 1,
                                            &bctx->waiting_queue) == -1)
        {
                fprintf (stderr,
                         "%s - error: failed to alloc or init timer waiting queue.\n",
                         __func__);
                return -1;
        }

        const unsigned long now_time = get_tick_count ();

        if (init_timers_and_add_initial_clients_to_load (bctx, now_time) == -1)
        {
                fprintf (stderr,
                         "%s - error: init_timers_and_add_initial_clients_to_load () failed.\n",
                         __func__);
                return -1;
        }

        if (is_batch_group_leader (bctx))
        {
                dump_snapshot_interval (bctx, now_time);
        }

        /*
           ========= Run the loading machinery ================
         */
        while ((pending_active_and_waiting_clients_num (bctx)) ||
               bctx->do_client_num_gradual_increase)
        {
                if (mget_url_smooth (bctx) == -1)
                {
                        fprintf (stderr, "%s error: mget_url () failed.\n", __func__);
                        return -1;
                }
        }

        dump_final_statistics (cctx_array);
        screen_release ();

        /*
           ======= Release resources =========================
         */
        if (bctx->waiting_queue)
        {
                /* Cancel periodic timers */
                cancel_periodic_timers (bctx);

                tq_release (bctx->waiting_queue);
                free (bctx->waiting_queue);
                bctx->waiting_queue = 0;
        }

        return 0;
}
Exemple #2
0
/****************************************************************************************
* Function name - dump_snapshot_interval_and_advance_total_statistics
*
* Description - Dumps snapshot_interval statistics for the latest loading time 
*               period and adds this statistics to the total loading counters. 
*
* Input -       *bctx    - pointer to batch context
*               now_time - current time in msec since the epoch
*
* Return Code/Output - None
****************************************************************************************/
void dump_snapshot_interval_and_advance_total_statistics (batch_context* bctx,
                                                          unsigned long now_time,
                                                          int clients_total_num)
{
  int i;
  const unsigned long delta_t = now_time - bctx->last_measure; 
  const unsigned long delta_time = delta_t ? delta_t : 1;

  if (stop_loading)
    {
      dump_final_statistics (bctx->cctx_array);
      screen_release ();

      if (create_ip_addrs (bctx, 1, 0) == -1)
      {
          fprintf (stderr, "%s - error: create_ip_addrs () remove secondary ip addresses failed. \n", __func__);
      }

      exit (1); 
    }

  fprintf(stdout,"============  loading batch is: %-10.10s ===================="
          "==================\n",
          bctx->batch_name);

  /*Collect the operational statistics*/

  for (i = 0; i <= threads_subbatches_num; i++)
    {
      if (i)
        {
          op_stat_point_add (&bctx->op_delta, &(bctx + i)->op_delta );

          /* Other threads operational statistics - reset just after collecting */
          op_stat_point_reset (&(bctx + i)->op_delta);
        }
    }

  op_stat_point_add (&bctx->op_total, &bctx->op_delta );

  print_operational_statistics (bctx->opstats_file,
                                &bctx->op_delta,
                                &bctx->op_total, 
                                bctx->url_ctx_array);


  fprintf(stdout,"--------------------------------------------------------------------------------\n");

  fprintf(stdout,"Interval stats (latest:%ld sec, clients:%d, CAPS-curr:%ld):\n",
          (unsigned long ) delta_time/1000, clients_total_num,
          bctx->op_delta.call_init_count* 1000/delta_time);

  op_stat_point_reset (&bctx->op_delta);


  for (i = 0; i <= threads_subbatches_num; i++)
    {
      if (i)
        {
          stat_point_add (&bctx->http_delta, &(bctx + i)->http_delta);
          stat_point_add (&bctx->https_delta, &(bctx + i)->https_delta);

          /* Other threads statistics - reset just after collecting */
          stat_point_reset (&(bctx + i)->http_delta); 
          stat_point_reset (&(bctx + i)->https_delta);
        }
    }

  stat_point_add (&bctx->http_total, &bctx->http_delta);
  stat_point_add (&bctx->https_total, &bctx->https_delta);

  print_snapshot_interval_statistics(delta_time, 
                                     &bctx->http_delta,  
                                     &bctx->https_delta);

  if (bctx->statistics_file)
    {
      const unsigned long timestamp_sec =  (now_time - bctx->start_time) / 1000;

      print_statistics_data_to_file (bctx->statistics_file,
                                     timestamp_sec,
                                     UNSECURE_APPL_STR,
                                     clients_total_num,
                                     &bctx->http_delta,
                                     delta_time);
    
      print_statistics_data_to_file (bctx->statistics_file, 
                                     timestamp_sec,
                                     SECURE_APPL_STR, 
                                     clients_total_num,
                                     &bctx->https_delta,
                                     delta_time);
    }

  stat_point_reset (&bctx->http_delta); 
  stat_point_reset (&bctx->https_delta);
        
  bctx->last_measure = now_time;
}