1 /* Copyright (c) 2008-2010, 2012-2015. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid/msg.h"
12 #define FILENAME1 "/sd1/doc/simgrid/examples/cxx/autoDestination/Main.cxx"
14 int host(int argc, char *argv[]);
15 void storage_info(msg_host_t host);
16 void display_storage_properties(msg_storage_t storage);
17 void dump_storage_by_name(char *name);
18 void display_storage_content(msg_storage_t storage);
20 XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation");
24 void storage_info(msg_host_t host)
26 const char* host_name = MSG_host_get_name(host);
27 XBT_INFO("*** Storage info on %s ***", host_name);
29 xbt_dict_cursor_t cursor = NULL;
32 msg_storage_t storage;
34 xbt_dict_t storage_list = MSG_host_get_mounted_storage_list(host);
36 xbt_dict_foreach(storage_list,cursor,mount_name,storage_name)
38 XBT_INFO("\tStorage name: %s, mount name: %s", storage_name, mount_name);
40 storage = MSG_storage_get_by_name(storage_name);
42 sg_size_t free_size = MSG_storage_get_free_size(storage);
43 sg_size_t used_size = MSG_storage_get_used_size(storage);
45 XBT_INFO("\t\tFree size: %llu bytes", free_size);
46 XBT_INFO("\t\tUsed size: %llu bytes", used_size);
48 display_storage_properties(storage);
49 dump_storage_by_name(storage_name);
51 xbt_dict_free(&storage_list);
54 void display_storage_properties(msg_storage_t storage){
55 xbt_dict_cursor_t cursor = NULL;
57 xbt_dict_t props = MSG_storage_get_properties(storage);
58 if (xbt_dict_length(props) > 0){
59 XBT_INFO("\tProperties of mounted storage: %s", MSG_storage_get_name(storage));
60 xbt_dict_foreach(props, cursor, key, data)
61 XBT_INFO("\t\t'%s' -> '%s'", key, data);
63 XBT_INFO("\tNo property attached.");
67 void dump_storage_by_name(char *name){
68 XBT_INFO("*** Dump a storage element ***");
69 msg_storage_t storage = MSG_storage_get_by_name(name);
72 display_storage_content(storage);
75 XBT_INFO("Unable to retrieve storage element by its name: %s.", name);
79 void display_storage_content(msg_storage_t storage){
80 XBT_INFO("Print the content of the storage element: %s",MSG_storage_get_name(storage));
81 xbt_dict_cursor_t cursor = NULL;
84 xbt_dict_t content = MSG_storage_get_content(storage);
86 xbt_dict_foreach(content, cursor, file, psize)
87 XBT_INFO("\t%s size: %llu bytes", file, *psize);
89 XBT_INFO("\tNo content.");
91 xbt_dict_free(&content);
98 int host(int argc, char *argv[])
101 sprintf(name,"%s%i", FILENAME1,MSG_process_self_PID());
102 msg_file_t file = MSG_file_open(name, NULL);
103 //MSG_file_read(file, MSG_file_get_size(file));
104 MSG_file_write(file, 500000);
106 XBT_INFO("Size of %s: %llu", MSG_file_get_name(file), MSG_file_get_size(file));
107 MSG_file_close(file);
113 int main(int argc, char **argv)
117 MSG_init(&argc, argv);
118 MSG_create_environment(argv[1]);
120 MSG_function_register("host", host);
121 storage_info(MSG_host_by_name(xbt_strdup("host")));
122 for(i = 0 ; i<10; i++){
123 MSG_process_create(xbt_strdup("host"), host, NULL, MSG_host_by_name(xbt_strdup("host")));
130 storage_info(MSG_host_by_name(xbt_strdup("host")));
131 XBT_INFO("Simulation time %g", MSG_get_clock());