Exemple #1
0
/* Completely disables all histories and clears all of them. */
static void
disable_history(void)
{
	free_view_history(&lwin);
	free_view_history(&rwin);

	(void)hist_reset(&cfg.search_hist, cfg.history_len);
	(void)hist_reset(&cfg.cmd_hist, cfg.history_len);
	(void)hist_reset(&cfg.prompt_hist, cfg.history_len);
	(void)hist_reset(&cfg.filter_hist, cfg.history_len);

	cfg.history_len = 0;
}
Exemple #2
0
void
hists_resize(int new_size)
{
	const int old_size = curr_stats.history_size;
	const int delta = new_size - old_size;

	if(new_size <= 0)
	{
		hist_reset(&curr_stats.search_hist, old_size);
		hist_reset(&curr_stats.cmd_hist, old_size);
		hist_reset(&curr_stats.prompt_hist, old_size);
		hist_reset(&curr_stats.filter_hist, old_size);
		curr_stats.history_size = 0;
		return;
	}

	curr_stats.history_size = new_size;

	if(delta < 0)
	{
		hist_trunc(&curr_stats.search_hist, new_size, -delta);
		hist_trunc(&curr_stats.cmd_hist, new_size, -delta);
		hist_trunc(&curr_stats.prompt_hist, new_size, -delta);
		hist_trunc(&curr_stats.filter_hist, new_size, -delta);
	}

	curr_stats.cmd_hist.items = reallocarray(curr_stats.cmd_hist.items, new_size,
			sizeof(char *));
	curr_stats.search_hist.items = reallocarray(curr_stats.search_hist.items,
			new_size, sizeof(char *));
	curr_stats.prompt_hist.items = reallocarray(curr_stats.prompt_hist.items,
			new_size, sizeof(char *));
	curr_stats.filter_hist.items = reallocarray(curr_stats.filter_hist.items,
			new_size, sizeof(char *));

	if(delta > 0)
	{
		const size_t str_item_len = sizeof(char *)*delta;

		memset(curr_stats.cmd_hist.items + old_size, 0, str_item_len);
		memset(curr_stats.search_hist.items + old_size, 0, str_item_len);
		memset(curr_stats.prompt_hist.items + old_size, 0, str_item_len);
		memset(curr_stats.filter_hist.items + old_size, 0, str_item_len);
	}
}
Exemple #3
0
int main(int argc, char **argv)
{
  int i, nthreads=-1;
  char *server_string = NULL;
  char opt;

  // deal w/ args
  while ( (opt = getopt(argc, argv, "ml:t:n:u:r:s:d")) != (char)EOF) {
    switch ( opt ) {
    case 'm':
      mdwstyle = 1;
      break;
    case 'l':
      spec_load = atoi(optarg);
      if( spec_load <= 0 ) usage("Invalid load level");
      break;
    case 't':
      total_reports = atoi(optarg);
      if( total_reports <= 0 ) usage("Invalid number of reports");
      break;
    case 'n':
      nthreads = atoi(optarg);
      if( nthreads <= 0 ) usage("Invalid number of threads");
      break;
    case 'u':
      server_string = optarg;
      break;
    case 'd':
      debug = 1;
      break;
    case 'r':
      nreqs = atoi(optarg);
      if( nreqs <= 0 ) usage("Invalid option for -n NUM_REQUESTS");
      break;
    case 's':
      sleep_ms = atoi(optarg);
      if( sleep_ms < 0 ) usage("Invalid option for -s SLEEP_MS");
      break;
    case '?':
      usage(NULL);
    default:
      usage("Invalid option");
    }
  }

  if( nthreads == -1 )
    usage("You must specify the number of threads.");
  if( server_string == NULL )
    usage("You didn't specify the base URL(s).");

  // set up the SPEC load generation
  setupDists(spec_load);

  // create some histograms
  connect_hist = hist_new(HIST_BUCKETS, 0); 
  err_connect_hist = hist_new(HIST_BUCKETS, 0); 
  request_hist = hist_new(HIST_BUCKETS, 0); 
  response_hist = hist_new(HIST_BUCKETS, 0); 
  close_hist = hist_new(HIST_BUCKETS, 0); 
  close_unconnected_hist = hist_new(HIST_BUCKETS, 0); 
  sleep_hist = hist_new(HIST_BUCKETS, 0); 

  // set up addres, ports, etc. for the servers
  {
    struct hostent *hostelement;
    char *str = server_string;
    char *end, c;
    int i=0;

    bzero( servers, sizeof(servers) );

    while( str != NULL  &&  *str != '\0' ) {
      // skip past http://
      if( strncasecmp(str,"http://",7) == 0 )
        str += 7;

      // read the hostname
      servers[i].hostname = str;
      str += strcspn(str,",/:");
      if( servers[i].hostname == str ) 
        usage("Invalid URL, hostname not found");
      c = *str; *str = '\0'; str++;

      // read the port
      if( c == ':' ) {
        servers[i].port = (int) strtol(str, &end, 0);
        if( servers[i].port == 0 || str == end ) 
          usage("Invalid port in URL.");
        str = end;
      } else {
        servers[i].port = 80;
      }

      // read the base URL
      str += strspn(str,"/");
      servers[i].url = str;
      
      // update the server structure
      servers[i].addr.sin_family = AF_INET;
      servers[i].addr.sin_port = htons((short)servers[i].port);

      hostelement = gethostbyname(servers[i].hostname);
      assert( hostelement );
      memcpy(&servers[i].addr.sin_addr, hostelement->h_addr, hostelement->h_length);


      printf("server %d:  host=%s  port=%d  url=%s\n",
             i, servers[i].hostname, servers[i].port, servers[i].url );

      // increment the number
      i++;
      if( i >= MAX_SERVERS )
        usage("Too many servers specified.");

      // end the URL string
      str += strcspn(str,",");
      if( *str == '\0' )
        break;
      *str = '\0';
      str++;

    }

    num_servers = i;

  }

  // spawn client threads
  {
    int rv;
    pthread_attr_t attr;
    pthread_t thread;

    pthread_attr_init( &attr );
    rv = pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
    assert (rv == 0);

    for( i=0; i<nthreads; i++ ) {
      int rv;
      rv = pthread_create(&thread, &attr, &client, (void*)i);
      assert( rv == 0);
    }
  }

  
  // periodically print stats
  { 
    cpu_tick_t prevstart;
    cpu_tick_t start, end;
    struct timeval tv_start, tv_prev;
    int num_reports_done = 0;

    // initial delay
    usleep( (STATS_INTERVAL_SECS*1e6) );

    GET_REAL_CPU_TICKS(prevstart);
    gettimeofday(&tv_prev, NULL);
    
    while( 1 ) {

      unsigned long long s_bytes_read = bytes_read;
      unsigned long long s_bytes_written = bytes_written;
      unsigned long long s_good_conn = good_conn;
      unsigned long long s_bad_conn = bad_conn;
      unsigned long long s_conn_timedout = conn_timedout;
      unsigned long long s_io_errors = io_errors;
      unsigned long long s_addrnotavail = addrnotavail;
      unsigned long long s_requests_completed = requests_completed;

      //unsigned long long s_bind_port_calls = bind_port_calls;
      //unsigned long long s_ports_checked = ports_checked;

      int connect_mean = hist_mean(connect_hist);
      int err_connect_mean = hist_mean(err_connect_hist);
      int request_mean = hist_mean(request_hist);
      int response_mean = hist_mean(response_hist);
      int close_mean = hist_mean(close_hist);
      int close_unconnected_mean = hist_mean(close_unconnected_hist);
      int sleep_mean = hist_mean(sleep_hist);
      hist_reset(connect_hist);
      hist_reset(err_connect_hist);
      hist_reset(request_hist);
      hist_reset(response_hist);
      hist_reset(close_hist);
      hist_reset(close_unconnected_hist);
      hist_reset(sleep_hist);

      

      GET_REAL_CPU_TICKS(start);
      gettimeofday(&tv_start, NULL);

      requests_completed = 0;
      addrnotavail = 0;
      bind_port_calls = 0;
      ports_checked = 0;
      io_errors = 0;
      bad_conn = 0;
      conn_timedout = 0;
      good_conn = 0;
      bytes_written = 0;
      bytes_read = 0;

      printf("(%.1f %.1f)  Mb/s: %5.2fr %5.2fw    conn/s: %5llu (%llu %4llu)   io err/s: %llu (%4llu)  -- idle: %d (%d)   conn: %d (%d,%d)   write: %d (%d)   read %d (%d)   close %d (%d,%d)\n",
             ((float)(start-prevstart)) / ticks_per_second,
             ((float)TVDIFF(tv_start,tv_prev)) / 1e6,
             ((float)s_bytes_read)*8/1024/1024 / STATS_INTERVAL_SECS, 
             ((float)s_bytes_written)*8/1024/1024 / STATS_INTERVAL_SECS, 
             s_good_conn/STATS_INTERVAL_SECS, 
             s_bad_conn/STATS_INTERVAL_SECS, 
             s_conn_timedout/STATS_INTERVAL_SECS,
             s_io_errors/STATS_INTERVAL_SECS, 
             s_addrnotavail/STATS_INTERVAL_SECS,

             state_idle, sleep_mean,
             state_connecting, connect_mean, err_connect_mean, 
             state_writing, request_mean, 
             state_reading, response_mean, 
             state_closing, close_mean, close_unconnected_mean
             ); 

      //0 BT: 4047705 5.174
      if( mdwstyle ) {
        printf("Connection Rate: %f connections/sec, %llu conns\n", ((float)s_good_conn)/STATS_INTERVAL_SECS, s_good_conn);
        printf("Overall rate:	%f completions/sec\n",    ((float)s_requests_completed)/STATS_INTERVAL_SECS);
        printf("Bandwidth:	%f bytes/sec\n", ((float)s_bytes_read) / STATS_INTERVAL_SECS); 

        // FIXME: add histograms, and fix these up
        //printf("Connect Time:	%f ms, max %d ms\n", 0, 0);
        //printf("Response Time:	%f ms, max %d ms\n", 0, 0);
        //printf("Combined Response Time:	%f ms, max %d ms\n", 0, 0);
      }

      fflush(stdout);

      num_reports_done++;
      if(num_reports_done >= total_reports) {
        // kludgey way to force an exit
        kill(getpid(), SIGINT);
        kill(getpid(), SIGQUIT);
        kill(getpid(), SIGKILL);
      }        


      GET_REAL_CPU_TICKS(end);

      usleep( (STATS_INTERVAL_SECS*1e6) - (end-start)/ticks_per_microsecond );

      prevstart = start;
      tv_prev = tv_start;
    }
  }


  return 0;
}
Exemple #4
0
void
vifm_restart(void)
{
	FileView *tmp_view;

	curr_stats.restart_in_progress = 1;

	/* All user mappings in all modes. */
	vle_keys_user_clear();

	/* User defined commands. */
	execute_cmd("comclear");

	/* Autocommands. */
	vle_aucmd_remove(NULL, NULL);

	/* Directory histories. */
	ui_view_clear_history(&lwin);
	ui_view_clear_history(&rwin);

	/* All kinds of history. */
	(void)hist_reset(&cfg.search_hist, cfg.history_len);
	(void)hist_reset(&cfg.cmd_hist, cfg.history_len);
	(void)hist_reset(&cfg.prompt_hist, cfg.history_len);
	(void)hist_reset(&cfg.filter_hist, cfg.history_len);
	cfg.history_len = 0;

	/* Session status.  Must be reset _before_ options, because options take some
	 * of values from status. */
	(void)reset_status(&cfg);

	/* Options of current pane. */
	reset_options_to_default();
	/* Options of other pane. */
	tmp_view = curr_view;
	curr_view = other_view;
	load_view_options(other_view);
	reset_options_to_default();
	curr_view = tmp_view;

	/* File types and viewers. */
	ft_reset(curr_stats.exec_env_type == EET_EMULATOR_WITH_X);

	/* Undo list. */
	reset_undo_list();

	/* Directory stack. */
	dir_stack_clear();

	/* Registers. */
	regs_reset();

	/* Clear all marks and bookmarks. */
	clear_all_marks();
	bmarks_clear();

	/* Reset variables. */
	clear_envvars();
	init_variables();
	/* This update is needed as clear_variables() will reset $PATH. */
	update_path_env(1);

	reset_views();
	read_info_file(1);
	flist_hist_save(&lwin, NULL, NULL, -1);
	flist_hist_save(&rwin, NULL, NULL, -1);

	/* Color schemes. */
	if(stroscmp(curr_stats.color_scheme, DEF_CS_NAME) != 0 &&
			cs_exists(curr_stats.color_scheme))
	{
		if(cs_load_primary(curr_stats.color_scheme) != 0)
		{
			cs_load_defaults();
		}
	}
	else
	{
		cs_load_defaults();
	}
	cs_load_pairs();

	cfg_load();
	exec_startup_commands(&vifm_args);

	curr_stats.restart_in_progress = 0;

	/* Trigger auto-commands for initial directories. */
	vle_aucmd_execute("DirEnter", lwin.curr_dir, &lwin);
	vle_aucmd_execute("DirEnter", rwin.curr_dir, &rwin);

	update_screen(UT_REDRAW);
}