Ejemplo n.º 1
0
int console_open(lua_State *L) {
  sg_platf_init();
  sg_platf_begin();

  storage_register_callbacks();

  return 0;
}
Ejemplo n.º 2
0
/* This function acts as a main in the parsing area. */
void parse_platform_file(const char *file)
{
#if HAVE_LUA
  int is_lua = (file != NULL && strlen(file) > 3 && file[strlen(file)-3] == 'l' && file[strlen(file)-2] == 'u'
        && file[strlen(file)-1] == 'a');
#endif

  sg_platf_init();

#if HAVE_LUA
  /* Check if file extension is "lua". If so, we will use
   * the lua bindings to parse the platform file (since it is
   * written in lua). If not, we will use the (old?) XML parser
   */
  if (is_lua) {
    lua_State* L = luaL_newstate();
    luaL_openlibs(L);

    luaL_loadfile(L, file); // This loads the file without executing it.

    /* Run the script */
    if (lua_pcall(L, 0, 0, 0)) {
        XBT_ERROR("FATAL ERROR:\n  %s: %s\n\n", "Lua call failed. Errormessage:", lua_tostring(L, -1));
        xbt_die("Lua call failed. See Log");
    }
  }
  else
#endif
  { // Use XML parser

    int parse_status;

    /* init the flex parser */
    surfxml_buffer_stack_stack_ptr = 1;
    surfxml_buffer_stack_stack[0] = 0;
    after_config_done = 0;
    surf_parse_open(file);

    traces_set_list = xbt_dict_new_homogeneous(NULL);
    trace_connect_list_host_avail = xbt_dict_new_homogeneous(free);
    trace_connect_list_host_speed = xbt_dict_new_homogeneous(free);
    trace_connect_list_link_avail = xbt_dict_new_homogeneous(free);
    trace_connect_list_link_bw = xbt_dict_new_homogeneous(free);
    trace_connect_list_link_lat = xbt_dict_new_homogeneous(free);

    /* Init my data */
    if (!surfxml_bufferstack_stack)
      surfxml_bufferstack_stack = xbt_dynar_new(sizeof(char *), NULL);

    /* Do the actual parsing */
    parse_status = surf_parse();

    /* connect all traces relative to hosts */
    xbt_dict_cursor_t cursor = NULL;
    char *trace_name, *elm;

    xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) {
      tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
      xbt_assert(trace, "Trace %s undefined", trace_name);

      simgrid::s4u::Host *host = sg_host_by_name(elm);
      xbt_assert(host, "Host %s undefined", elm);
      simgrid::surf::Cpu *cpu = host->pimpl_cpu;

      cpu->setStateTrace(trace);
    }
    xbt_dict_foreach(trace_connect_list_host_speed, cursor, trace_name, elm) {
      tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name);
      xbt_assert(trace, "Trace %s undefined", trace_name);

      simgrid::s4u::Host *host = sg_host_by_name(elm);
      xbt_assert(host, "Host %s undefined", elm);
      simgrid::surf::Cpu *cpu = host->pimpl_cpu;

      cpu->setSpeedTrace(trace);
    }
Ejemplo n.º 3
0
void surf_parse_init_callbacks(void)
{
    sg_platf_init();
}