CodeObjectBinary Class Reference#
Rocprofiler SDK Developer API 0.5.0
ROCm Profiling API and tools
|
rocprofiler::sdk::codeobj::disassembly::CodeObjectBinary Class Reference
#include "rocprofiler-sdk/cxx/codeobj/disassembly.hpp"

Public Member Functions | |
CodeObjectBinary (std::string _uri) | |
Data Fields | |
std::string | m_uri |
std::vector< char > | buffer |
Detailed Description
Definition at line 79 of file disassembly.hpp.
Constructor & Destructor Documentation
◆ CodeObjectBinary()
|
inline |
Definition at line 82 of file disassembly.hpp.
83 : m_uri(std::move(_uri))
84 {
85 const std::string protocol_delim{"://"};
86
88 std::string protocol = m_uri.substr(0, protocol_end);
89 protocol_end += protocol_delim.length();
90
91 std::transform(protocol.begin(), protocol.end(), protocol.begin(), [](unsigned char c) {
92 return std::tolower(c);
93 });
94
95 std::string path;
97 if(path_end != std::string::npos)
98 {
99 path = m_uri.substr(protocol_end, path_end++ - protocol_end);
100 }
101 else
102 {
103 path = m_uri.substr(protocol_end);
104 }
105
106 /* %-decode the string. */
107 std::string decoded_path;
108 decoded_path.reserve(path.length());
109 for(size_t i = 0; i < path.length(); ++i)
110 {
111 if(path[i] == '%' && std::isxdigit(path[i + 1]) != 0 && std::isxdigit(path[i + 2]) != 0)
112 {
113 decoded_path += std::stoi(path.substr(i + 1, 2), nullptr, 16);
114 i += 2;
115 }
116 else
117 {
118 decoded_path += path[i];
119 }
120 }
121
122 /* Tokenize the query/fragment. */
123 std::vector<std::string> tokens;
124 size_t pos, last = path_end;
126 {
127 tokens.emplace_back(m_uri.substr(last, pos - last));
128 last = pos + 1;
129 }
130 if(last != std::string::npos)
131 {
132 tokens.emplace_back(m_uri.substr(last));
133 }
134
135 /* Create a tag-value map from the tokenized query/fragment. */
136 std::unordered_map<std::string, std::string> params;
137 std::for_each(tokens.begin(), tokens.end(), [&](std::string& token) {
138 size_t delim = token.find('=');
139 if(delim != std::string::npos)
140 {
141 params.emplace(token.substr(0, delim), token.substr(delim + 1));
142 }
143 });
144
145 buffer = std::vector<char>{};
146 size_t offset = 0;
147 size_t size = 0;
148
149 if(auto offset_it = params.find("offset"); offset_it != params.end())
150 {
151 offset = std::stoul(offset_it->second, nullptr, 0);
152 }
153
154 if(auto size_it = params.find("size"); size_it != params.end())
155 {
156 if((size = std::stoul(size_it->second, nullptr, 0)) == 0) return;
157 }
158
159 if(protocol == "memory") throw std::runtime_error(protocol + " protocol not supported!");
160
161 std::ifstream file(decoded_path, std::ios::in | std::ios::binary);
162 if(!file || !file.is_open()) throw std::runtime_error("could not open " + decoded_path);
163
164 if(size == 0)
165 {
166 file.ignore(std::numeric_limits<std::streamsize>::max());
167 size_t bytes = file.gcount();
168 file.clear();
169
170 if(bytes < offset) throw std::runtime_error("invalid uri " + decoded_path);
171
172 size = bytes - offset;
173 }
174
175 file.seekg(offset, std::ios_base::beg);
176 buffer.resize(size);
177 file.read(buffer.data(), size);
178 }
std::vector< char > buffer
Definition disassembly.hpp:181
std::string m_uri
Definition disassembly.hpp:180
References m_uri.
Field Documentation
◆ buffer
std::vector<char> rocprofiler::sdk::codeobj::disassembly::CodeObjectBinary::buffer |
Definition at line 181 of file disassembly.hpp.
◆ m_uri
std::string rocprofiler::sdk::codeobj::disassembly::CodeObjectBinary::m_uri |
Definition at line 180 of file disassembly.hpp.
Referenced by CodeObjectBinary().
The documentation for this class was generated from the following file:
- rocprofiler-sdk/cxx/codeobj/disassembly.hpp
Generated by