Пример #1
0
int
xfind (const char *basedir)
{
        struct xwork xwork;
        int          ret = 0;
        char         *cwd = NULL;

        ret = chdir (basedir);
        if (ret) {
                err ("%s: %s\n", basedir, strerror (errno));
                return ret;
        }

        cwd = getcwd (0, 0);
        if (!cwd) {
                err ("getcwd(): %s\n", strerror (errno));
                return -1;
        }

        tdbg ("Working directory: %s\n", cwd);
        free (cwd);

        memset (&xwork, 0, sizeof (xwork));

        ret = xwork_init (&xwork, workers);
        if (ret == 0)
                xworker_crawl (&xwork);

        ret = xwork_fini (&xwork, ret);
        stats_dump ();

        return ret;
}
static void cmd_stats_dump(int argc, char *argv[])
{
	const char *path, *cmd;
	int c;

	path = t_strconcat(doveadm_settings->base_dir, "/stats", NULL);

	while ((c = getopt(argc, argv, "s:")) > 0) {
		switch (c) {
		case 's':
			path = optarg;
			break;
		default:
			help(&doveadm_cmd_stats_dump);
		}
	}
	argv += optind - 1;
	if (argv[1] == NULL)
		help(&doveadm_cmd_stats_dump);
	cmd = t_strdup_printf("EXPORT\t%s\n",
			      t_strarray_join((const void *)(argv+1), "\t"));

	doveadm_print_init(DOVEADM_PRINT_TYPE_TAB);
	stats_dump(path, cmd);
}
Пример #3
0
static void
doveadm_cmd_stats_dump(struct doveadm_cmd_context* cctx)
{
	const char *path, *cmd;
	const char *args[3] = {0};

	if (!doveadm_cmd_param_str(cctx, "socket-path", &path))
		path = t_strconcat(doveadm_settings->base_dir, "/stats", NULL);

	if (!doveadm_cmd_param_str(cctx, "type", &args[0])) {
		i_error("Missing type parameter");
		doveadm_exit_code = EX_USAGE;
		return;
	}

	/* purely optional */
	if (!doveadm_cmd_param_str(cctx, "filter", &args[1]))
		args[1] = NULL;

	cmd = t_strdup_printf("EXPORT\t%s\n", t_strarray_join(args, "\t"));

	doveadm_print_init(DOVEADM_PRINT_TYPE_TAB);
	stats_dump(path, cmd);
	return;
}
Пример #4
0
int main(int argc, char *argv[]) {
		
	struct trie *t = NULL;
	char keybuf[1024], databuf[1024];
	size_t i;

	tr_compar = charcmp;

	t = malloc(sizeof(struct trie));
	if (!t)
		err(1, "malloc");

	memset(t, 0, sizeof(struct trie));

	stats_init();
	while (fgets(keybuf, 1023, stdin)) {

		keybuf[strlen(keybuf)-1] = '\0'; /* FIXME \r\n */
		
		snprintf(databuf, 1023, "%s is the data as well", keybuf);
	
		stats_depth_0();
		int ret = tr_insert(t, keybuf, strdup(databuf));
		if (ret != 0)
			err(1, "tr_insert");
	}

	stats_dump();

	for (i = 1; i < (size_t)argc; i++) {
		tr_search(t, argv[i]);
	}

	printf("<?xml version='1.0' standalone='no'?>\n"
                "<svg:svg width='100%%' height='100%%' version='1.1' xmlns:svg='http://www.w3.org/2000/svg'>\n");

	t->tr_key='*';
	tr_print(t, 0.0, canvas_width, 512.0, 32.0);
	printf("</svg:svg>\n");

	tr_destroy(t);
	stats_fini();

	return (0);
}
Пример #5
0
static bool handle_free_tx_slot_fn(void)
{
    void *op;

    if (e10k_queue_get_txbuf(q, &op) != 0) {
        return false;
    }

    DEBUG("handle_free_tx_slot_fn: Packet %p done\n", op);

    stats_dump();

#if TRACE_ETHERSRV_MODE
        trace_event(TRACE_SUBSYS_NNET, TRACE_EVENT_NNET_DRVTXDONE, 0);
#endif // TRACE_ETHERSRV_MODE

    handle_tx_done(op);

    return true;
}
Пример #6
0
DEFINEFN
PyObject* psyco_stats_dump(void)
{
	PyObject* d = PyDict_New();
	int i = 0;
	PyObject *key, *value;
	if (d == NULL)
		return NULL;
	
	while (PyDict_Next(codestats_dict, &i, &key, &value)) {
		PyCodeStats* cs = (PyCodeStats*) key;
		PyObject* o = PyFloat_FromDouble(cs->st_charge);
		extra_assert(PyCStruct_Check(key));
		extra_assert(PyCode_Check(cs->cs_key));
		if (o == NULL || PyDict_SetItem(d, cs->cs_key, o)) {
			Py_DECREF(d);
			return NULL;
		}
	}
	stats_dump();
	return d;
}
Пример #7
0
u08 cmd_parse(u08 len, const char *cmd)
{
  u08 status;
  
  switch(cmd[0]) {
    // ----- v) version -----
    case 'v':
      uart_send_string("plip2slip " VERSION);
      uart_send_crlf();
      return SER_PARSE_CMD_OK;
    
    // ----- x) exit -----
    case 'x':
      return SER_PARSE_CMD_EXIT;
    
    // ----- s) stats -----
    case 's':
      if(len==1) {
        // show stats
        stats_dump();
        return SER_PARSE_CMD_OK;
      } else {
        switch(cmd[1]) {
          case 'r': // stats reset
            stats_reset();
            return SER_PARSE_CMD_OK;        
          default:
            return SER_PARSE_CMD_UNKNOWN;
        }
      }
    
    // ----- b) bench -----
    case 'b':
      bench_dump();
      return SER_PARSE_CMD_OK;
    
    // ----- p) param -----
    case 'p':
      if(len==1) {
        // show params
        param_dump();
        return SER_PARSE_CMD_OK;
      } else {
        switch(cmd[1]) {
          case 's': // param save
            status = param_save();
            return (status == PARAM_OK) ? SER_PARSE_CMD_OK : SER_PARSE_CMD_FAIL;
          case 'l': // param load
            status = param_load();
            return (status == PARAM_OK) ? SER_PARSE_CMD_OK : SER_PARSE_CMD_FAIL;
          case 'r': // param reset
            param_reset();
            return SER_PARSE_CMD_OK;
          default:
            return SER_PARSE_CMD_UNKNOWN;
        }
      }
      return SER_PARSE_CMD_UNKNOWN;
    
    // ----- m) mode -----
    case 'm':
      if(len==2) {
        u08 value;
        status = parse_nybble(cmd[1],&value);
        if(!status || (value >= PARAM_MODE_TOTAL_NUMBER)) {
          return SER_PARSE_CMD_FAIL;
        }
        param.mode = value;
        return SER_PARSE_CMD_OK;
      }
      return SER_PARSE_CMD_UNKNOWN;
    
    // ----- f) fake_tx -----
    case 'f':
      if(len==2) {
        u08 value;
        status = parse_nybble(cmd[1],&value);
        if(!status) {
          return SER_PARSE_CMD_FAIL;
        }
        param.fake_tx = value ? 1 : 0;
        return SER_PARSE_CMD_OK;
      }
      return SER_PARSE_CMD_UNKNOWN;
    
    // ----- l) log -----
    case 'l':
      if(len==1) {
        // show log
        log_dump();
        return SER_PARSE_CMD_OK;
      } else {
        switch(cmd[1]) {
          case 'r': // reset log
            log_init();
            return SER_PARSE_CMD_OK;
          default:
            return SER_PARSE_CMD_UNKNOWN;
        }
      }
      return SER_PARSE_CMD_UNKNOWN;
    
    // ----- e) error sim -----
    case 'e':
      if(len==2) {
        u08 value;
        status = parse_nybble(cmd[1],&value);
        if(!status) {
          return SER_PARSE_CMD_FAIL;
        }
        for(u08 i=0;i<value;i++) {
          error_add();
        }
        return SER_PARSE_CMD_OK;
      } else {
        error_add();
      }
      return SER_PARSE_CMD_OK;
    
    // unknown command
    default:
      return SER_PARSE_CMD_UNKNOWN;
  }
}
Пример #8
0
int init(const platform_env_t* env)
{
    paused = 0;

    LOGI("Environment:\n  Platform: %d\n  Assets: %s\n  Shared: %s\n  Config: %s\n  Tmp: %s\n",
         env->platform,
         env->assets_dir,
         env->shared_dir,
         env->config_dir,
         env->tmp_dir);

    io_driver_t* assets = NULL;
    io_driver_t* config = NULL;
    io_driver_t* tmp = NULL;
    io_driver_t* shared = NULL;
    if (io_init(&io) != 0 ||
#ifdef ANDROID
            io_driver_apk_init(&assets, env->platform_specific) != 0 ||
#else
            io_driver_fs_init(&assets, env->assets_dir) != 0 ||
#endif
            io_driver_fs_init(&config, env->config_dir) != 0 ||
            io_driver_fs_init(&shared, env->shared_dir) != 0 ||
            io_driver_fs_init(&tmp, env->tmp_dir) != 0 ||
            io_bind(io, "/config", config) ||
            io_bind(io, "/tmp", tmp) ||
            io_bind(io, "/shared", shared) ||
            io_bind(io, "/assets", assets)
       )
    {
        LOGE("Error initializing I/O system");
        return -1;
    }
    io_set_working_dir(io, "/assets");
    io_set_default(io);

    if (gfx_init(&gfx) != 0)
    {
        LOGE("Error initializing GFX system");
        return -1;
    }

    font_info_t info =
    {
        .name = "fonts/default.ttf",
        .face_index = 0,
        .width = 0,
        .height = 14 * 64,
        .dpi_x = 0,
        .dpi_y = 72,
    };
    if (font_init(&font, &info, NULL) != 0)
    {
        LOGE("Error loading font");
        return -1;
    }

    info.height = 22 * 64;
    if (font_init(&big_font, &info, NULL) != 0)
    {
        LOGE("Error loading font");
        return -1;
    }

    if (atlases_load(&atlases, "atlases.dat") != 0)
    {
        LOGE("Error loading atlases metadata");
        return -1;
    }

    if (sprites_load(&sprites, "sprites.dat") != 0)
    {
        LOGE("Error loading sprites metadata");
        return -1;
    }

    stats_load(&global_stats, "/config/player.dat");

    if (am_init(&am, achievements_get_all(), achievements_get_count(), achievement_progress, achievement_unlocked))
    {
        LOGE("Unable to initialize achievements manager");
        return -1;
    }
    achievements_context.am = am;
    am_load(am, "/config/achievements.dat");

    timestamp_set(&timer);
    timestamp_set(&fps_timer);

    push_screen(SCREEN_MAIN_MENU);

    return 0;
}

void shutdown()
{
    LOGI("shutdown");
    atlases_free(atlases);
    sprites_free(sprites);
    font_free(font);
    font_free(big_font);
    gfx_free(gfx);

    stats_dump(&global_stats);
    stats_save(&global_stats, "/config/player.dat");
    stats_free(&global_stats);

    if (am != NULL)
    {
        am_save(am, "/config/achievements.dat");
        am_dump(am);
        am_free(am);
        am = NULL;
    }

    io_free(io);
    io = NULL;

    atlases = NULL;
    sprites = NULL;
    font = NULL;
    big_font = NULL;
    gfx = NULL;
}