Metall v0.30
A persistent memory allocator for data-centric analytics
 
Loading...
Searching...
No Matches
datastore_ls.hpp
Go to the documentation of this file.
1// Copyright 2020 Lawrence Livermore National Security, LLC and other Metall
2// Project Developers. See the top-level COPYRIGHT file for details.
3//
4// SPDX-License-Identifier: (Apache-2.0 OR MIT)
5
6#ifndef METALL_UTILITY_DATASTORE_LS_HPP
7#define METALL_UTILITY_DATASTORE_LS_HPP
8
9#include <iostream>
10#include <cstdlib>
11#include <string>
12#include <vector>
13#include <iomanip>
14#include <numeric>
15
16#include <metall/metall.hpp>
17
18namespace metall::utility {
19
20#ifndef DOXYGEN_SKIP
21namespace datastore_ls_detail {
22inline void aligned_show(const std::vector<std::vector<std::string>> &buf) {
23 if (buf.empty()) return;
24
25 // Calculate each column size
26 std::vector<std::size_t> col_size(buf.front().size(), 0);
27 for (const auto &row : buf) {
28 assert(col_size.size() == row.size());
29 for (std::size_t c = 0; c < row.size(); ++c) {
30 col_size[c] = std::max(row[c].size(), col_size[c]);
31 }
32 }
33
34 // Show column title
35 {
36 std::cout << "|";
37 for (std::size_t c = 0; c < col_size.size(); ++c) {
38 std::cout << std::setw(col_size[c] + 2) << buf[0][c] << " |";
39 }
40 std::cout << std::endl;
41
42 // Show horizontal rule
43 for (std::size_t c = 0; c < col_size.size(); ++c) {
44 for (std::size_t i = 0; i < col_size[c] + 4; ++i) {
45 std::cout << "-";
46 }
47 }
48 std::cout << std::endl;
49 }
50
51 // Show items
52 for (std::size_t l = 1; l < buf.size(); ++l) {
53 const auto &row = buf[l];
54
55 std::cout << "|";
56 for (std::size_t c = 0; c < col_size.size(); ++c) {
57 std::cout << std::setw(col_size[c] + 2) << std::right << row[c] << " |";
58 }
59 std::cout << std::endl;
60 }
61}
62} // namespace datastore_ls_detail
63#endif // DOXYGEN_SKIP
64
65inline void ls_named_object(const std::string &datastore_path) {
66 std::cout << "[Named Object]" << std::endl;
67 auto accessor =
68 metall::manager::access_named_object_attribute(datastore_path.c_str());
69 if (!accessor.good()) {
70 std::cerr << "Failed to open datastore" << std::endl;
71 std::abort();
72 }
73
74 std::vector<std::vector<std::string>> buf;
75 buf.emplace_back(std::vector<std::string>{"Name", "Length", "Offset",
76 "Type-ID", "Description"});
77 for (const auto &object : accessor) {
78 std::vector<std::string> row;
79 row.push_back(object.name());
80 row.push_back(std::to_string(object.length()));
81 row.push_back(std::to_string(object.offset()));
82 row.push_back(std::to_string(object.type_id()));
83 row.push_back(object.description());
84 buf.emplace_back(std::move(row));
85 }
86 datastore_ls_detail::aligned_show(buf);
87}
88
89inline void ls_unique_object(const std::string &datastore_path) {
90 std::cout << "[Unique Object]" << std::endl;
91 auto accessor =
92 metall::manager::access_unique_object_attribute(datastore_path.c_str());
93 if (!accessor.good()) {
94 std::cerr << "Failed to open datastore" << std::endl;
95 std::abort();
96 }
97
98 std::vector<std::vector<std::string>> buf;
99 buf.emplace_back(std::vector<std::string>{
100 "Name: typeid(T).name()", "Length", "Offset", "Type-ID", "Description"});
101 for (const auto &object : accessor) {
102 std::vector<std::string> row;
103 row.push_back(object.name());
104 row.push_back(std::to_string(object.length()));
105 row.push_back(std::to_string(object.offset()));
106 row.push_back(std::to_string(object.type_id()));
107 row.push_back(object.description());
108 buf.emplace_back(std::move(row));
109 }
110 datastore_ls_detail::aligned_show(buf);
111}
112
113inline void ls_anonymous_object(const std::string &datastore_path) {
114 std::cout << "[Anonymous Object]" << std::endl;
115 auto accessor = metall::manager::access_anonymous_object_attribute(
116 datastore_path.c_str());
117 if (!accessor.good()) {
118 std::cerr << "Failed to open datastore" << std::endl;
119 std::abort();
120 }
121
122 std::vector<std::vector<std::string>> buf;
123 buf.emplace_back(
124 std::vector<std::string>{"Length", "Offset", "Type-ID", "Description"});
125 for (const auto &object : accessor) {
126 std::vector<std::string> row;
127 row.push_back(std::to_string(object.length()));
128 row.push_back(std::to_string(object.offset()));
129 row.push_back(std::to_string(object.type_id()));
130 row.push_back(object.description());
131 buf.emplace_back(std::move(row));
132 }
133 datastore_ls_detail::aligned_show(buf);
134}
135
136} // namespace metall::utility
137
138#endif // METALL_UTILITY_DATASTORE_LS_HPP
Namespace for utility items.
void ls_anonymous_object(const std::string &datastore_path)
Definition datastore_ls.hpp:113
void ls_unique_object(const std::string &datastore_path)
Definition datastore_ls.hpp:89
void ls_named_object(const std::string &datastore_path)
Definition datastore_ls.hpp:65