Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Constify pointer and reference local variables in examples/.
[simgrid.git] / examples / s4u / io-disk-raw / s4u-io-disk-raw.cpp
1 /* Copyright (c) 2017-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "simgrid/s4u.hpp"
7 #include <string>
8 #include <unordered_map>
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(disk, "Messages specific for this simulation");
11
12 static void host()
13 {
14   /* - Display information on the disks mounted by the current host */
15   XBT_INFO("*** Storage info on %s ***", simgrid::s4u::Host::current()->get_cname());
16
17   /* - Retrieve all disks from current host */
18   std::vector<simgrid::s4u::Disk*> const& disk_list = simgrid::s4u::Host::current()->get_disks();
19
20   /* - For each disk mounted on host, display disk name and mount point */
21   for (auto disk : disk_list)
22     XBT_INFO("Disk name: %s (read: %.0f B/s -- write: %.0f B/s ", disk->get_cname(), disk->get_read_bandwidth(),
23              disk->get_write_bandwidth());
24
25   /* - Write 400,000 bytes on Disk1 */
26   simgrid::s4u::Disk* disk = disk_list.front();
27   sg_size_t write          = disk->write(400000);
28   XBT_INFO("Wrote %llu bytes on '%s'", write, disk->get_cname());
29
30   /*  - Now read 200,000 bytes */
31   sg_size_t read = disk->read(200000);
32   XBT_INFO("Read %llu bytes on '%s'", read, disk->get_cname());
33
34   /* - Attach some user data to disk1 */
35   XBT_INFO("*** Get/set data for storage element: Disk1 ***");
36
37   const std::string* data = static_cast<std::string*>(disk->get_data());
38
39   XBT_INFO("Get storage data: '%s'", data ? data->c_str() : "No user data");
40
41   disk->set_data(new std::string("Some user data"));
42   data = static_cast<std::string*>(disk->get_data());
43   XBT_INFO("Set and get data: '%s'", data->c_str());
44   delete data;
45 }
46
47 int main(int argc, char** argv)
48 {
49   simgrid::s4u::Engine e(&argc, argv);
50   e.load_platform(argv[1]);
51
52   /* - Display Host properties */
53   for (auto h : e.get_all_hosts()) {
54     XBT_INFO("*** %s properties ****", h->get_cname());
55     for (auto kv : *h->get_properties())
56       XBT_INFO("  %s -> %s", kv.first.c_str(), kv.second.c_str());
57   }
58
59   simgrid::s4u::Actor::create("", simgrid::s4u::Host::by_name("bob"), host);
60
61   e.run();
62   XBT_INFO("Simulated time: %g", simgrid::s4u::Engine::get_clock());
63
64   return 0;
65 }