| 145 | } |
| 146 | |
| 147 | Maybe<ProfilerCache::Result> ProfilerCache::get(const Key& key) { |
| 148 | auto raw_buf = m_impl->get(key.category(), key.blob()); |
| 149 | if (!raw_buf.valid()) |
| 150 | return None; |
| 151 | // data type of cost is float |
| 152 | auto buf = static_cast<const uint8_t*>(raw_buf->ptr); |
| 153 | auto size = raw_buf->size; |
| 154 | mgb_assert( |
| 155 | buf && size == sizeof(float), |
| 156 | "ProfileCache invalid value: ptr=%p, size=%zu", buf, size); |
| 157 | auto read_f32 = [&]() { |
| 158 | auto ret = *reinterpret_cast<const float*>(buf); |
| 159 | return ret; |
| 160 | }; |
| 161 | auto cost = read_f32(); |
| 162 | return cost; |
| 163 | } |
| 164 | |
| 165 | void ProfilerCache::put(const Key& key, Result& result) { |
| 166 | std::string val; |