Skip to content

Commit

Permalink
more dense hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
tony2001 committed Aug 3, 2015
1 parent 449f3fe commit f0b67f1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 102 deletions.
149 changes: 55 additions & 94 deletions src/data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ void pinba_update_tag_info_add(size_t request_id, void *rep, const pinba_stats_r
{
pinba_tag_report *report = (pinba_tag_report *)rep;
struct pinba_tag_info_data *data;
PPvoid_t ppvalue;
pinba_timer_record *timer;
int i, j, tag_found;
pinba_word *word;
Expand All @@ -49,14 +48,9 @@ void pinba_update_tag_info_add(size_t request_id, void *rep, const pinba_stats_r
}

word = (pinba_word *)timer->tag_values[j];
ppvalue = JudySLGet(report->results, (uint8_t *)word->str, NULL);

if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
data = (struct pinba_tag_info_data *)tag_report_map_get(report->results, word->str);

ppvalue = JudySLIns(&report->results, (uint8_t *)word->str, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
continue;
}
if (UNLIKELY(!data)) {

data = (struct pinba_tag_info_data *)calloc(1, sizeof(struct pinba_tag_info_data));
if (!data) {
Expand All @@ -69,10 +63,10 @@ void pinba_update_tag_info_add(size_t request_id, void *rep, const pinba_stats_r
data->prev_add_request_id = request_id;
data->prev_del_request_id = -1;

*ppvalue = data;
report->results = tag_report_map_add(report->results, word->str, data);

report->std.results_cnt++;
} else {
data = (struct pinba_tag_info_data *)*ppvalue;
data->hit_count += timer->hit_count;
timeradd(&data->timer_value, &timer->value, &data->timer_value);
}
Expand All @@ -93,7 +87,6 @@ void pinba_update_tag_info_delete(size_t request_id, void *rep, const pinba_stat
{
pinba_tag_report *report = (pinba_tag_report *)rep;
struct pinba_tag_info_data *data;
PPvoid_t ppvalue;
pinba_timer_record *timer;
int i, j, tag_found;
pinba_word *word;
Expand All @@ -117,24 +110,24 @@ void pinba_update_tag_info_delete(size_t request_id, void *rep, const pinba_stat

word = (pinba_word *)timer->tag_values[j];

ppvalue = JudySLGet(report->results, (uint8_t *)word->str, NULL);
data = (struct pinba_tag_info_data *)tag_report_map_get(report->results, word->str);

if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
if (UNLIKELY(!data)) {
continue;
} else {
data = (struct pinba_tag_info_data *)*ppvalue;

/* count tag values only once per request */
if (request_id != data->prev_del_request_id) {
data->req_count--;
data->prev_del_request_id = request_id;
}

if (UNLIKELY(data->req_count == 0)) {
free(data);
JudySLDel(&report->results, (uint8_t *)word->str, NULL);
if (tag_report_map_del(report->results, word->str) < 0) {
tag_report_destroy(report->results);
report->results = NULL;
}
report->std.results_cnt--;
continue;
free(data);
} else {
data->hit_count -= timer->hit_count;
timersub(&data->timer_value, &timer->value, &data->timer_value);
Expand All @@ -151,12 +144,11 @@ void pinba_update_tag2_info_add(size_t request_id, void *rep, const pinba_stats_
{
pinba_tag_report *report = (pinba_tag_report *)rep;
struct pinba_tag2_info_data *data;
PPvoid_t ppvalue;
pinba_timer_record *timer;
int i, j, tag1_pos, tag2_pos, dummy;
pinba_word *word1, *word2;
int index_len;
uint8_t index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE];
char index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE];


for (i = 0; i < record->timers_cnt; i++) {
Expand Down Expand Up @@ -185,14 +177,9 @@ void pinba_update_tag2_info_add(size_t request_id, void *rep, const pinba_stats_
index_val[index_len] = '|'; index_len++;
memcat_static(index_val, index_len, word2->str, word2->len, index_len);

ppvalue = JudySLGet(report->results, index_val, NULL);
data = (struct pinba_tag2_info_data *)tag_report_map_get(report->results, index_val);

if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {

ppvalue = JudySLIns(&report->results, index_val, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
continue;
}
if (UNLIKELY(!data)) {

data = (struct pinba_tag2_info_data *)calloc(1, sizeof(struct pinba_tag2_info_data));
if (!data) {
Expand All @@ -208,10 +195,9 @@ void pinba_update_tag2_info_add(size_t request_id, void *rep, const pinba_stats_
memcpy_static(data->tag1_value, word1->str, word1->len, dummy);
memcpy_static(data->tag2_value, word2->str, word2->len, dummy);

*ppvalue = data;
report->results = tag_report_map_add(report->results, index_val, data);
report->std.results_cnt++;
} else {
data = (struct pinba_tag2_info_data *)*ppvalue;
data->hit_count += timer->hit_count;
timeradd(&data->timer_value, &timer->value, &data->timer_value);
}
Expand All @@ -232,12 +218,11 @@ void pinba_update_tag2_info_delete(size_t request_id, void *rep, const pinba_sta
{
pinba_tag_report *report = (pinba_tag_report *)rep;
struct pinba_tag2_info_data *data;
PPvoid_t ppvalue;
pinba_timer_record *timer;
int i, j, tag1_pos, tag2_pos;
int index_len;
pinba_word *word1, *word2;
uint8_t index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE];
char index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE];

PINBA_REPORT_DELETE_CHECK(report, record);

Expand Down Expand Up @@ -267,22 +252,23 @@ void pinba_update_tag2_info_delete(size_t request_id, void *rep, const pinba_sta
index_val[index_len] = '|'; index_len++;
memcat_static(index_val, index_len, word2->str, word2->len, index_len);

ppvalue = JudySLGet(report->results, index_val, NULL);
data = (struct pinba_tag2_info_data *)tag_report_map_get(report->results, index_val);

if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
if (UNLIKELY(!data)) {
continue;
} else {
data = (struct pinba_tag2_info_data *)*ppvalue;

/* count tag values only once per request */
if (request_id != data->prev_del_request_id) {
data->req_count--;
data->prev_del_request_id = request_id;
}

if (UNLIKELY(data->req_count == 0)) {
if (tag_report_map_del(report->results, index_val) < 0) {
tag_report_destroy(report->results);
report->results = NULL;
}
free(data);
JudySLDel(&report->results, (uint8_t *)index_val, NULL);
report->std.results_cnt--;
continue;
} else {
Expand Down Expand Up @@ -1549,7 +1535,6 @@ void pinba_update_rtag_info_add(size_t request_id, void *rep, const pinba_stats_
{
pinba_rtag_report *report = (pinba_rtag_report *)rep;
struct pinba_rtag_info_data *data;
PPvoid_t ppvalue;
unsigned int i, tag_found = 0;
pinba_word *word;

Expand All @@ -1565,23 +1550,14 @@ void pinba_update_rtag_info_add(size_t request_id, void *rep, const pinba_stats_
}

word = (pinba_word *)record->data.tag_values[i];
ppvalue = JudySLGet(report->results, (uint8_t *)word->str, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {

ppvalue = JudySLIns(&report->results, (uint8_t *)word->str, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
return;
}

data = (struct pinba_rtag_info_data*)tag_report_map_get(report->results, word->str);
if (UNLIKELY(!data)) {
data = (struct pinba_rtag_info_data *)calloc(1, sizeof(struct pinba_rtag_info_data));
if (!data) {
return;
}

*ppvalue = data;
report->results = tag_report_map_add(report->results, word->str, data);
report->std.results_cnt++;
} else {
data = (struct pinba_rtag_info_data *)*ppvalue;
}

timeradd(&report->time_total, &record->data.req_time, &report->time_total);
Expand All @@ -1604,7 +1580,6 @@ void pinba_update_rtag_info_delete(size_t request_id, void *rep, const pinba_sta
{
pinba_rtag_report *report = (pinba_rtag_report *)rep;
struct pinba_rtag_info_data *data;
PPvoid_t ppvalue;
unsigned int i, tag_found = 0;
pinba_word *word;

Expand All @@ -1622,12 +1597,11 @@ void pinba_update_rtag_info_delete(size_t request_id, void *rep, const pinba_sta
}

word = (pinba_word *)record->data.tag_values[i];
ppvalue = JudySLGet(report->results, (uint8_t *)word->str, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {

data = (struct pinba_rtag_info_data*)tag_report_map_get(report->results, word->str);
if (UNLIKELY(!data)) {
return;
} else {
data = (struct pinba_rtag_info_data *)*ppvalue;

timersub(&report->time_total, &record->data.req_time, &report->time_total);
timersub(&report->ru_utime_total, &record->data.ru_utime, &report->ru_utime_total);
timersub(&report->ru_stime_total, &record->data.ru_stime, &report->ru_stime_total);
Expand All @@ -1638,7 +1612,10 @@ void pinba_update_rtag_info_delete(size_t request_id, void *rep, const pinba_sta

if (UNLIKELY(data->req_count == 0)) {
free(data);
JudySLDel(&report->results, (uint8_t *)word->str, NULL);
if (tag_report_map_del(report->results, word->str) < 0) {
tag_report_destroy(report->results);
report->results = NULL;
}
report->std.results_cnt--;
return;
} else {
Expand All @@ -1657,11 +1634,10 @@ void pinba_update_rtag2_info_add(size_t request_id, void *rep, const pinba_stats
{
pinba_rtag_report *report = (pinba_rtag_report *)rep;
struct pinba_rtag2_info_data *data;
PPvoid_t ppvalue;
unsigned int i;
int tag1_pos = -1, tag2_pos = -1, index_len;
pinba_word *word1, *word2;
uint8_t index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE + 1];
char index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE + 1];

for (i = 0; i < record->data.tags_cnt; i++) {
if (report->tags[0] == record->data.tag_names[i]) {
Expand All @@ -1686,27 +1662,21 @@ void pinba_update_rtag2_info_add(size_t request_id, void *rep, const pinba_stats
index_val[index_len] = '|'; index_len++;
memcat_static(index_val, index_len, word2->str, word2->len, index_len);

ppvalue = JudySLGet(report->results, (uint8_t *)index_val, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
data = (struct pinba_rtag2_info_data*)tag_report_map_get(report->results, index_val);
if (UNLIKELY(!data)) {
int dummy;

ppvalue = JudySLIns(&report->results, (uint8_t *)index_val, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
return;
}

data = (struct pinba_rtag2_info_data *)calloc(1, sizeof(struct pinba_rtag2_info_data));
if (!data) {
return;
}

*ppvalue = data;

memcpy_static(data->tag1_value, word1->str, word1->len, dummy);
memcpy_static(data->tag2_value, word2->str, word2->len, dummy);
(void)dummy;

report->results = tag_report_map_add(report->results, index_val, data);
report->std.results_cnt++;
} else {
data = (struct pinba_rtag2_info_data *)*ppvalue;
}

timeradd(&report->time_total, &record->data.req_time, &report->time_total);
Expand All @@ -1729,11 +1699,10 @@ void pinba_update_rtag2_info_delete(size_t request_id, void *rep, const pinba_st
{
pinba_rtag_report *report = (pinba_rtag_report *)rep;
struct pinba_rtag2_info_data *data;
PPvoid_t ppvalue;
unsigned int i;
int tag1_pos = -1, tag2_pos = -1, index_len;
pinba_word *word1, *word2;
uint8_t index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE + 1];
char index_val[PINBA_TAG_VALUE_SIZE + 1 + PINBA_TAG_VALUE_SIZE + 1];

PINBA_REPORT_DELETE_CHECK(report, record);

Expand All @@ -1760,12 +1729,10 @@ void pinba_update_rtag2_info_delete(size_t request_id, void *rep, const pinba_st
index_val[index_len] = '|'; index_len++;
memcat_static(index_val, index_len, word2->str, word2->len, index_len);

ppvalue = JudySLGet(report->results, (uint8_t *)index_val, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
data = (struct pinba_rtag2_info_data *)tag_report_map_get(report->results, index_val);
if (UNLIKELY(!data)) {
return;
} else {
data = (struct pinba_rtag2_info_data *)*ppvalue;

timersub(&report->time_total, &record->data.req_time, &report->time_total);
timersub(&report->ru_utime_total, &record->data.ru_utime, &report->ru_utime_total);
timersub(&report->ru_stime_total, &record->data.ru_stime, &report->ru_stime_total);
Expand All @@ -1776,7 +1743,10 @@ void pinba_update_rtag2_info_delete(size_t request_id, void *rep, const pinba_st

if (UNLIKELY(data->req_count == 0)) {
free(data);
JudySLDel(&report->results, (uint8_t *)index_val, NULL);
if (tag_report_map_del(report->results, index_val) < 0) {
tag_report_destroy(report->results);
report->results = NULL;
}
report->std.results_cnt--;
return;
} else {
Expand Down Expand Up @@ -1964,7 +1934,7 @@ void pinba_update_rtag_report_add(size_t request_id, void *rep, const pinba_stat
{
pinba_rtag_report *report = (pinba_rtag_report *)rep;
struct pinba_rtag_report_data *data;
PPvoid_t ppvalue, ppvalue_host = NULL;
PPvoid_t ppvalue_host = NULL;
unsigned int i, tag_found = 0;
pinba_word *word;

Expand All @@ -1986,16 +1956,10 @@ void pinba_update_rtag_report_add(size_t request_id, void *rep, const pinba_stat
return;
}

ppvalue = JudySLGet(*ppvalue_host, (uint8_t *)word->str, NULL);

if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
data = (struct pinba_rtag_report_data *)tag_report_map_get(*ppvalue_host, word->str);
if (UNLIKELY(!data)) {
int dummy;

ppvalue = JudySLIns(ppvalue_host, (uint8_t *)word->str, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
return;
}

data = (struct pinba_rtag_report_data *)calloc(1, sizeof(struct pinba_rtag_report_data));
if (!data) {
return;
Expand All @@ -2004,10 +1968,8 @@ void pinba_update_rtag_report_add(size_t request_id, void *rep, const pinba_stat
memcpy_static(data->hostname, record->data.hostname, record->data.hostname_len, dummy);
memcpy_static(data->tag_value, word->str, word->len, dummy);

*ppvalue = data;
*ppvalue_host = tag_report_map_add(*ppvalue_host, word->str, data);
report->std.results_cnt++;
} else {
data = (struct pinba_rtag_report_data *)*ppvalue;
}

timeradd(&report->time_total, &record->data.req_time, &report->time_total);
Expand All @@ -2030,7 +1992,7 @@ void pinba_update_rtag_report_delete(size_t request_id, void *rep, const pinba_s
{
pinba_rtag_report *report = (pinba_rtag_report *)rep;
struct pinba_rtag_report_data *data;
PPvoid_t ppvalue, ppvalue_host = NULL;
PPvoid_t ppvalue_host = NULL;
unsigned int i, tag_found = 0;
pinba_word *word;

Expand All @@ -2054,12 +2016,10 @@ void pinba_update_rtag_report_delete(size_t request_id, void *rep, const pinba_s

word = (pinba_word *)record->data.tag_values[i];

ppvalue = JudySLGet(*ppvalue_host, (uint8_t *)word->str, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
data = (struct pinba_rtag_report_data *)tag_report_map_get(*ppvalue_host, word->str);
if (UNLIKELY(!data)) {
return;
} else {
data = (struct pinba_rtag_report_data *)*ppvalue;

timersub(&report->time_total, &record->data.req_time, &report->time_total);
timersub(&report->ru_utime_total, &record->data.ru_utime, &report->ru_utime_total);
timersub(&report->ru_stime_total, &record->data.ru_stime, &report->ru_stime_total);
Expand All @@ -2070,9 +2030,10 @@ void pinba_update_rtag_report_delete(size_t request_id, void *rep, const pinba_s

if (UNLIKELY(data->req_count == 0)) {
free(data);
JudySLDel(ppvalue_host, (uint8_t *)word->str, NULL);
if (*ppvalue_host == NULL) {
if (tag_report_map_del(*ppvalue_host, word->str) < 0) {
tag_report_destroy(*ppvalue_host);
JudySLDel(&report->results, (uint8_t *)record->data.hostname, NULL);
ppvalue_host = NULL;
}
report->std.results_cnt--;
return;
Expand Down
Loading

0 comments on commit f0b67f1

Please sign in to comment.