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