aboutsummaryrefslogtreecommitdiffstats
path: root/libibex/wordindexmem.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@HelixCode.com>2000-11-27 10:05:14 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-11-27 10:05:14 +0800
commit6c45c449cae597f00cf57d5c9914489871ba916e (patch)
tree0f4e0184070be3b08dea0ca97641f18d99add985 /libibex/wordindexmem.c
parent918ead73323ed08bc182e5827a1cab2e719f48b6 (diff)
downloadgsoc2013-evolution-6c45c449cae597f00cf57d5c9914489871ba916e.tar.gz
gsoc2013-evolution-6c45c449cae597f00cf57d5c9914489871ba916e.tar.zst
gsoc2013-evolution-6c45c449cae597f00cf57d5c9914489871ba916e.zip
If we have the namecache active, and there is no name there, we add it
2000-11-17 Not Zed <NotZed@HelixCode.com> * wordindexmem.c (add_list): If we have the namecache active, and there is no name there, we add it directly and dont look it up first. * testindex.c: Some performance testing & stat gathering stuff. svn path=/trunk/; revision=6677
Diffstat (limited to 'libibex/wordindexmem.c')
-rw-r--r--libibex/wordindexmem.c112
1 files changed, 108 insertions, 4 deletions
diff --git a/libibex/wordindexmem.c b/libibex/wordindexmem.c
index 4c0bca7cef..9d26bb3697 100644
--- a/libibex/wordindexmem.c
+++ b/libibex/wordindexmem.c
@@ -650,11 +650,16 @@ static void add_list(struct _IBEXWord *idx, const char *name, GPtrArray *words)
d(cache_sanity(idx));
/* make sure we keep the namecache in sync, if it is active */
- if (idx->nameinit && g_hash_table_lookup(idx->namecache, name) == NULL)
+ if (idx->nameinit && g_hash_table_lookup(idx->namecache, name) == NULL) {
g_hash_table_insert(idx->namecache, g_strdup(name), (void *)TRUE);
-
- /* get the nameid and block start for this name */
- add_index_key(idx->nameindex, name, &nameid, &nameblock, &nametail);
+ /* we know we dont have it in the disk hash either, so we insert anew (saves a lookup) */
+ nameid = idx->nameindex->klass->insert(idx->nameindex, name, strlen(name));
+ nameblock = 0;
+ nametail = 0;
+ } else {
+ /* get the nameid and block start for this name */
+ add_index_key(idx->nameindex, name, &nameid, &nameblock, &nametail);
+ }
d(cache_sanity(idx));
@@ -778,3 +783,102 @@ static int word_close(struct _IBEXWord *idx)
return 0;
}
+
+/* debugging/tuning function */
+
+struct _stats {
+ int memcache; /* total memory used by cache entries */
+ int memfile; /* total mem ysed by file data */
+ int memfileused; /* actual memory used by file data */
+ int memword; /* total mem used by words */
+ int file1; /* total file entries with only 1 entry */
+ int total;
+};
+
+static void
+get_info(void *key, void *value, void *data)
+{
+ struct _wordcache *cache = (struct _wordcache *)value;
+ struct _stats *stats = (struct _stats *)data;
+
+ /* round up to probable alignment, + malloc overheads */
+ stats->memcache += ((sizeof(struct _wordcache) + strlen(cache->word) + 4 + 3) & ~3);
+ if (cache->filealloc > 0) {
+ /* size of file array data */
+ stats->memcache += sizeof(nameid_t) * cache->filealloc + 4;
+ /* actual used memory */
+ stats->memfile += sizeof(nameid_t) * cache->filealloc;
+ stats->memfileused += sizeof(nameid_t) * cache->filecount;
+ }
+ if (cache->filecount == 1 && cache->filealloc == 0)
+ stats->file1++;
+
+ stats->memword += strlen(cache->word);
+ stats->total++;
+}
+
+static char *
+num(int num)
+{
+ int n;
+ char buf[256], *p = buf;
+ char type = 0;
+
+ n = num;
+ if (n>1000000) {
+ p+= sprintf(p, "%d ", n/1000000);
+ n -= (n/1000000)*1000000;
+ type = 'M';
+ }
+ if (n>1000) {
+ if (num>1000000)
+ p+= sprintf(p, "%03d ", n/1000);
+ else
+ p+= sprintf(p, "%d ", n/1000);
+ n -= (n/1000)*1000;
+ if (type == 0)
+ type = 'K';
+ }
+ if (num > 1000)
+ p += sprintf(p, "%03d", n);
+ else
+ p += sprintf(p, "%d", n);
+
+ n = num;
+ switch (type) {
+ case 'M':
+ p += sprintf(p, ", %d.%02dM", n/1024/1024, n*100/1024/1024);
+ break;
+ case 'K':
+ p += sprintf(p, ", %d.%02dK", n/1024, n*100/1024);
+ break;
+ case 0:
+ break;
+ }
+
+ return buf;
+}
+
+void word_index_mem_dump_info(struct _IBEXWord *idx);
+
+void word_index_mem_dump_info(struct _IBEXWord *idx)
+{
+ struct _stats stats = { 0 };
+ int useful;
+
+ g_hash_table_foreach(idx->wordcache, get_info, &stats);
+
+ useful = stats.total * sizeof(struct _wordcache) + stats.memword + stats.memfile;
+
+ printf("Word Index Stats:\n");
+ printf("Total word count: %d\n", stats.total);
+ printf("Total memory used: %s\n", num(stats.memcache));
+ printf("Total useful memory: %s\n", num(useful));
+ printf("Total malloc/alignment overhead: %s\n", num(stats.memcache - useful));
+ printf("Total buffer overhead: %s\n", num(stats.memfile - stats.memfileused));
+ printf("Space taken by words: %s\n", num(stats.memword + stats.total));
+ printf("Number of 1-word entries: %s\n", num(stats.file1));
+ if (stats.memcache > 0)
+ printf("%% unused space: %d %%\n", (stats.memfile - stats.memfileused) * 100 / stats.memcache);
+}
+
* | Update yarn lockBrandon Millman2018-08-311-25/+4 * | Token registry from old 0x versionBrandon Millman2018-08-311-2/+60 * | Initial changes for v2 portalBrandon Millman2018-08-311-89/+22 |/ * Merge branch 'development' of https://github.com/0xProject/0x-monorepo into w...fragosti2018-08-301-60/+1 |\ | * feat: Add support for TypeScript project references (#991)Alex Browne2018-08-301-60/+1 * | Change VersionDropDown to use material-ui 3fragosti2018-08-291-3/+208 * | Upgrade version of react-shared in websitefragosti2018-08-291-37/+1 * | Upgrade react-copy-to-clipboardfragosti2018-08-291-16/+7 * | Remove react-tap-event-plugin from react-sharedfragosti2018-08-291-10/+4 * | Upgrade material ui in react-docsfragosti2018-08-291-60/+7 * | Update lockfilefragosti2018-08-291-3/+3 * | Update material-ui in react-sharedfragosti2018-08-291-1/+37 * | Upgrade material ui to 0.20.0fragosti2018-08-291-2/+62 * | Bump react-highlight in react-shared once morefragosti2018-08-251-5/+5 * | Upgrade react-shared used by website to one that depends on react 16fragosti2018-08-251-154/+9 * | Upgrade react-highlight to version that depends on React 16fragosti2018-08-251-0/+9 * | Update react and remove tap event plugin [deprecated]fragosti2018-08-251-32/+36 * | Merge branch 'development' of https://github.com/0xProject/0x-monorepo into w...fragosti2018-08-251-3195/+3458 |\| | * Merge pull request #997 from 0xProject/feature/forwarder-helper/initBrandon Millman2018-08-241-2/+72 | |\ | | * Remove legacy docs stuffBrandon Millman2018-08-241-5/+56 | | * Merge branch 'development' into feature/forwarder-helper/initBrandon Millman2018-08-241-191/+226 | | |\ | | * | Update yarn lockBrandon Millman2018-08-241-0/+4 | | * | Merge branch 'development' into feature/forwarder-helper/initBrandon Millman2018-08-241-13/+170 | | |\ \ | | * | | Add assertions to factoryBrandon Millman2018-08-231-37/+29 | | * | | Update yarn lockBrandon Millman2018-08-231-1/+16 | | * | | Add ForwarderHelperImplConfigBrandon Millman2018-08-231-0/+4 | | * | | Remove marketSell and add to marketBuy implementationBrandon Millman2018-08-231-3/+3 | | * | | Flesh out typesBrandon Millman2018-08-231-3/+3 * | | | | Add new react and typesfragosti2018-08-251-3382/+3202 |/ / / / * | | / Update uglify plugin to support es6Brandon Millman2018-08-241-0/+13 | |_|/ |/| | * | | Merge pull request #924 from 0xProject/wrap-typedocFabio Berger2018-08-241-225/+256 |\ \ \ | |_|/ |/| | | * | Upgrade Typedoc to 0.12.0, which works with TS 3.xFabio Berger2018-08-231-46/+46 | * | update yarn.lockFabio Berger2018-08-231-3/+7 | * | merge developmentFabio Berger2018-08-231-1/+15 | |\ \ | * | | Replace complicated camelCase to spaces logic with change-case packageFabio Berger2018-08-231-3/+137 | * | | Fix many linter errors that showed up upon upgrading tsutilFabio Berger2018-08-231-24/+14 | * | | Fix remaining merge issuesFabio Berger2018-08-221-37/+29 | * | | Merge development branchFabio Berger2018-08-221-23/+23 | |\ \ \ | | | |/ | | |/| | * | | Update yarn.lockFabio Berger2018-08-171-3/+2 | * | | Merge developmentFabio Berger2018-08-171-28/+14 | |\ \ \ | * | | | Export Web3ProviderEngine directly instead of indirectly via subprovidersFabio Berger2018-08-161-30/+38 | * | | | Merge in new 0x.js interfaceFabio Berger2018-08-151-3/+3 | |\ \ \ \ | | * | | | Refactor 0x.js to simply re-export it's own sub-dependencies rather then wrap...Fabio Berger2018-08-141-4/+4 | * | | | | Fix additional merge conflictsFabio Berger2018-08-151-11/+93 | * | | | | Merge developmentFabio Berger2018-08-151-38/+782 | |\| | | | | * | | | | Update yarn.lockFabio Berger2018-08-141-7/+0 | * | | | | Update yarn.lockFabio Berger2018-08-061-144/+13 | * | | | | Use our fork of react-scroll that fixes scrolling within an absolutely positi...Fabio Berger2018-08-021-6/+6