]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/History.h
Merged from parent (trunk 11270, circa 3.2.0.5+)
[thirdparty/squid.git] / src / adaptation / History.h
1 #ifndef SQUID_ADAPT_HISTORY_H
2 #define SQUID_ADAPT_HISTORY_H
3
4 #include "Array.h"
5 #include "HttpHeader.h"
6 #include "RefCount.h"
7 #include "SquidString.h"
8
9 namespace Adaptation
10 {
11
12
13 /// collects information about adaptations related to a master transaction
14 class History: public RefCountable
15 {
16 public:
17 typedef RefCount<Adaptation::History> Pointer;
18
19 History();
20
21 /// record the start of a xact, return xact history ID
22 int recordXactStart(const String &serviceId, const timeval &when, bool retrying);
23
24 /// record the end of a xact identified by its history ID
25 void recordXactFinish(int hid);
26
27 /// dump individual xaction times to a string
28 void allLogString(const char *serviceId, String &buf);
29
30 /// dump xaction times, merging retried and retry times together
31 void sumLogString(const char *serviceId, String &buf);
32
33 /// sets or resets a cross-transactional database record
34 void updateXxRecord(const char *name, const String &value);
35
36 /// returns true and fills the record fields iff there is a db record
37 bool getXxRecord(String &name, String &value) const;
38
39 /// sets or resets next services for the Adaptation::Iterator to notice
40 void updateNextServices(const String &services);
41
42 /// returns true, fills the value, and resets iff next services were set
43 bool extractNextServices(String &value);
44
45 /// store the last meta header fields received from the adaptation service
46 void recordMeta(const HttpHeader *lm);
47
48 public:
49 /// Last received meta header (REQMOD or RESPMOD, whichever comes last).
50 HttpHeader lastMeta;
51 /// All REQMOD and RESPMOD meta headers merged. Last field wins conflicts.
52 HttpHeader allMeta;
53
54 private:
55 /// single Xaction stats (i.e., a historical record entry)
56 class Entry
57 {
58 public:
59 Entry(const String &serviceId, const timeval &when);
60 Entry(); // required by Vector<>
61
62 void stop(); ///< updates stats on transaction end
63 int rptm(); ///< returns response time [msec], calculates it if needed
64
65 String service; ///< adaptation service ID
66 timeval start; ///< when the xaction was started
67
68 private:
69 int theRptm; ///< calculated and cached response time value in msec
70
71 public:
72 bool retried; ///< whether the xaction was replaced by another
73 };
74
75 typedef Vector<Entry> Entries;
76 Entries theEntries; ///< historical record, in the order of xact starts
77
78 // theXx* will become a map<string,string>, but we only support one record
79 String theXxName; ///< name part of the cross-transactional database record
80 String theXxValue; ///< value part of the cross-xactional database record
81
82 String theNextServices; ///< services Adaptation::Iterator must use next
83 };
84
85 } // namespace Adaptation
86
87 #endif