active_survey::active_survey(int argc, char **argv):
    nh_("active_survey")
{    
    ros::NodeHandle private_node_handle_("~");
    active_survey_param::GetParams(private_node_handle_);


    mav_ = std::make_shared<mav>(*environment_model::instance(), Vector3f{-0.5f*static_cast<float>(active_survey_param::area_width),
                                                                         -0.5f*static_cast<float>(active_survey_param::area_height),
                                                                         10.0f});

    if(active_survey_param::logging)
    {
        setup_log_file();
    }

    active_survey_log("this is a test for active_survey logging system.");
}
// application setup method
void emDNA_Application::setup_application() {

    // log file
    setup_log_file(m_cmd_line.output_name());

    // log command line input
    m_log_file.log_emDNA_CommandLine(m_cmd_line);

    // bp collection
    setup_bp_collection();

    // log bp collection
    m_log_file.log_BpCollection(m_bp_collection);

    // setup message
    if (!m_cmd_line.quiet_flag())
        application_setup_message();

};
Beispiel #3
0
int
main(int argc, char *argv[])
{
  int i, j = 0;
  int create_flag = 0;
  const unsigned char *user = 0, *group = 0, *workdir = 0;
  int restart_flag = 0;
  char **argv_restart = 0;
  int pid;
  time_t server_start_time = 0;

  hr_set_symbolic_action_table(NEW_SRV_ACTION_LAST, ns_symbolic_action_table, ns_submit_button_labels, 0);
  time(&server_start_time);
  start_set_self_args(argc, argv);
  /* certain options should be removed for restart */
  XCALLOC(argv_restart, argc + 2);
  argv_restart[j++] = argv[0];

  params.program_name = argv[0];
  for (i = 1; i < argc; ) {
    if (!strcmp(argv[i], "-D")) {
      params.daemon_mode_flag = 1;
      i++;
    } else if (!strcmp(argv[i], "-f")) {
      params.force_socket_flag = 1;
      argv_restart[j++] = argv[i];
      i++;
    } else if (!strcmp(argv[i], "--create")) {
      create_flag = 1;
      i++;
    } else if (!strcmp(argv[i], "-u")) {
      if (++i >= argc) startup_error("invalid usage");
      user = argv[i++];
    } else if (!strcmp(argv[i], "-g")) {
      if (++i >= argc) startup_error("invalid usage");
      group = argv[i++];
    } else if (!strcmp(argv[i], "-C")) {
      if (++i >= argc) startup_error("invalid usage");
      workdir = argv[i++];
    } else if (!strcmp(argv[i], "-R")) {
      params.restart_mode_flag = 1;
      ++i;
    } else if (!strcmp(argv[i], "--")) {
      argv_restart[j++] = argv[i];
      i++;
      break;
    } else if (argv[i][0] == '-') {
      startup_error("invalid option `%s'", argv[i]);
    } else
      break;
  }
  argv_restart[j++] = "-R";
  if (i < argc) {
    argv_restart[j++] = argv[i];
    ejudge_xml_path = argv[i++];
  }
  if (i != argc) startup_error("invalid number of parameters");
  argv_restart[j] = 0;
  start_set_args(argv_restart);

  if (!(pid = start_find_process("ej-contests", 0))) {
    params.force_socket_flag = 1;
  } else if (pid > 0) {
    fprintf(stderr, "%s: is already running as pid %d\n", argv[0], pid);
    return 1;
  }

  if (start_prepare(user, group, workdir) < 0) return 1;

  if (workdir && *workdir) {
    if (chdir(workdir) < 0) {
      err("cannot change directory to %s", workdir);
      return 1;
    }
  }

#if defined EJUDGE_XML_PATH
  if (!ejudge_xml_path) ejudge_xml_path = EJUDGE_XML_PATH;
#endif /* EJUDGE_XML_PATH */
  if (!ejudge_xml_path) startup_error("configuration file is not specified");

  ejudge_config = ejudge_cfg_parse(ejudge_xml_path, 0);
  if (!ejudge_config) return 1;
  if (contests_set_directory(ejudge_config->contests_dir) < 0) return 1;
  l10n_prepare(ejudge_config->l10n, ejudge_config->l10n_dir);
  if (!strcasecmp(EJUDGE_CHARSET, "UTF-8")) utf8_mode = 1;
#if defined EJUDGE_NEW_SERVER_SOCKET
  if (!ejudge_config->new_server_socket)
    ejudge_config->new_server_socket = xstrdup(EJUDGE_NEW_SERVER_SOCKET);
#endif
  if (!ejudge_config->new_server_socket)
    ejudge_config->new_server_socket=xstrdup(EJUDGE_NEW_SERVER_SOCKET_DEFAULT);

#if defined EJUDGE_CONTESTS_HOME_DIR
  if (!ejudge_config->contests_home_dir)
    ejudge_config->contests_home_dir = xstrdup(EJUDGE_CONTESTS_HOME_DIR);
#endif
  setup_log_file();

  info("ej-contests %s, compiled %s", compile_version, compile_date);

  params.socket_path = ejudge_config->new_server_socket;
  params.log_path = ejudge_config->new_server_log;

  if (load_plugins() < 0) return 1;

  // initialize the default plugin
  if (nsdb_default->iface->open(nsdb_default->data) < 0) {
    startup_error("default plugin failed to open its connection");
    return 1;
  }

  if (create_flag) {
    if (nsdb_default->iface->create(nsdb_default->data) < 0) {
      startup_error("database creation failed");
      return 1;
    }
    if (nsdb_default->iface->close(nsdb_default->data) < 0) {
      startup_error("database closing failed");
      return 1;
    }
    return 0;
  }

  if (nsdb_default->iface->check(nsdb_default->data) <= 0) {
    startup_error("default plugin failed to check its data");
    return 1;
  }

  if (!(state = nsf_init(&params, 0, server_start_time))) return 1;
  if (nsf_prepare(state) < 0) return 1;
  nsf_main_loop(state);
  restart_flag = nsf_is_restart_requested(state);
  ns_unload_contests();
  nsf_cleanup(state);
  nsdb_default->iface->close(nsdb_default->data);

  if (restart_flag) start_restart();

  return 0;
}
Beispiel #4
0
int main(int argc, char **argv)
{
	CONFIG cfg;
	WT_CONNECTION *conn;
	const char *user_cconfig, *user_tconfig;
	const char *opts = "C:I:P:R:U:T:c:d:eh:i:jk:l:m:r:ps:t:u:v:SML";
	char *cc_buf, *tc_buf;
	int ch, checkpoint_created, ret, stat_created;
	pthread_t checkpoint, stat;
	uint64_t req_len;

	/* Setup the default configuration values. */
	memcpy(&cfg, &default_cfg, sizeof(cfg));
	cc_buf = tc_buf = NULL;
	user_cconfig = user_tconfig = NULL;
	conn = NULL;
	checkpoint_created = stat_created = 0;

	/*
	 * First parse different config structures - other options override
	 * fields within the structure.
	 */
	while ((ch = getopt(argc, argv, opts)) != EOF)
		switch (ch) {
		case 'S':
			memcpy(&cfg, &small_cfg, sizeof(cfg));
			break;
		case 'M':
			memcpy(&cfg, &med_cfg, sizeof(cfg));
			break;
		case 'L':
			memcpy(&cfg, &large_cfg, sizeof(cfg));
			break;
		default:
			/* Validation is provided on the next parse. */
			break;
		}

	/* Parse other options */
	optind = 1;
	while ((ch = getopt(argc, argv, opts)) != EOF)
		switch (ch) {
		case 'd':
			cfg.data_sz = (uint32_t)atoi(optarg);
			break;
		case 'c':
			cfg.checkpoint_interval = (uint32_t)atoi(optarg);
			break;
		case 'e':
			cfg.create = 0;
			break;
		case 'h':
			cfg.home = optarg;
			break;
		case 'i':
			cfg.icount = (uint32_t)atoi(optarg);
			break;
		case 'j':
			F_SET(&cfg, PERF_INSERT_RMW);
			break;
		case 'k':
			cfg.key_sz = (uint32_t)atoi(optarg);
			break;
		case 'l':
			cfg.stat_interval = (uint32_t)atoi(optarg);
			break;
		case 'm':
			F_SET(&cfg, PERF_RAND_WORKLOAD);
			cfg.rand_range = (uint32_t)atoi(optarg);
			if (cfg.rand_range == 0) {
				fprintf(stderr, "Invalid random range.\n");
				usage();
				return (EINVAL);
			}
				
			break;
		case 'p':
			F_SET(&cfg, PERF_RAND_PARETO);
			break;
		case 'r':
			cfg.run_time = (uint32_t)atoi(optarg);
			break;
		case 's':
			cfg.rand_seed = (uint32_t)atoi(optarg);
			break;
		case 't':
			cfg.report_interval = (uint32_t)atoi(optarg);
			break;
		case 'u':
			cfg.uri = optarg;
			break;
		case 'v':
			cfg.verbose = (uint32_t)atoi(optarg);
			break;
		case 'C':
			user_cconfig = optarg;
			break;
		case 'I':
			cfg.insert_threads = (uint32_t)atoi(optarg);
			break;
		case 'P':
			cfg.populate_threads = (uint32_t)atoi(optarg);
			break;
		case 'R':
			cfg.read_threads = (uint32_t)atoi(optarg);
			break;
		case 'U':
			cfg.update_threads = (uint32_t)atoi(optarg);
			break;
		case 'T':
			user_tconfig = optarg;
			break;
		case 'L':
		case 'M':
		case 'S':
			break;
		case '?':
		default:
			fprintf(stderr, "Invalid option\n");
			usage();
			return (EINVAL);
		}

	if ((ret = setup_log_file(&cfg)) != 0)
		goto err;

	/* Make stdout line buffered, so verbose output appears quickly. */
	(void)setvbuf(stdout, NULL, _IOLBF, 0);

	/* Concatenate non-default configuration strings. */
	if (cfg.verbose > 1 || user_cconfig != NULL) {
		req_len = strlen(cfg.conn_config) + strlen(debug_cconfig) + 3;
		if (user_cconfig != NULL)
			req_len += strlen(user_cconfig);
		cc_buf = calloc(req_len, 1);
		if (cc_buf == NULL) {
			ret = ENOMEM;
			goto err;
		}
		snprintf(cc_buf, req_len, "%s%s%s%s%s",
		    cfg.conn_config,
		    cfg.verbose > 1 ? "," : "",
		    cfg.verbose > 1 ? debug_cconfig : "",
		    user_cconfig ? "," : "", user_cconfig ? user_cconfig : "");
		cfg.conn_config = cc_buf;
	}
	if (cfg.verbose > 1 || user_tconfig != NULL) {
		req_len = strlen(cfg.table_config) + strlen(debug_tconfig) + 3;
		if (user_tconfig != NULL)
			req_len += strlen(user_tconfig);
		tc_buf = calloc(req_len, 1);
		if (tc_buf == NULL) {
			ret = ENOMEM;
			goto err;
		}
		snprintf(tc_buf, req_len, "%s%s%s%s%s",
		    cfg.table_config,
		    cfg.verbose > 1 ? "," : "",
		    cfg.verbose > 1 ? debug_tconfig : "",
		    user_tconfig ? "," : "", user_tconfig ? user_tconfig : "");
		cfg.table_config = tc_buf;
	}

	wtperf_srand(&cfg);

	if (cfg.verbose > 1)
		print_config(&cfg);

	/* Open a connection to the database, creating it if necessary. */
	if ((ret = wiredtiger_open(
	    cfg.home, NULL, cfg.conn_config, &conn)) != 0) {
		lprintf(&cfg, ret, 0, "Error connecting to %s", cfg.home);
		goto err;
	}

	cfg.conn = conn;

	g_util_running = 1;
	if (cfg.stat_interval != 0) {
		if ((ret = pthread_create(
		    &stat, NULL, stat_worker, &cfg)) != 0) {
			lprintf(&cfg, ret, 0,
			    "Error creating statistics thread.");
			goto err;
		}
		stat_created = 1;
	}
	if (cfg.checkpoint_interval != 0) {
		if ((ret = pthread_create(
		    &checkpoint, NULL, checkpoint_worker, &cfg)) != 0) {
			lprintf(&cfg, ret, 0,
			    "Error creating checkpoint thread.");
			goto err;
		}
		checkpoint_created = 1;
	}
	if (cfg.create != 0 && execute_populate(&cfg) != 0)
		goto err;
	/* If we aren't populating, set the insert count. */
	if (cfg.create == 0 && find_table_count(&cfg) != 0)
		goto err;

	if (cfg.run_time != 0 &&
	    cfg.read_threads + cfg.insert_threads + cfg.update_threads != 0 &&
	    (ret = execute_workload(&cfg)) != 0)
			goto err;

	lprintf(&cfg, 0, 1,
	    "Ran performance test example with %d read threads, %d insert"
	    " threads and %d update threads for %d seconds.",
	    cfg.read_threads, cfg.insert_threads,
	    cfg.update_threads, cfg.run_time);

	if (cfg.read_threads != 0)
		lprintf(&cfg, 0, 1,
		    "Executed %" PRIu64 " read operations", g_nread_ops);
	if (cfg.insert_threads != 0)
		lprintf(&cfg, 0, 1,
		    "Executed %" PRIu64 " insert operations", g_nins_ops);
	if (cfg.update_threads != 0)
		lprintf(&cfg, 0, 1,
		    "Executed %" PRIu64 " update operations", g_nupdate_ops);

err:	g_util_running = 0;

	if (checkpoint_created != 0 &&
	    (ret = pthread_join(checkpoint, NULL)) != 0)
		lprintf(&cfg, ret, 0, "Error joining checkpoint thread.");
	if (stat_created != 0 && (ret = pthread_join(stat, NULL)) != 0)
		lprintf(&cfg, ret, 0, "Error joining stat thread.");
	if (conn != NULL && (ret = conn->close(conn, NULL)) != 0)
		lprintf(&cfg, ret, 0,
		    "Error closing connection to %s", cfg.home);
	if (cc_buf != NULL)
		free(cc_buf);
	if (tc_buf != NULL)
		free(tc_buf);
	if (cfg.logf != NULL) {
		fflush(cfg.logf);
		fclose(cfg.logf);
	}

	return (ret);
}
Beispiel #5
0
int main(int argc, char **argv)
{
	CONFIG cfg;
	WT_CONNECTION *conn;
	const char *user_cconfig, *user_tconfig;
	const char *opts = "C:R:T:d:eh:i:k:lr:s:u:v:SML";
	char *cc_buf, *tc_buf;
	int ch, ret, stat_created;
	pthread_t stat;
	uint64_t req_len;

	/* Setup the default configuration values. */
	memcpy(&cfg, &default_cfg, sizeof(cfg));
	cc_buf = tc_buf = NULL;
	user_cconfig = user_tconfig = NULL;
	conn = NULL;
	stat_created = 0;

	/*
	 * First parse different config structures - other options override
	 * fields within the structure.
	 */
	while ((ch = getopt(argc, argv, opts)) != EOF)
		switch (ch) {
		case 'S':
			memcpy(&cfg, &small_cfg, sizeof(cfg));
			break;
		case 'M':
			memcpy(&cfg, &med_cfg, sizeof(cfg));
			break;
		case 'L':
			memcpy(&cfg, &large_cfg, sizeof(cfg));
			break;
		default:
			/* Validation is provided on the next parse. */
			break;
		}

	/* Parse other options */
	optind = 1;
	while ((ch = getopt(argc, argv, opts)) != EOF)
		switch (ch) {
		case 'd':
			cfg.data_sz = atoi(optarg);
			break;
		case 'e':
			cfg.create = 0;
			break;
		case 'h':
			cfg.home = optarg;
			break;
		case 'i':
			cfg.icount = atoi(optarg) * 1000;
			break;
		case 'k':
			cfg.key_sz = atoi(optarg);
			break;
		case 'l':
			cfg.stat_thread = 1;
			break;
		case 'r':
			cfg.read_time = atoi(optarg);
			break;
		case 's':
			cfg.rand_seed = atoi(optarg);
			break;
		case 'u':
			cfg.uri = optarg;
			break;
		case 'v':
			cfg.verbose = atoi(optarg);
			break;
		case 'C':
			user_cconfig = optarg;
			break;
		case 'R':
			cfg.read_threads = atoi(optarg);
			break;
		case 'T':
			user_tconfig = optarg;
			break;
		case 'L':
		case 'M':
		case 'S':
			break;
		case '?':
		default:
			fprintf(stderr, "Invalid option\n");
			usage();
			return (EINVAL);
		}

	if ((ret = setup_log_file(&cfg)) != 0)
		goto err;

	/* Make stdout line buffered, so verbose output appears quickly. */
	(void)setvbuf(stdout, NULL, _IOLBF, 0);

	/* Concatenate non-default configuration strings. */
	if (cfg.verbose > 1 || user_cconfig != NULL) {
		req_len = strlen(cfg.conn_config) + strlen(debug_cconfig) + 3;
		if (user_cconfig != NULL)
			req_len += strlen(user_cconfig);
		cc_buf = calloc(req_len, 1);
		if (cc_buf == NULL) {
			ret = ENOMEM;
			goto err;
		}
		snprintf(cc_buf, req_len, "%s%s%s%s%s",
		    cfg.conn_config,
		    cfg.verbose > 1 ? "," : "",
		    cfg.verbose > 1 ? debug_cconfig : "",
		    user_cconfig ? "," : "", user_cconfig ? user_cconfig : "");
		cfg.conn_config = cc_buf;
	}
	if (cfg.verbose > 1 || user_tconfig != NULL) {
		req_len = strlen(cfg.table_config) + strlen(debug_tconfig) + 3;
		if (user_tconfig != NULL)
			req_len += strlen(user_tconfig);
		tc_buf = calloc(req_len, 1);
		if (tc_buf == NULL) {
			ret = ENOMEM;
			goto err;
		}
		snprintf(tc_buf, req_len, "%s%s%s%s%s",
		    cfg.table_config,
		    cfg.verbose > 1 ? "," : "",
		    cfg.verbose > 1 ? debug_tconfig : "",
		    user_tconfig ? "," : "", user_tconfig ? user_tconfig : "");
		cfg.table_config = tc_buf;
	}

	srand(cfg.rand_seed);

	if (cfg.verbose > 1)
		print_config(&cfg);

	/* Open a connection to the database, creating it if necessary. */
	if ((ret = wiredtiger_open(
	    cfg.home, NULL, cfg.conn_config, &conn)) != 0) {
		fprintf(stderr, "Error connecting to %s: %s\n",
		    cfg.home, wiredtiger_strerror(ret));
		goto err;
	}

	cfg.conn = conn;

	if (cfg.stat_thread) {
		stat_running = 1;
		if ((ret = pthread_create(
		    &stat, NULL, stat_worker, &cfg)) != 0) {
			fprintf(stderr, "Error creating statistics thread.\n");
			goto err;
		}
		stat_created = 1;
	}
	if (cfg.create != 0 && (ret = populate(&cfg)) != 0)
		goto err;

	if (cfg.read_time != 0 && cfg.read_threads != 0)
		if ((ret = execute_reads(&cfg)) != 0)
			goto err;

	if (cfg.verbose > 0) {
		fprintf(cfg.logf,
	    "Ran performance test example with %d threads for %d seconds.\n",
		    cfg.read_threads, cfg.read_time);
		fprintf(cfg.logf,
		    "Executed %" PRIu64 " read operations\n", nops);
	}

	if (cfg.stat_thread)
		stat_running = 0;

	/* Cleanup. */
err:	if (stat_created != 0 && (ret = pthread_join(stat, NULL)) != 0)
		fprintf(stderr, "Error joining stat thread: %d.\n", ret);
	if (conn != NULL && (ret = conn->close(conn, NULL)) != 0)
		fprintf(stderr, "Error connecting to %s: %s\n",
		    cfg.home, wiredtiger_strerror(ret));
	if (cc_buf != NULL)
		free(cc_buf);
	if (tc_buf != NULL)
		free(tc_buf);
	if (cfg.logf != NULL) {
		fflush(cfg.logf);
		fclose(cfg.logf);
	}

	return (ret);
}