Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'mc'
[simgrid.git] / teshsuite / msg / storage / concurrent_rw.c
1 /* Copyright (c) 2008-2010, 2012-2014. The SimGrid Team.
2  * All rights reserved.
3 */
4
5 #include "msg/msg.h"
6 #include "xbt/log.h"
7 #include <unistd.h>
8
9
10 #define FILENAME1 "/sd1/doc/simgrid/examples/cxx/autoDestination/Main.cxx"
11
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);
17
18 XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation");
19
20
21
22 void storage_info(msg_host_t host)
23 {
24   const char* host_name = MSG_host_get_name(host);
25   XBT_INFO("*** Storage info on %s ***", host_name);
26
27   xbt_dict_cursor_t cursor = NULL;
28   char* mount_name;
29   char* storage_name;
30   msg_storage_t storage;
31
32   xbt_dict_t storage_list = MSG_host_get_mounted_storage_list(host);
33
34   xbt_dict_foreach(storage_list,cursor,mount_name,storage_name)
35   {
36     XBT_INFO("\tStorage name: %s, mount name: %s", storage_name, mount_name);
37
38     storage = MSG_storage_get_by_name(storage_name);
39
40     sg_size_t free_size = MSG_storage_get_free_size(storage);
41     sg_size_t used_size = MSG_storage_get_used_size(storage);
42
43     XBT_INFO("\t\tFree size: %llu bytes", free_size);
44     XBT_INFO("\t\tUsed size: %llu bytes", used_size);
45
46     display_storage_properties(storage);
47     dump_storage_by_name(storage_name);
48   }
49   xbt_dict_free(&storage_list);
50 }
51
52 void display_storage_properties(msg_storage_t storage){
53   xbt_dict_cursor_t cursor = NULL;
54   char *key, *data;
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);
60   }else{
61         XBT_INFO("\tNo property attached.");
62   }
63 }
64
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);
68
69   if(storage){
70     display_storage_content(storage);
71   }
72   else{
73     XBT_INFO("Unable to retrieve storage element by its name: %s.", name);
74   }
75 }
76
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;
80   char *file;
81   sg_size_t *psize;
82   xbt_dict_t content = MSG_storage_get_content(storage);
83   if (content){
84     xbt_dict_foreach(content, cursor, file, psize)
85     XBT_INFO("\t%s size: %llu bytes", file, *psize);
86   } else {
87     XBT_INFO("\tNo content.");
88   }
89   xbt_dict_free(&content);
90 }
91
92
93
94
95
96 int host(int argc, char *argv[])
97 {
98         char name[2048];
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);
103
104         XBT_INFO("Size of %s: %llu", MSG_file_get_name(file), MSG_file_get_size(file));
105         MSG_file_close(file);
106
107         return 1;
108 }
109
110
111 int main(int argc, char **argv)
112 {
113
114   int res, i;
115   MSG_init(&argc, argv);
116   MSG_create_environment(argv[1]);
117
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")));
122   }
123
124
125
126
127   res = MSG_main();
128   storage_info(MSG_get_host_by_name(xbt_strdup("host")));
129   XBT_INFO("Simulation time %g", MSG_get_clock());
130
131   if (res == MSG_OK)
132     return 0;
133   else
134     return 1;
135
136 }