[prev in list] [next in list] [prev in thread] [next in thread]
List: oprofile-commits
Subject: [oprof-cvs] CVS: oprofile/libdb odb.h,NONE,1.1 Makefile.am,1.10,1.11 db_debug.c,1.8,1.9 db_insert.c,
From: John Levon <movement () users ! sourceforge ! net>
Date: 2004-05-29 16:29:46
Message-ID: E1BU6iQ-0007XG-Nh () sc8-pr-cvs1 ! sourceforge ! net
[Download RAW message or body]
Update of /cvsroot/oprofile/oprofile/libdb
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28599/libdb
Modified Files:
Makefile.am db_debug.c db_insert.c db_manage.c db_stat.c
db_travel.c
Added Files:
odb.h
Removed Files:
odb_hash.h
Log Message:
some trivial renamings
--- NEW FILE: odb.h ---
/**
* @file odb.h
* This file contains various definitions and interface for management
* of in-memory, through mmaped file, growable hash table, that stores
* sample files.
*
* @remark Copyright 2002 OProfile authors
* @remark Read the file COPYING
*
* @author Philippe Elie
*/
#ifndef ODB_HASH_H
#define ODB_HASH_H
#include <stddef.h>
#include <stdint.h>
#include "op_list.h"
/** the type of key. 64-bit because CG needs 32-bit pair {from,to} */
typedef uint64_t odb_key_t;
/** the type of an information in the database */
typedef unsigned int odb_value_t;
/** the type of index (node number), list are implemented through index */
typedef unsigned int odb_index_t;
/** the type store node number */
typedef odb_index_t odb_node_nr_t;
/** store the hash mask, hash table size are always power of two */
typedef odb_index_t odb_hash_mask_t;
/* there is (bucket factor * nr node) entry in hash table, this can seem
* excessive but hash coding eip don't give a good distributions and our
* goal is to get a O(1) amortized insert time. bucket factor must be a
* power of two. FIXME: see big comment in odb_hash_add_node, you must
* re-enable zeroing hash table if BUCKET_FACTOR > 2 (roughly exact, you
* want to read the comment in odb_hash_add_node() if you tune this define)
*/
#define BUCKET_FACTOR 1
/** a db hash node */
typedef struct {
odb_key_t key; /**< eip */
odb_value_t value; /**< samples count */
odb_index_t next; /**< next entry for this bucket */
} odb_node_t;
/** the minimal information which must be stored in the file to reload
* properly the data base, following this header is the node array then
* the hash table (when growing we avoid to copy node array)
*/
typedef struct {
odb_node_nr_t size; /**< in node nr (power of two) */
odb_node_nr_t current_size; /**< nr used node + 1, node 0 unused */
int padding[6]; /**< for padding and future use */
} odb_descr_t;
/** a "database". this is an in memory only description.
*
* We allow to manage a database inside a mapped file with an "header" of
* unknown size so odb_open get a parameter to specify the size of this header.
* A typical use is:
*
* struct header { int etc; ... };
* odb_open(&hash, filename, ODB_RW, sizeof(header));
* so on this library have no dependency on the header type.
*
* the internal memory layout from base_memory is:
* the unknown header (sizeof_header)
* odb_descr_t
* the node array: (descr->size * sizeof(odb_node_t) entries
* the hash table: array of odb_index_t indexing the node array
* (descr->size * BUCKET_FACTOR) entries
*/
typedef struct odb_data {
odb_node_t * node_base; /**< base memory area of the page */
odb_index_t * hash_base; /**< base memory of hash table */
odb_descr_t * descr; /**< the current state of database */
odb_hash_mask_t hash_mask; /**< == descr->size - 1 */
unsigned int sizeof_header; /**< from base_memory to odb header */
unsigned int offset_node; /**< from base_memory to node array */
void * base_memory; /**< base memory of the maped memory */
int fd; /**< mmaped memory file descriptor */
char * filename; /**< full path name of sample file */
int ref_count; /**< reference count */
struct list_head list; /**< hash bucket list */
} odb_data_t;
typedef struct {
odb_data_t * data;
} odb_t;
#ifdef __cplusplus
extern "C" {
#endif
/* db_manage.c */
/** how to open the DB file */
enum odb_rw {
ODB_RDONLY = 0, /**< open for read only */
ODB_RDWR = 1 /**< open for read and/or write */
};
/**
* odb_init - initialize a DB file
* @param odb the DB file to init
*/
void odb_init(odb_t * odb);
/**
* odb_open - open a DB file
* @param odb the data base object to setup
* @param filename the filename where go the maped memory
* @param rw \enum ODB_RW if opening for writing, else \enum ODB_RDONLY
* @param sizeof_header size of the file header if any
*
* The sizeof_header parameter allows the data file to have a header
* at the start of the file which is skipped.
* odb_open() always preallocate a few number of pages.
* returns 0 on success, errno on failure
*/
int odb_open(odb_t * odb, char const * filename,
enum odb_rw rw, size_t sizeof_header);
/** Close the given ODB file */
void odb_close(odb_t * odb);
/** return the number of times this sample file is open */
int odb_open_count(odb_t const * odb);
/** return the start of the mapped data */
void * odb_get_data(odb_t * odb);
/** issue a msync on the used size of the mmaped file */
void odb_sync(odb_t const * odb);
/** add a page returning its index. Take care all page pointer can be
* invalidated by this call !
* returns the index of the created node on success or
* ODB_NODE_NR_INVALID on failure, in this case this function do nothing
* and errno is set by the first libc call failure allowing to retry after
* cleanup some program resource.
*/
odb_node_nr_t odb_hash_add_node(odb_t * odb);
/** "immpossible" node number to indicate an error from odb_hash_add_node() */
#define ODB_NODE_NR_INVALID ((odb_node_nr_t)-1)
/* db_debug.c */
/** check that the hash is well built */
int odb_check_hash(odb_t const * odb);
/* db_stat.c */
typedef struct odb_hash_stat_t odb_hash_stat_t;
odb_hash_stat_t * odb_hash_stat(odb_t const * odb);
void odb_hash_display_stat(odb_hash_stat_t const * stats);
void odb_hash_free_stat(odb_hash_stat_t * stats);
/* db_insert.c */
/** insert info at key, if key already exist the info is added to the
* existing samples
* returns EXIT_SUCCESS on success, EXIT_FAILURE on failure
*/
int odb_insert(odb_t * odb, odb_key_t key, odb_value_t value);
/* db_travel.c */
/**
* return a base pointer to the node array and number of node in this array
* caller then will iterate through:
*
* odb_node_nr_t node_nr, pos;
* odb_node_t * node = odb_get_iterator(odb, &node_nr);
* for ( pos = 0 ; pos < node_nr ; ++pos) {
* if (node[pos].key) {
* // do something
* }
* }
*
* note than caller *must* filter nil key.
*/
odb_node_t * odb_get_iterator(odb_t const * odb, odb_node_nr_t * nr);
static __inline unsigned int
odb_do_hash(odb_data_t const * data, odb_key_t value)
{
/* FIXME: better hash for eip value, needs to instrument code
* and do a lot of tests ... */
/* trying to combine high order bits his a no-op: inside a binary image
* high order bits don't vary a lot, hash table start with 7 bits mask
* so this hash coding use bits 0-7, 8-15. Hash table is stored in
* files avoiding to rebuilding them at profiling re-start so
* on changing do_hash() change the file format!
*/
uint32_t temp = (value >> 32) ^ value;
return ((temp << 0) ^ (temp >> 8)) & data->hash_mask;
}
#ifdef __cplusplus
}
#endif
#endif /* !ODB_H */
Index: Makefile.am
===================================================================
RCS file: /cvsroot/oprofile/oprofile/libdb/Makefile.am,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -p -d -r1.10 -r1.11
--- Makefile.am 26 Sep 2003 02:16:22 -0000 1.10
+++ Makefile.am 29 May 2004 16:29:41 -0000 1.11
@@ -14,5 +14,5 @@ libodb_a_SOURCES = \
db_travel.c \
db_debug.c \
db_stat.c \
- odb_hash.h
+ odb.h
Index: db_debug.c
===================================================================
RCS file: /cvsroot/oprofile/oprofile/libdb/db_debug.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -p -d -r1.8 -r1.9
--- db_debug.c 28 May 2004 17:21:40 -0000 1.8
+++ db_debug.c 29 May 2004 16:29:41 -0000 1.9
@@ -1,6 +1,6 @@
/**
* @file db_debug.c
- * Debug routines for libdb-hash
+ * Debug routines for libdb
*
* @remark Copyright 2002 OProfile authors
* @remark Read the file COPYING
@@ -12,7 +12,7 @@
#include <stdlib.h>
#include <string.h>
-#include "odb_hash.h"
+#include "odb.h"
static int check_circular_list(odb_data_t const * data)
{
@@ -86,14 +86,14 @@ static int check_redundant_key(odb_data_
return 0;
}
-int odb_check_hash(samples_odb_t const * hash)
+int odb_check_hash(odb_t const * odb)
{
odb_node_nr_t pos;
odb_node_nr_t nr_node = 0;
odb_node_nr_t nr_node_out_of_bound = 0;
int ret = 0;
odb_key_t max = 0;
- odb_data_t * data = hash->data;
+ odb_data_t * data = odb->data;
for (pos = 0 ; pos < data->descr->size * BUCKET_FACTOR ; ++pos) {
odb_index_t index = data->hash_base[pos];
Index: db_insert.c
===================================================================
RCS file: /cvsroot/oprofile/oprofile/libdb/db_insert.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -p -d -r1.12 -r1.13
--- db_insert.c 28 May 2004 17:21:40 -0000 1.12
+++ db_insert.c 29 May 2004 16:29:41 -0000 1.13
@@ -1,6 +1,6 @@
/**
* @file db_insert.c
- * Inserting a key-value pair into a DB hash
+ * Inserting a key-value pair into a DB
*
* @remark Copyright 2002 OProfile authors
* @remark Read the file COPYING
@@ -15,16 +15,16 @@
#include <string.h>
#include <errno.h>
-#include "odb_hash.h"
+#include "odb.h"
-int odb_insert(samples_odb_t * hash, odb_key_t key, odb_value_t value)
+int odb_insert(odb_t * odb, odb_key_t key, odb_value_t value)
{
odb_index_t index;
odb_index_t new_node;
odb_node_t * node;
odb_data_t * data;
- data = hash->data;
+ data = odb->data;
index = data->hash_base[odb_do_hash(data, key)];
while (index) {
if (index <= 0 || index >= data->descr->current_size) {
@@ -48,7 +48,7 @@ int odb_insert(samples_odb_t * hash, odb
* the node_base array, odb_hash_add_node() increase current_size but
* odb_travel just ignore node with a zero key so on setting the key
* atomically update the node */
- new_node = odb_hash_add_node(hash);
+ new_node = odb_hash_add_node(odb);
if (new_node == ODB_NODE_NR_INVALID) {
return EINVAL;
}
Index: db_manage.c
===================================================================
RCS file: /cvsroot/oprofile/oprofile/libdb/db_manage.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -p -d -r1.16 -r1.17
--- db_manage.c 28 May 2004 18:51:47 -0000 1.16
+++ db_manage.c 29 May 2004 16:29:41 -0000 1.17
@@ -1,6 +1,6 @@
/**
* @file db_manage.c
- * Management of a DB hash
+ * Management of a DB file
*
* @remark Copyright 2002 OProfile authors
* @remark Read the file COPYING
@@ -20,7 +20,7 @@
#include <string.h>
#include <stdio.h>
-#include "odb_hash.h"
+#include "odb.h"
#include "op_string.h"
#include "op_libiberty.h"
@@ -60,9 +60,9 @@ static unsigned int tables_size(odb_data
}
-odb_index_t odb_hash_add_node(samples_odb_t * hash)
+odb_index_t odb_hash_add_node(odb_t * odb)
{
- odb_data_t * data = hash->data;
+ odb_data_t * data = odb->data;
if (data->descr->current_size >= data->descr->size) {
unsigned int old_file_size;
@@ -121,9 +121,10 @@ odb_index_t odb_hash_add_node(samples_od
return (odb_index_t)data->descr->current_size++;
}
-void odb_init(samples_odb_t * hash)
+
+void odb_init(odb_t * odb)
{
- hash->data = NULL;
+ odb->data = NULL;
}
@@ -163,20 +164,20 @@ find_samples_data(size_t hash, char cons
}
-int odb_open(samples_odb_t * hash, char const * filename, enum odb_rw rw,
+int odb_open(odb_t * odb, char const * filename, enum odb_rw rw,
size_t sizeof_header)
{
struct stat stat_buf;
odb_node_nr_t nr_node;
odb_data_t *data;
- size_t hash_code;
+ size_t hash;
int err = 0;
int flags = (rw == ODB_RDWR) ? (O_CREAT | O_RDWR) : O_RDONLY;
int mmflags = (rw == ODB_RDWR) ? (PROT_READ | PROT_WRITE) : PROT_READ;
- hash_code = op_hash_string(filename) % FILES_HASH_SIZE;
- data = find_samples_data(hash_code, filename);
+ hash = op_hash_string(filename) % FILES_HASH_SIZE;
+ data = find_samples_data(hash, filename);
if (data) {
data->ref_count++;
return 0;
@@ -248,8 +249,8 @@ int odb_open(samples_odb_t * hash, char
data->node_base = odb_to_node_base(data);
data->hash_mask = (data->descr->size * BUCKET_FACTOR) - 1;
- list_add(&data->list, &files_hash[hash_code]);
- hash->data = data;
+ list_add(&data->list, &files_hash[hash]);
+ odb->data = data;
out:
return err;
fail_unmap:
@@ -258,14 +259,14 @@ fail:
close(data->fd);
free(data->filename);
free(data);
- hash->data = NULL;
+ odb->data = NULL;
goto out;
}
-void odb_close(samples_odb_t * hash)
+void odb_close(odb_t * odb)
{
- odb_data_t * data = hash->data;
+ odb_data_t * data = odb->data;
if (data) {
data->ref_count--;
@@ -277,29 +278,29 @@ void odb_close(samples_odb_t * hash)
close(data->fd);
free(data->filename);
free(data);
- hash->data = NULL;
+ odb->data = NULL;
}
}
}
-int odb_open_count(samples_odb_t const * hash)
+int odb_open_count(odb_t const * odb)
{
- if (!hash->data)
+ if (!odb->data)
return 0;
- return hash->data->ref_count;
+ return odb->data->ref_count;
}
-void * odb_get_data(samples_odb_t * hash)
+void * odb_get_data(odb_t * odb)
{
- return hash->data->base_memory;
+ return odb->data->base_memory;
}
-void odb_sync(samples_odb_t const * hash)
+void odb_sync(odb_t const * odb)
{
- odb_data_t * data = hash->data;
+ odb_data_t * data = odb->data;
size_t size;
if (!data)
Index: db_stat.c
===================================================================
RCS file: /cvsroot/oprofile/oprofile/libdb/db_stat.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -p -d -r1.7 -r1.8
--- db_stat.c 28 May 2004 17:21:40 -0000 1.7
+++ db_stat.c 29 May 2004 16:29:41 -0000 1.8
@@ -1,6 +1,6 @@
/**
* @file db_stat.c
- * Statistics routines for libdb-hash
+ * Statistics routines for libdb
*
* @remark Copyright 2002 OProfile authors
* @remark Read the file COPYING
@@ -11,9 +11,9 @@
#include <stdlib.h>
#include <stdio.h>
-#include "odb_hash.h"
+#include "odb.h"
-/// hold various statistics data for a db hash file
+/// hold various statistics data for a db file
struct odb_hash_stat_t {
odb_node_nr_t node_nr; /**< allocated node number */
odb_node_nr_t used_node_nr; /**< in use node number */
@@ -24,13 +24,13 @@ struct odb_hash_stat_t {
/* do we need variance ? */
};
-odb_hash_stat_t * odb_hash_stat(samples_odb_t const * hash)
+odb_hash_stat_t * odb_hash_stat(odb_t const * odb)
{
size_t max_length = 0;
double total_length = 0.0;
size_t nr_non_empty_list = 0;
size_t pos;
- odb_data_t * data = hash->data;
+ odb_data_t * data = odb->data;
odb_hash_stat_t * result = calloc(1, sizeof(odb_hash_stat_t));
if (!result) {
Index: db_travel.c
===================================================================
RCS file: /cvsroot/oprofile/oprofile/libdb/db_travel.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -p -d -r1.5 -r1.6
--- db_travel.c 28 May 2004 17:21:40 -0000 1.5
+++ db_travel.c 29 May 2004 16:29:41 -0000 1.6
@@ -1,6 +1,6 @@
/**
* @file db_travel.c
- * Inspection of a DB tree
+ * Inspection of a DB
*
* @remark Copyright 2002 OProfile authors
* @remark Read the file COPYING
@@ -8,11 +8,11 @@
* @author Philippe Elie
*/
-#include "odb_hash.h"
+#include "odb.h"
-odb_node_t * odb_get_iterator(samples_odb_t const * hash, odb_node_nr_t * nr)
+odb_node_t * odb_get_iterator(odb_t const * odb, odb_node_nr_t * nr)
{
/* node zero is unused */
- *nr = hash->data->descr->current_size - 1;
- return hash->data->node_base + 1;
+ *nr = odb->data->descr->current_size - 1;
+ return odb->data->node_base + 1;
}
--- odb_hash.h DELETED ---
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
_______________________________________________
Oprofile-commits mailing list
Oprofile-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oprofile-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic