@@ -204,6 +204,8 @@ int traceeval_query_size(struct traceeval *teval, const struct traceeval_data *k
void traceeval_results_release(struct traceeval *teval,
const struct traceeval_data *results);
+size_t traceeval_count(struct traceeval *teval);
+
#define traceeval_stat(teval, keys, type) \
traceeval_stat_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), type)
@@ -69,6 +69,7 @@ struct traceeval {
size_t nr_key_types;
size_t nr_val_types;
size_t update_counter;
+ size_t nr_elements;
size_t sizeof_type;
size_t sizeof_data;
};
@@ -786,6 +786,7 @@ static int create_entry(struct traceeval *teval,
entry->vals = new_vals;
teval->update_counter++;
+ teval->nr_elements++;
return 0;
@@ -1002,11 +1003,26 @@ int traceeval_remove_size(struct traceeval *teval,
hash_remove(hist, &entry->hash);
free_entry(teval, entry);
+ /* update_counter is used to know if there was an update. */
teval->update_counter++;
+ /* nr_elements keeps track of the number of stored elemnets */
+ teval->nr_elements--;
+
return 1;
}
+/**
+ * traceeval_count - Return the number of elements in the traceeval
+ * @teval: The traceeval handle to get the count from
+ *
+ * Returns the number of elements stored by unique keys in the @teval.
+ */
+size_t traceeval_count(struct traceeval *teval)
+{
+ return teval->nr_elements;
+}
+
/**
* traceeval_iterator_put - release a given iterator
* @iter: The iterartor to release
@@ -1457,6 +1473,7 @@ int traceeval_iterator_remove(struct traceeval_iterator *iter)
/* The entry no longer exists */
iter->entries[iter->next - 1] = NULL;
teval->update_counter++;
+ teval->nr_elements--;
return 1;
}