-
Notifications
You must be signed in to change notification settings - Fork 35
/
dwarf_cache.cc
42 lines (35 loc) · 888 Bytes
/
dwarf_cache.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// vim: expandtab:ts=4:sw=4
#include "libpstack/dwarf.h"
#include "libpstack/global.h"
namespace pstack::Dwarf {
Info::sptr
ImageCache::getDwarf(const std::string &filename)
{
return getDwarf(getImageForName(filename));
}
Info::sptr
ImageCache::getDwarf(Elf::Object::sptr object)
{
auto it = dwarfCache.find(object);
dwarfLookups++;
if (it != dwarfCache.end()) {
dwarfHits++;
return it->second;
}
auto dwarf = std::make_shared<Info>(object, *this);
dwarfCache[object] = dwarf;
return dwarf;
}
ImageCache::ImageCache() : dwarfHits(0), dwarfLookups(0) { }
ImageCache::~ImageCache() noexcept {
if (verbose >= 2)
*debug << "DWARF image cache: lookups: " << dwarfLookups << ", hits="
<< dwarfHits << "\n";
}
void
ImageCache::flush(Elf::Object::sptr o)
{
Elf::ImageCache::flush(o);
dwarfCache.erase(o);
}
}