odb.h File Reference

#include <stddef.h>
#include <stdint.h>
#include "op_list.h"
Include dependency graph for odb.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  odb_node_t
struct  odb_descr_t
struct  odb_data
struct  odb_t

Defines

#define BUCKET_FACTOR   1
#define ODB_NODE_NR_INVALID   ((odb_node_nr_t)-1)

Typedefs

typedef uint64_t odb_key_t
typedef unsigned int odb_value_t
typedef unsigned int odb_index_t
typedef odb_index_t odb_node_nr_t
typedef odb_index_t odb_hash_mask_t
typedef struct odb_data odb_data_t
typedef struct odb_hash_stat_t odb_hash_stat_t

Enumerations

enum  odb_rw { ODB_RDONLY = 0, ODB_RDWR = 1 }

Functions

void odb_init (odb_t *odb)
int odb_open (odb_t *odb, char const *filename, enum odb_rw rw, size_t sizeof_header)
void odb_close (odb_t *odb)
int odb_open_count (odb_t const *odb)
void * odb_get_data (odb_t *odb)
void odb_sync (odb_t const *odb)
int odb_grow_hashtable (odb_data_t *data)
static __inline void odb_commit_reservation (odb_data_t *data)
int odb_check_hash (odb_t const *odb)
odb_hash_stat_todb_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)
int odb_update_node (odb_t *odb, odb_key_t key)
int odb_update_node_with_offset (odb_t *odb, odb_key_t key, unsigned long int offset)
int odb_add_node (odb_t *odb, odb_key_t key, odb_value_t value)
odb_node_todb_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)

Detailed Description

This file contains various definitions and interface for management of in-memory, through mmaped file, growable hash table, that stores sample files.

Remarks:
Copyright 2002 OProfile authors
Read the file COPYING
Author:
Philippe Elie

Definition in file odb.h.


Define Documentation

#define BUCKET_FACTOR   1
#define ODB_NODE_NR_INVALID   ((odb_node_nr_t)-1)

"immpossible" node number to indicate an error from odb_hash_add_node()

Definition at line 162 of file odb.h.


Typedef Documentation

typedef struct odb_data odb_data_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

store the hash mask, hash table size are always power of two

Definition at line 30 of file odb.h.

Definition at line 169 of file odb.h.

typedef unsigned int odb_index_t

the type of index (node number), list are implemented through index

Definition at line 26 of file odb.h.

typedef uint64_t odb_key_t

the type of key. 64-bit because CG needs 32-bit pair {from,to}

Definition at line 22 of file odb.h.

the type store node number

Definition at line 28 of file odb.h.

typedef unsigned int odb_value_t

the type of an information in the database

Definition at line 24 of file odb.h.


Enumeration Type Documentation

enum odb_rw

how to open the DB file

Enumerator:
ODB_RDONLY 

open for read only

ODB_RDWR 

open for read and/or write

Definition at line 100 of file odb.h.


Function Documentation

int odb_add_node ( odb_t odb,
odb_key_t  key,
odb_value_t  value 
)

Add a new node w/o regarding if a node with the same key already exists

returns EXIT_SUCCESS on success, EXIT_FAILURE on failure

Definition at line 106 of file db_insert.c.

References add_node(), and odb_t::data.

Referenced by import_from_abi(), and main().

Here is the call graph for this function:

Here is the caller graph for this function:

int odb_check_hash ( odb_t const *  odb  ) 

check that the hash is well built

Definition at line 90 of file db_debug.c.

References BUCKET_FACTOR, check_circular_list(), check_redundant_key(), odb_descr_t::current_size, odb_t::data, odb_data::descr, odb_data::hash_base, odb_node_t::key, odb_node_t::next, odb_data::node_base, and odb_descr_t::size.

Referenced by sanity_check(), and test().

Here is the call graph for this function:

Here is the caller graph for this function:

void odb_close ( odb_t odb  ) 

Close the given ODB file

Definition at line 263 of file db_manage.c.

References odb_data::base_memory, odb_t::data, odb_data::descr, odb_data::fd, odb_data::filename, odb_data::list, list_del(), odb_data::ref_count, odb_descr_t::size, and tables_size().

Referenced by close_sfile(), ibs_sfile_close(), main(), opd_24_sfile_lru_clear(), opd_close_image_samples_files(), sanity_check(), speed_test(), and test().

Here is the call graph for this function:

Here is the caller graph for this function:

static __inline void odb_commit_reservation ( odb_data_t data  )  [static]

commit a previously successfull node reservation. This can't fail.

Definition at line 156 of file odb.h.

References odb_descr_t::current_size, and odb_data::descr.

Referenced by add_node().

Here is the caller graph for this function:

static __inline unsigned int odb_do_hash ( odb_data_t const *  data,
odb_key_t  value 
) [static]

Definition at line 221 of file odb.h.

References odb_data::hash_mask.

Referenced by add_node(), odb_grow_hashtable(), and odb_update_node_with_offset().

Here is the caller graph for this function:

void* odb_get_data ( odb_t odb  ) 

return the start of the mapped data

Definition at line 291 of file db_manage.c.

References odb_data::base_memory, and odb_t::data.

Referenced by import_from_abi(), main(), opd_open_24_sample_file(), opd_open_sample_file(), and operf_open_sample_file().

Here is the caller graph for this function:

odb_node_t* odb_get_iterator ( odb_t const *  odb,
odb_node_nr_t nr 
)

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) // do something

note than caller does not need to filter nil key as it's a valid key, The returned range is all valid (i.e. should never contain zero value).

Definition at line 13 of file db_travel.c.

References odb_descr_t::current_size, odb_t::data, odb_data::descr, and odb_data::node_base.

int odb_grow_hashtable ( odb_data_t data  ) 

grow the hashtable in such way current_size is the index of the first free node. Take care all node pointer can be invalidated by this call.

Node allocation is done in a two step way 1st) ensure a free node exist eventually, caller can setup it, 2nd) commit the node allocation with odb_commit_reservation(). This is done in this way to ensure node setup is visible from another process like pp tools in an atomic way.

returns 0 on success, non zero 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.

Definition at line 63 of file db_manage.c.

References odb_data::base_memory, BUCKET_FACTOR, odb_descr_t::current_size, odb_data::descr, odb_data::fd, odb_data::hash_base, odb_data::hash_mask, odb_node_t::key, odb_node_t::next, odb_data::node_base, odb_do_hash(), odb_to_descr(), odb_to_hash_base(), odb_to_node_base(), odb_descr_t::size, and tables_size().

Referenced by add_node().

Here is the call graph for this function:

Here is the caller graph for this function:

void odb_hash_display_stat ( odb_hash_stat_t const *  stats  ) 
void odb_hash_free_stat ( odb_hash_stat_t stats  ) 

Definition at line 85 of file db_stat.c.

Referenced by sanity_check().

Here is the caller graph for this function:

odb_hash_stat_t* odb_hash_stat ( odb_t const *  odb  ) 
void odb_init ( odb_t odb  ) 

odb_init - initialize a DB file

Parameters:
odb the DB file to init

Definition at line 120 of file db_manage.c.

References odb_t::data.

Referenced by create_sfile(), ibs_sfile_create(), ibs_sfile_dup(), opd_open_24_sample_file(), operf_sfile_dup(), and sfile_dup().

Here is the caller graph for this function:

int odb_open ( odb_t odb,
char const *  filename,
enum odb_rw  rw,
size_t  sizeof_header 
)
int odb_open_count ( odb_t const *  odb  ) 

return the number of times this sample file is open

Definition at line 283 of file db_manage.c.

References odb_t::data, and odb_data::ref_count.

Referenced by get_file(), ibs_sfile_get(), and opd_put_image_sample().

Here is the caller graph for this function:

void odb_sync ( odb_t const *  odb  ) 

issue a msync on the used size of the mmaped file

Definition at line 297 of file db_manage.c.

References odb_data::base_memory, odb_t::data, odb_data::descr, odb_descr_t::size, and tables_size().

Referenced by ibs_sfile_sync(), opd_sync_samples_files(), and sync_sfile().

Here is the call graph for this function:

Here is the caller graph for this function:

int odb_update_node ( odb_t odb,
odb_key_t  key 
)

update info at key by incrementing its associated value by one, if the key does not exist a new node is created and the value associated is set to one.

returns EXIT_SUCCESS on success, EXIT_FAILURE on failure

Definition at line 52 of file db_insert.c.

References odb_update_node_with_offset().

Referenced by opd_put_image_sample(), operf_sfile_log_arc(), sfile_log_arc(), speed_test(), and test().

Here is the call graph for this function:

Here is the caller graph for this function:

int odb_update_node_with_offset ( odb_t odb,
odb_key_t  key,
unsigned long int  offset 
)

odb_update_node_with_offset

Parameters:
odb the data base object to setup
key the hash key
offset the offset to be added

update info at key by adding the specified offset to its associated value, if the key does not exist a new node is created and the value associated is set to offset.

returns EXIT_SUCCESS on success, EXIT_FAILURE on failure

Definition at line 57 of file db_insert.c.

References add_node(), odb_t::data, odb_data::hash_base, odb_node_t::key, odb_node_t::next, odb_data::node_base, odb_do_hash(), and odb_node_t::value.

Referenced by odb_update_node(), operf_sfile_log_sample_count(), and sfile_log_sample_count().

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1