expr visit(expr const & e) { switch (e.kind()) { case expr_kind::Sort: case expr_kind::Constant: case expr_kind::Var: case expr_kind::Meta: case expr_kind::Local: return e; default: break; } check_system("unfold macros"); auto it = m_cache.find(e); if (it != m_cache.end()) return it->second; switch (e.kind()) { case expr_kind::Sort: case expr_kind::Constant: case expr_kind::Var: case expr_kind::Meta: case expr_kind::Local: lean_unreachable(); case expr_kind::Macro: return save_result(e, visit_macro(e)); case expr_kind::App: return save_result(e, visit_app(e)); case expr_kind::Lambda: case expr_kind::Pi: return save_result(e, visit_binding(e)); } lean_unreachable(); }
void aggr_source_discovery::dump_cache(base_stream &out, const cache &c) const { time_t now = time(0); for (cache::const_iterator i = c.begin(); i != c.end(); ++i) { out.xprintf("(%{Addr}, %{Addr}) for %{duration}\n", i->first.second, i->first.first, time_duration((now - i->second) * 1000)); } }
void deserialize(Deserializer& source, cache<Key, Value, Policy>& c) { uint64_t size, capacity; source >> capacity >> size; c.capacity(capacity); Key k; Value v; for (uint64_t i = 0; i < size; ++i) { source >> k >> v; c.insert(std::move(k), std::move(v)); } }
void signals(int param) { switch(param) { case SIGUSR1: c.refresh(getNowPlaying); break; case SIGUSR2: c.refresh(getUpdates); break; default: cerr << "catched unhandled signal: " << param << endl; } }
void visit(expr * n, unsigned delta, bool & visited) { expr_delta_pair e(n, delta); if (!m_cache.contains(e)) { m_todo.push_back(e); visited = false; } }
int main(){ string fileName; cin >> fileName; Cache.simulate(fileName); cout << "L3 Misses Per Kilo Instructions: " << (Cache.L3->missCount*1000)/(Cache.L1->insCount*1.0) << endl; }
// return true if n contains a variable in the range [begin, end] bool operator()(expr * n, unsigned begin = 0, unsigned end = UINT_MAX) { m_contains = false; m_window = end - begin; m_todo.reset(); m_cache.reset(); m_todo.push_back(expr_delta_pair(n, begin)); while (!m_todo.empty()) { expr_delta_pair e = m_todo.back(); if (visit_children(e.m_node, e.m_delta)) { m_cache.insert(e); m_todo.pop_back(); } if (m_contains) { return true; } } SASSERT(!m_contains); return false; }
void aggr_source_discovery::run_gc(cache &c) { time_t now = time(0); cache::iterator i = c.begin(); while (i != c.end()) { cache::iterator j = i; ++i; if ((now - j->second) > m_keepalive) { if (g_mrd->should_log(INTERNAL_FLOW)) { g_mrd->log().xprintf("AggrSourceDiscovery " "cleaned source (%{Addr}, %{Addr}).\n", j->first.second, j->first.first); } c.erase(j); } } }
/*! * \brief Swaps contents of two caches * * Exchanges the content of the cache with the content of mp, which is another cache object containing elements of the same type and using the same expiration policy. * Sizes may differ. Maximum number of entries may differ too. * * \param <mp> Another cache of the same type as this whose cache is swapped with that of this cache. * * \throw <exception_invalid_policy> Thrown when the policies of the caches to swap are incompatible. * * \see cache::operator= */ void swap ( cache<Key,Data,Policy,Compare,Allocator>& mp ) { write_lock_type l = lock.lockWrite(); _storage.swap(mp._storage); _policy->swap(*mp._policy); std::size_t m=this->_maxEntries; this->_maxEntries=mp._maxEntries; mp._maxEntries=m; this->_currEntries=this->_size(); mp._currEntries=mp.size(); }
int aggr_source_discovery::add_to_cache(cache &c, int ifindex, const inet6_addr &group, const inet6_addr &src) { sg_pair p(group, src); cache::iterator i = c.find(p); time_t now = time(0); if (i == c.end()) { c.insert(std::make_pair(p, now)); if (g_mrd->should_log(INTERNAL_FLOW)) { g_mrd->log().xprintf("AggrSourceDiscovery added source" " (%{Addr}, %{Addr}) to cache.\n", src, group); } return 1; } else { if ((now - i->second) > m_keepalive) { if (g_mrd->should_log(INTERNAL_FLOW)) { g_mrd->log().xprintf("AggrSourceDiscovery " "updated source (%{Addr}," "%{Addr}), cache was old.\n", src, group); } /* was in the cache but is old */ source_discovery_origin::discovered_source(ifindex, group, src); return 0; } i->second = now; } return -1; }
expr save_result(expr const & e, expr && r) { m_cache.insert(std::make_pair(e, r)); return r; }
void serialize(Serializer& sink, cache<Key, Value, Policy> const& c) { sink << static_cast<uint64_t>(c.capacity()); sink << static_cast<uint64_t>(c.size()); for (auto entry : c) sink << entry.first << entry.second; }
int main() { if (!(dpy = XOpenDisplay(NULL))) { cerr << "dwmstatus: cannot open display." << endl; return 1; } signal(SIGUSR1, signals); signal(SIGUSR2, signals); c.add(getLoad, 31); c.add(getNowPlaying, 17); c.add(getUpdates, 60*60); c.add(getBattery, 97); c.add(getMem, 23); c.add(getCpuTemp, 5); c.add(getCpu, 2); c.add(getTime, 1); string bat; while (true) { bat = c.get(getBattery); setStatus(c.get(getLoad) + " [" + c.get(getNowPlaying) + "] " + c.get(getUpdates) + " " + (!bat.empty() ? bat + " " : "") + c.get(getMem) + " " + c.get(getCpuTemp) + " " + c.get(getCpu) + " " + c.get(getTime)); sleep(INTERVAL); } setStatus("dwm"); XCloseDisplay(dpy); return 0; }