summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2024-03-15 11:50:19 +0800
committerchenzizhan <[email protected]>2024-03-15 11:50:19 +0800
commit41cce570e1bf7e578f810b6af42b80f5034b896f (patch)
tree51ee22b993b4bb7344ee43f6d61b78fe31fe3c60
parent14ee23c81e897293b5182ec2a109364b85e211b0 (diff)
counter_set in fse
-rw-r--r--include/fieldstat/fieldstat_easy.h13
-rw-r--r--src/fieldstat_easy.c16
2 files changed, 25 insertions, 4 deletions
diff --git a/include/fieldstat/fieldstat_easy.h b/include/fieldstat/fieldstat_easy.h
index 92edb91..3cb9429 100644
--- a/include/fieldstat/fieldstat_easy.h
+++ b/include/fieldstat/fieldstat_easy.h
@@ -56,14 +56,19 @@ void fieldstat_easy_output_array(struct fieldstat_easy *fse, char ***json_object
*/
int fieldstat_easy_output_array_and_reset(struct fieldstat_easy *fse, char ***json_objects, size_t *n_object);
/*
- * @brief let the value of counter metric of cell_id increase by `increment`.
+ * @brief let the value of counter metric of tags increase by `increment`.
* @param thread_id: thread id. Must be in [0, max_thread_num).
- * @param metric_id: metric id, previously returned by fieldstat_register_counter.
+ * @param metric_id: metric id, previously returned by fieldstat_easy_register_counter.
* @param increment: increment of the counter metric. Can be negative.
- * @return FS_OK if success. FS_ERR_NULL_HANDLER, FS_ERR_INVALID_CUBE_ID, FS_ERR_INVALID_METRIC_ID if fail.
- * return -1 also when the thread_id is out of range.
+ * return -1 also when the thread_id is out of range.FS_ERR_INVALID_METRIC_ID metric_id is not registered.
*/
int fieldstat_easy_counter_incrby(struct fieldstat_easy *fse, int thread_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, long long increment);
+/*
+ * @brief let the value of counter metric of tags equal to `value`.
+ * for other notes, see fieldstat_easy_counter_incrby.
+ * The value will be output by summing each ones in different threads, exactly the same as values set by fieldstat_easy_counter_incrby.
+*/
+int fieldstat_easy_counter_set(struct fieldstat_easy *fse, int thread_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, long long value);
/*
* @brief Add a value to the histogram metric of cell_id. Histogram will record the distribution of the values.
The value bigger than highest_trackable_value will be set to highest_trackable_value. The value less than lowest_trackable_value will be tried to record, and, if succeed, remains in the record as -inf(most of the time) or 0(if value == 0)
diff --git a/src/fieldstat_easy.c b/src/fieldstat_easy.c
index 8be8dbc..879a06f 100644
--- a/src/fieldstat_easy.c
+++ b/src/fieldstat_easy.c
@@ -327,6 +327,22 @@ int fieldstat_easy_counter_incrby(struct fieldstat_easy *fse, int thread_id, int
return ret;
}
+int fieldstat_easy_counter_set(struct fieldstat_easy *fse, int thread_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, long long value)
+{
+ if (thread_id < 0) {
+ return -1;
+ }
+ if (thread_id >= fse->max_thread_num) {
+ return -1;
+ }
+
+ pthread_spin_lock(&fse->fsu[thread_id].lock);
+ int ret = fieldstat_counter_set(fse->fsu[thread_id].active, 0, metric_id, tags, n_tag, value);
+ pthread_spin_unlock(&fse->fsu[thread_id].lock);
+
+ return ret;
+}
+
int fieldstat_easy_histogram_record(struct fieldstat_easy *fse, int thread_id, int metric_id, const struct fieldstat_tag *tags, size_t n_tag, long long value)
{
if (thread_id < 0) {