summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/store.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2011-09-26 16:54:02 +0200
committerAdam Borowski <kilobyte@angband.pl>2011-09-26 18:17:00 +0200
commitebb05b803bc54bb21248b2be42e1f7accda1f595 (patch)
treea9f967b80040b646da8fb507e0337a87f6c5887e /crawl-ref/source/store.cc
parent3f757922d4e306a4eb56f5348d29fd5e0c8a166d (diff)
downloadcrawl-ref-ebb05b803bc54bb21248b2be42e1f7accda1f595.tar.gz
crawl-ref-ebb05b803bc54bb21248b2be42e1f7accda1f595.zip
A way to see which props slow us down the most.
Diffstat (limited to 'crawl-ref/source/store.cc')
-rw-r--r--crawl-ref/source/store.cc41
1 files changed, 41 insertions, 0 deletions
diff --git a/crawl-ref/source/store.cc b/crawl-ref/source/store.cc
index f2368db4f9..57bea81688 100644
--- a/crawl-ref/source/store.cc
+++ b/crawl-ref/source/store.cc
@@ -1340,6 +1340,13 @@ void CrawlHashTable::read(reader &th)
}
+#ifdef DEBUG_PROPS
+static std::map<std::string, int> accesses;
+# define ACCESS(x) ++accesses[x]
+#else
+# define ACCESS(x)
+#endif
+
//////////////////
// Misc functions
@@ -1348,6 +1355,7 @@ bool CrawlHashTable::exists(const std::string &key) const
if (hash_map == NULL)
return (false);
+ ACCESS(key);
assert_validity();
hash_map_type::const_iterator i = hash_map->find(key);
@@ -1427,6 +1435,7 @@ CrawlStoreValue& CrawlHashTable::get_value(const std::string &key)
assert_validity();
init_hash_map();
+ ACCESS(key);
iterator i = hash_map->find(key);
if (i == hash_map->end())
@@ -1448,6 +1457,7 @@ const CrawlStoreValue& CrawlHashTable::get_value(const std::string &key) const
#endif
assert_validity();
+ ACCESS(key);
hash_map_type::const_iterator i = hash_map->find(key);
#ifdef ASSERTS
@@ -1494,6 +1504,7 @@ void CrawlHashTable::erase(const std::string key)
assert_validity();
init_hash_map();
+ ACCESS(key);
iterator i = hash_map->find(key);
if (i != hash_map->end())
@@ -1936,3 +1947,33 @@ CrawlVector::const_iterator CrawlVector::end() const
assert_validity();
return vec.end();
}
+
+
+#ifdef DEBUG_PROPS
+static bool _cmp(std::string a, std::string b)
+{
+ return accesses[a] > accesses[b];
+}
+
+void dump_prop_accesses()
+{
+ FILE *f = fopen("prop_accesses", "w");
+ ASSERT(f);
+
+ std::vector<std::string> props;
+
+ for (std::map<std::string, int>::const_iterator i = accesses.begin();
+ i != accesses.end(); ++i)
+ {
+ props.push_back(i->first);
+ }
+
+ std::sort(props.begin(), props.end(), _cmp);
+ for (std::vector<std::string>::const_iterator i = props.begin();
+ i != props.end(); ++i)
+ {
+ fprintf(f, "%10d %s\n", accesses[*i], i->c_str());
+ }
+ fclose(f);
+}
+#endif