1 /* Copyright (c) 2008-2010, 2012-2014. The SimGrid Team.
10 #define FILENAME1 "/sd1/doc/simgrid/examples/cxx/autoDestination/Main.cxx"
12 int host(int argc, char *argv[]);
13 void storage_info(msg_host_t host);
14 void display_storage_properties(msg_storage_t storage);
15 void dump_storage_by_name(char *name);
16 void display_storage_content(msg_storage_t storage);
18 XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation");
22 void storage_info(msg_host_t host)
24 const char* host_name = MSG_host_get_name(host);
25 XBT_INFO("*** Storage info on %s ***", host_name);
27 xbt_dict_cursor_t cursor = NULL;
30 msg_storage_t storage;
32 xbt_dict_t storage_list = MSG_host_get_mounted_storage_list(host);
34 xbt_dict_foreach(storage_list,cursor,mount_name,storage_name)
36 XBT_INFO("\tStorage name: %s, mount name: %s", storage_name, mount_name);
38 storage = MSG_storage_get_by_name(storage_name);
40 sg_size_t free_size = MSG_storage_get_free_size(storage);
41 sg_size_t used_size = MSG_storage_get_used_size(storage);
43 XBT_INFO("\t\tFree size: %llu bytes", free_size);
44 XBT_INFO("\t\tUsed size: %llu bytes", used_size);
46 display_storage_properties(storage);
47 dump_storage_by_name(storage_name);
49 xbt_dict_free(&storage_list);
52 void display_storage_properties(msg_storage_t storage){
53 xbt_dict_cursor_t cursor = NULL;
55 xbt_dict_t props = MSG_storage_get_properties(storage);
56 if (xbt_dict_length(props) > 0){
57 XBT_INFO("\tProperties of mounted storage: %s", MSG_storage_get_name(storage));
58 xbt_dict_foreach(props, cursor, key, data)
59 XBT_INFO("\t\t'%s' -> '%s'", key, data);
61 XBT_INFO("\tNo property attached.");
65 void dump_storage_by_name(char *name){
66 XBT_INFO("*** Dump a storage element ***");
67 msg_storage_t storage = MSG_storage_get_by_name(name);
70 display_storage_content(storage);
73 XBT_INFO("Unable to retrieve storage element by its name: %s.", name);
77 void display_storage_content(msg_storage_t storage){
78 XBT_INFO("Print the content of the storage element: %s",MSG_storage_get_name(storage));
79 xbt_dict_cursor_t cursor = NULL;
82 xbt_dict_t content = MSG_storage_get_content(storage);
84 xbt_dict_foreach(content, cursor, file, psize)
85 XBT_INFO("\t%s size: %llu bytes", file, *psize);
87 XBT_INFO("\tNo content.");
89 xbt_dict_free(&content);
96 int host(int argc, char *argv[])
99 sprintf(name,"%s%i", FILENAME1,MSG_process_self_PID());
100 msg_file_t file = MSG_file_open(name, NULL);
101 //MSG_file_read(file, MSG_file_get_size(file));
102 MSG_file_write(file, 500000);
104 XBT_INFO("Size of %s: %llu", MSG_file_get_name(file), MSG_file_get_size(file));
105 MSG_file_close(file);
111 int main(int argc, char **argv)
115 MSG_init(&argc, argv);
116 MSG_create_environment(argv[1]);
118 MSG_function_register("host", host);
119 storage_info(MSG_get_host_by_name(xbt_strdup("host")));
120 for(i = 0 ; i<10; i++){
121 MSG_process_create(xbt_strdup("host"), host, NULL, MSG_get_host_by_name(xbt_strdup("host")));
128 storage_info(MSG_get_host_by_name(xbt_strdup("host")));
129 XBT_INFO("Simulation time %g", MSG_get_clock());