void Device::DropCaches() { // give advice to disable caching int ret = posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED); if(ret) ReportWarning(); // empty caches QFile caches("/proc/sys/vm/drop_caches"); caches.open(QIODevice::WriteOnly); if(caches.isOpen()) { caches.putChar('3'); caches.close(); } else { ReportWarning(); } }
std::string cache_manager::stat_json() const { rapidjson::Document doc; doc.SetObject(); auto &allocator = doc.GetAllocator(); rapidjson::Value total_cache(rapidjson::kObjectType); rapidjson::Value size_stats(rapidjson::kObjectType); get_total_caches_size_stats_json(size_stats, allocator); total_cache.AddMember("size_stats", size_stats, allocator); doc.AddMember("total_cache", total_cache, allocator); rapidjson::Value caches(rapidjson::kObjectType); get_caches_size_stats_json(caches, allocator); doc.AddMember("caches", caches, allocator); rapidjson::StringBuffer buffer; rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); doc.Accept(writer); return buffer.GetString(); }