1 /* Copyright (c) 2006-2020. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/actor.h"
7 #include "simgrid/disk.h"
8 #include "simgrid/engine.h"
9 #include "simgrid/forward.h"
10 #include "simgrid/host.h"
13 #include "xbt/sysdep.h"
18 XBT_LOG_NEW_DEFAULT_CATEGORY(disk, "Messages specific for this simulation");
20 static void host(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
22 const char* host_name = sg_host_get_name(sg_host_self());
24 /* - Display information on the disks mounted by the current host */
25 XBT_INFO("*** Storage info on %s ***", host_name);
27 /* - Retrieve all disks from current host */
28 unsigned int disk_count;
30 sg_host_disks(sg_host_self(), &disk_count, &disk_list);
32 for (unsigned int i = 0; i < disk_count; i++)
33 XBT_INFO("Disk name: %s (read: %.0f B/s -- write: %.0f B/s ", sg_disk_name(disk_list[i]),
34 sg_disk_read_bandwidth(disk_list[i]), sg_disk_write_bandwidth(disk_list[i]));
36 /* - Write 400,000 bytes on Disk1 */
37 sg_disk_t disk = disk_list[0];
38 sg_size_t write = sg_disk_write(disk, 400000);
39 XBT_INFO("Wrote %llu bytes on '%s'", write, sg_disk_name(disk));
41 /* - Now read 200,000 bytes */
42 sg_size_t read = sg_disk_read(disk, 200000);
43 XBT_INFO("Read %llu bytes on '%s'", read, sg_disk_name(disk));
45 /* - Attach some user data to disk1 */
46 XBT_INFO("*** Get/set data for storage element: Disk1 ***");
48 char* data = (char*)sg_disk_data(disk);
50 XBT_INFO("Get storage data: '%s'", data ? data : "No user data");
52 sg_disk_data_set(disk, xbt_strdup("Some user data"));
53 data = (char*)sg_disk_data(disk);
54 XBT_INFO("Set and get data: '%s'", data);
59 int main(int argc, char* argv[])
61 simgrid_init(&argc, argv);
62 simgrid_load_platform(argv[1]);
64 simgrid_register_function("host", host);
66 size_t host_count = sg_host_count();
67 sg_host_t* hosts = sg_host_list();
69 for (long i = 0; i < host_count; i++) {
70 XBT_INFO("*** %s properties ****", sg_host_get_name(hosts[i]));
71 xbt_dict_t props = sg_host_get_properties(hosts[i]);
72 xbt_dict_cursor_t cursor = NULL;
75 xbt_dict_foreach (props, cursor, key, data)
76 XBT_INFO(" %s -> %s", key, (char*)data);
77 xbt_dict_free(&props);
82 sg_actor_create("", sg_host_by_name("bob"), host, 0, NULL);
86 XBT_INFO("Simulated time %g", simgrid_get_clock());