-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport_list.cc
72 lines (61 loc) · 1.57 KB
/
report_list.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include "report_list.h"
#include "pinba.h"
#include "pinba.pb-c.h"
void ReportList::merge_reports(ReportList *main_reports)
{
for (auto it = reports.begin(); it != reports.end(); ++it) {
Report *report = it->second;
if (report) {
auto main_rep = main_reports->reports.find(it->first);
if (main_rep == main_reports->reports.end()) {
pinba_error(P_WARNING, "no report in main reports list");
continue;
}
main_rep->second->merge_report(report);
report->clear();
}
}
}
int ReportList::add_request_to_reports(Pinba__Request *request) {
for (auto it = reports.begin(); it != reports.end(); ++it) {
Report *report = it->second;
if (report) {
report->add_record(request);
}
}
return 0;
}
int ReportList::del_request_from_reports(Pinba__Request *request) {
for (auto it = reports.begin(); it != reports.end(); ++it) {
Report *report = it->second;
if (report) {
report->del_record(request);
}
}
return 0;
}
void ReportList::del_report(std::string type) {
auto it = reports.find(type);
if (it != reports.end()) {
delete it->second;
reports.erase(type);
}
}
int ReportList::add_report(Report *report, std::string type) {
std::cout << "try to add report " << type << " to list" << std::endl;
auto it = reports.find(type);
if (it != reports.end()) {
std::cout << "report " << type << " alread exist, skip" << std::endl;
return -1;
}
reports[type] = report;
return 0;
}
Report *ReportList::get_report(std::string type) {
auto it = reports.find(type);
if (it == reports.end()) {
return NULL;
}
return it->second;
}