Skip to content

Commit

Permalink
make use of pinba_map
Browse files Browse the repository at this point in the history
  • Loading branch information
tony2001 committed Aug 26, 2015
1 parent 1e89940 commit 2ce21fd
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 101 deletions.
114 changes: 42 additions & 72 deletions src/data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ 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;

report->results = pinba_map_add(report->results, word->str, data);
report->results = pinba_map_add(report->results, word->str, data);

report->std.results_cnt++;
} else {
Expand Down Expand Up @@ -920,7 +920,6 @@ void pinba_update_tagN_info_add(size_t request_id, void *rep, const pinba_stats_
{
pinba_tag_report *report = (pinba_tag_report *)rep;
struct pinba_tagN_info_data *data;
PPvoid_t ppvalue;
pinba_timer_record *timer;
int i, j, k, found_tags_cnt, h;
int index_len;
Expand Down Expand Up @@ -970,14 +969,9 @@ void pinba_update_tagN_info_add(size_t request_id, void *rep, const pinba_stats_
}
report->index[index_len] = '\0';

ppvalue = JudySLGet(report->results, report->index, NULL);

if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
ppvalue = JudySLIns(&report->results, report->index, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
continue;
}
data = (struct pinba_tagN_info_data *)pinba_map_get(report->results, report->index);

if (UNLIKELY(!data)) {
data = (struct pinba_tagN_info_data *)calloc(1, sizeof(struct pinba_tagN_info_data));
if (UNLIKELY(!data)) {
continue;
Expand All @@ -1000,10 +994,9 @@ void pinba_update_tagN_info_add(size_t request_id, void *rep, const pinba_stats_
memcpy(data->tag_value + PINBA_TAG_VALUE_SIZE * k, word->str, word->len);
}

*ppvalue = data;
report->results = pinba_map_add(report->results, report->index, data);
report->std.results_cnt++;
} else {
data = (struct pinba_tagN_info_data *)*ppvalue;
data->hit_count += timer->hit_count;
timeradd(&data->timer_value, &timer->value, &data->timer_value);
}
Expand All @@ -1024,7 +1017,6 @@ void pinba_update_tagN_info_delete(size_t request_id, void *rep, const pinba_sta
{
pinba_tag_report *report = (pinba_tag_report *)rep;
struct pinba_tagN_info_data *data;
PPvoid_t ppvalue;
pinba_timer_record *timer;
int i, j, k, found_tags_cnt, h;
int index_len;
Expand Down Expand Up @@ -1076,22 +1068,23 @@ void pinba_update_tagN_info_delete(size_t request_id, void *rep, const pinba_sta
}
report->index[index_len] = '\0';

ppvalue = JudySLGet(report->results, report->index, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
data = (struct pinba_tagN_info_data *)pinba_map_get(report->results, report->index);
if (UNLIKELY(!data)) {
continue;
} else {
data = (struct pinba_tagN_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 (pinba_map_del(report->results, report->index) < 0) {
pinba_map_destroy(report->results);
report->results = NULL;
}
free(data->tag_value);
free(data);
JudySLDel(&report->results, (uint8_t *)report->index, NULL);
report->std.results_cnt--;
continue;
} else {
Expand Down Expand Up @@ -1164,14 +1157,9 @@ void pinba_update_tagN_report_add(size_t request_id, void *rep, const pinba_stat
}
report->index[index_len] = '\0';

ppvalue = JudySLGet(*ppvalue_script, report->index, NULL);

if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
ppvalue = JudySLIns(ppvalue_script, report->index, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
continue;
}
data = (struct pinba_tagN_report_data *)pinba_map_get(*ppvalue_script, report->index);

if (UNLIKELY(!data)) {
data = (struct pinba_tagN_report_data *)calloc(1, sizeof(struct pinba_tagN_report_data));
if (UNLIKELY(!data)) {
continue;
Expand All @@ -1195,10 +1183,9 @@ void pinba_update_tagN_report_add(size_t request_id, void *rep, const pinba_stat
memcpy(data->tag_value + PINBA_TAG_VALUE_SIZE * k, word->str, word->len);
}

*ppvalue = data;
*ppvalue_script = pinba_map_add(*ppvalue_script, report->index, data);
report->std.results_cnt++;
} else {
data = (struct pinba_tagN_report_data *)*ppvalue;
data->hit_count += timer->hit_count;
timeradd(&data->timer_value, &timer->value, &data->timer_value);
}
Expand Down Expand Up @@ -1277,26 +1264,24 @@ void pinba_update_tagN_report_delete(size_t request_id, void *rep, const pinba_s
}
report->index[index_len] = '\0';

ppvalue = JudySLGet(*ppvalue_script, report->index, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
data = (struct pinba_tagN_report_data *)pinba_map_get(*ppvalue_script, report->index);
if (UNLIKELY(!data)) {
continue;
} else {
data = (struct pinba_tagN_report_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->tag_value);
free(data);
JudySLDel(ppvalue_script, (uint8_t *)report->index, NULL);
if (*ppvalue_script == NULL) {
JudySLDel(&report->results, (uint8_t *)record->data.script_name, NULL);
if (pinba_map_del(*ppvalue_script, report->index) < 0) {
pinba_map_destroy(*ppvalue_script);
ppvalue_script = NULL;
JudySLDel(&report->results, (uint8_t *)report->index, NULL);
}
free(data->tag_value);
free(data);
report->std.results_cnt--;
continue;
} else {
Expand Down Expand Up @@ -1375,14 +1360,9 @@ void pinba_update_tagN_report2_add(size_t request_id, void *rep, const pinba_sta
}
report->index[index_len] = '\0';

ppvalue = JudySLGet(*ppvalue_script, report->index, NULL);

if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
ppvalue = JudySLIns(ppvalue_script, report->index, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
continue;
}
data = (struct pinba_tagN_report2_data *)pinba_map_get(*ppvalue_script, report->index);

if (UNLIKELY(!data)) {
data = (struct pinba_tagN_report2_data *)calloc(1, sizeof(struct pinba_tagN_report2_data));
if (UNLIKELY(!data)) {
continue;
Expand All @@ -1408,7 +1388,7 @@ void pinba_update_tagN_report2_add(size_t request_id, void *rep, const pinba_sta
memcpy(data->tag_value + PINBA_TAG_VALUE_SIZE * k, word->str, word->len);
}

*ppvalue = data;
*ppvalue_script = pinba_map_add(*ppvalue_script, report->index, data);
report->std.results_cnt++;
} else {
data = (struct pinba_tagN_report2_data *)*ppvalue;
Expand Down Expand Up @@ -1496,26 +1476,24 @@ void pinba_update_tagN_report2_delete(size_t request_id, void *rep, const pinba_
}
report->index[index_len] = '\0';

ppvalue = JudySLGet(*ppvalue_script, report->index, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
data = (struct pinba_tagN_report2_data *)pinba_map_get(*ppvalue_script, report->index);
if (UNLIKELY(!data)) {
continue;
} else {
data = (struct pinba_tagN_report2_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->tag_value);
free(data);
JudySLDel(ppvalue_script, (uint8_t *)report->index, NULL);
if (*ppvalue_script == NULL) {
JudySLDel(&report->results, (uint8_t *)record->data.script_name, NULL);
if (pinba_map_del(*ppvalue_script, report->index) < 0) {
pinba_map_destroy(*ppvalue_script);
ppvalue_script = NULL;
JudySLDel(&report->results, (uint8_t *)report->index, NULL);
}
free(data->tag_value);
free(data);
report->std.results_cnt--;
continue;
} else {
Expand Down Expand Up @@ -1614,7 +1592,7 @@ void pinba_update_rtag_info_delete(size_t request_id, void *rep, const pinba_sta
free(data);
if (pinba_map_del(report->results, word->str) < 0) {
pinba_map_destroy(report->results);
report->results = NULL;
report->results = NULL;
}
report->std.results_cnt--;
return;
Expand Down Expand Up @@ -1745,7 +1723,7 @@ void pinba_update_rtag2_info_delete(size_t request_id, void *rep, const pinba_st
free(data);
if (pinba_map_del(report->results, index_val) < 0) {
pinba_map_destroy(report->results);
report->results = NULL;
report->results = NULL;
}
report->std.results_cnt--;
return;
Expand Down Expand Up @@ -2199,7 +2177,7 @@ void pinba_update_rtagN_report_add(size_t request_id, void *rep, const pinba_sta
{
pinba_rtag_report *report = (pinba_rtag_report *)rep;
struct pinba_rtagN_report_data *data;
PPvoid_t ppvalue, ppvalue_host = NULL;
PPvoid_t ppvalue_host = NULL;
unsigned int i, j, found_tags_cnt = 0;
int index_len;
pinba_word *word;
Expand Down Expand Up @@ -2245,15 +2223,10 @@ void pinba_update_rtagN_report_add(size_t request_id, void *rep, const pinba_sta
}
report->index[index_len] = '\0';

ppvalue = JudySLGet(*ppvalue_host, report->index, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
data = (struct pinba_rtagN_report_data *)pinba_map_get(*ppvalue_host, report->index);
if (UNLIKELY(!data)) {
int dummy;

ppvalue = JudySLIns(ppvalue_host, report->index, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
return;
}

data = (struct pinba_rtagN_report_data *)calloc(1, sizeof(struct pinba_rtagN_report_data));
if (!data) {
return;
Expand All @@ -2272,10 +2245,8 @@ void pinba_update_rtagN_report_add(size_t request_id, void *rep, const pinba_sta
memcpy(data->tag_value + PINBA_TAG_VALUE_SIZE * i, word->str, word->len);
}

*ppvalue = data;
*ppvalue_host = pinba_map_add(*ppvalue_host, report->index, data);
report->std.results_cnt++;
} else {
data = (struct pinba_rtagN_report_data *)*ppvalue;
}

timeradd(&report->time_total, &record->data.req_time, &report->time_total);
Expand All @@ -2298,7 +2269,7 @@ void pinba_update_rtagN_report_delete(size_t request_id, void *rep, const pinba_
{
pinba_rtag_report *report = (pinba_rtag_report *)rep;
struct pinba_rtagN_report_data *data;
PPvoid_t ppvalue, ppvalue_host = NULL;
PPvoid_t ppvalue_host = NULL;
unsigned int i, j, found_tags_cnt = 0;
int index_len;
pinba_word *word;
Expand Down Expand Up @@ -2346,12 +2317,10 @@ void pinba_update_rtagN_report_delete(size_t request_id, void *rep, const pinba_
}
report->index[index_len] = '\0';

ppvalue = JudySLGet(*ppvalue_host, report->index, NULL);
if (UNLIKELY(!ppvalue || ppvalue == PPJERR)) {
data = (struct pinba_rtagN_report_data *) pinba_map_get(*ppvalue_host, report->index);
if (UNLIKELY(!data)) {
return;
} else {
data = (struct pinba_rtagN_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 @@ -2363,8 +2332,9 @@ void pinba_update_rtagN_report_delete(size_t request_id, void *rep, const pinba_
if (UNLIKELY(data->req_count == 0)) {
free(data->tag_value);
free(data);
JudySLDel(ppvalue_host, report->index, NULL);
if (*ppvalue_host == NULL) {

if (pinba_map_del(*ppvalue_host, report->index) < 0) {
pinba_map_destroy(*ppvalue_host);
JudySLDel(&report->results, (uint8_t *)record->data.hostname, NULL);
}
report->std.results_cnt--;
Expand Down
Loading

0 comments on commit 2ce21fd

Please sign in to comment.