1 /** @file
2 
3   Public RecProcess declarations
4 
5   @section license License
6 
7   Licensed to the Apache Software Foundation (ASF) under one
8   or more contributor license agreements.  See the NOTICE file
9   distributed with this work for additional information
10   regarding copyright ownership.  The ASF licenses this file
11   to you under the Apache License, Version 2.0 (the
12   "License"); you may not use this file except in compliance
13   with the License.  You may obtain a copy of the License at
14 
15       http://www.apache.org/licenses/LICENSE-2.0
16 
17   Unless required by applicable law or agreed to in writing, software
18   distributed under the License is distributed on an "AS IS" BASIS,
19   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20   See the License for the specific language governing permissions and
21   limitations under the License.
22  */
23 
24 #pragma once
25 
26 #include "I_RecCore.h"
27 #include "I_EventSystem.h"
28 
29 //-------------------------------------------------------------------------
30 // Initialization/Starting
31 //-------------------------------------------------------------------------
32 int RecProcessInit(RecModeT mode_type, Diags *diags = nullptr);
33 int RecProcessInitMessage(RecModeT mode_type);
34 int RecProcessStart();
35 
36 //-------------------------------------------------------------------------
37 // Setters for manipulating internal sleep intervals
38 //-------------------------------------------------------------------------
39 void RecProcess_set_raw_stat_sync_interval_ms(int ms);
40 void RecProcess_set_config_update_interval_ms(int ms);
41 void RecProcess_set_remote_sync_interval_ms(int ms);
42 
43 //-------------------------------------------------------------------------
44 // RawStat Registration
45 //-------------------------------------------------------------------------
46 RecRawStatBlock *RecAllocateRawStatBlock(int num_stats);
47 
48 int _RecRegisterRawStat(RecRawStatBlock *rsb, RecT rec_type, const char *name, RecDataT data_type, RecPersistT persist_type, int id,
49                         RecRawStatSyncCb sync_cb);
50 #define RecRegisterRawStat(rsb, rec_type, name, data_type, persist_type, id, sync_cb) \
51   _RecRegisterRawStat((rsb), (rec_type), (name), (data_type), REC_PERSISTENCE_TYPE(persist_type), (id), (sync_cb))
52 
53 // RecRawStatRange* RecAllocateRawStatRange (int num_buckets);
54 
55 // int RecRegisterRawStatRange (RecRawStatRange *rsr,
56 //                           RecT rec_type,
57 //                           char *name,
58 //                           RecPersistT persist_type,
59 //                           int id,
60 //                           RecInt min,
61 //                           RecInt max);
62 
63 //-------------------------------------------------------------------------
64 // Predefined RawStat Callbacks
65 //-------------------------------------------------------------------------
66 int RecRawStatSyncSum(const char *name, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id);
67 int RecRawStatSyncCount(const char *name, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id);
68 int RecRawStatSyncAvg(const char *name, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id);
69 int RecRawStatSyncHrTimeAvg(const char *name, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id);
70 int RecRawStatSyncIntMsecsToFloatSeconds(const char *name, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id);
71 
72 int RecRegisterRawStatSyncCb(const char *name, RecRawStatSyncCb sync_cb, RecRawStatBlock *rsb, int id);
73 int RecRawStatUpdateSum(RecRawStatBlock *rsb, int id);
74 
75 //-------------------------------------------------------------------------
76 // RawStat Setting/Getting
77 //-------------------------------------------------------------------------
78 
79 // Note: The following RecIncrRawStatXXX calls are fast and don't
80 // require any ink_atomic_xxx64()'s to be executed.  Use these RawStat
81 // functions over other RawStat functions whenever possible.
82 inline int RecIncrRawStat(RecRawStatBlock *rsb, EThread *ethread, int id, int64_t incr = 1);
83 inline int RecIncrRawStatSum(RecRawStatBlock *rsb, EThread *ethread, int id, int64_t incr = 1);
84 inline int RecIncrRawStatCount(RecRawStatBlock *rsb, EThread *ethread, int id, int64_t incr = 1);
85 
86 int RecSetRawStatSum(RecRawStatBlock *rsb, int id, int64_t data);
87 int RecSetRawStatCount(RecRawStatBlock *rsb, int id, int64_t data);
88 
89 int RecGetRawStatSum(RecRawStatBlock *rsb, int id, int64_t *data);
90 int RecGetRawStatCount(RecRawStatBlock *rsb, int id, int64_t *data);
91 
92 //-------------------------------------------------------------------------
93 // Global RawStat Items (e.g. same as above, but no thread-local behavior)
94 //-------------------------------------------------------------------------
95 int RecIncrGlobalRawStat(RecRawStatBlock *rsb, int id, int64_t incr = 1);
96 int RecIncrGlobalRawStatSum(RecRawStatBlock *rsb, int id, int64_t incr = 1);
97 int RecIncrGlobalRawStatCount(RecRawStatBlock *rsb, int id, int64_t incr = 1);
98 
99 int RecSetGlobalRawStatSum(RecRawStatBlock *rsb, int id, int64_t data);
100 int RecSetGlobalRawStatCount(RecRawStatBlock *rsb, int id, int64_t data);
101 
102 int RecGetGlobalRawStatSum(RecRawStatBlock *rsb, int id, int64_t *data);
103 int RecGetGlobalRawStatCount(RecRawStatBlock *rsb, int id, int64_t *data);
104 
105 RecRawStat *RecGetGlobalRawStatPtr(RecRawStatBlock *rsb, int id);
106 int64_t *RecGetGlobalRawStatSumPtr(RecRawStatBlock *rsb, int id);
107 int64_t *RecGetGlobalRawStatCountPtr(RecRawStatBlock *rsb, int id);
108 
109 //-------------------------------------------------------------------------
110 // RecIncrRawStatXXX
111 //-------------------------------------------------------------------------
112 // inlined functions that are used very frequently.
113 // FIXME: move it to Inline.cc
114 inline RecRawStat *
raw_stat_get_tlp(RecRawStatBlock * rsb,int id,EThread * ethread)115 raw_stat_get_tlp(RecRawStatBlock *rsb, int id, EThread *ethread)
116 {
117   ink_assert((id >= 0) && (id < rsb->max_stats));
118   if (ethread == nullptr) {
119     ethread = this_ethread();
120   }
121   return (((RecRawStat *)((char *)(ethread) + rsb->ethr_stat_offset)) + id);
122 }
123 
124 inline int
RecIncrRawStat(RecRawStatBlock * rsb,EThread * ethread,int id,int64_t incr)125 RecIncrRawStat(RecRawStatBlock *rsb, EThread *ethread, int id, int64_t incr)
126 {
127   RecRawStat *tlp = raw_stat_get_tlp(rsb, id, ethread);
128   tlp->sum += incr;
129   tlp->count += 1;
130   return REC_ERR_OKAY;
131 }
132 
133 inline int
RecDecrRawStat(RecRawStatBlock * rsb,EThread * ethread,int id,int64_t decr)134 RecDecrRawStat(RecRawStatBlock *rsb, EThread *ethread, int id, int64_t decr)
135 {
136   RecRawStat *tlp = raw_stat_get_tlp(rsb, id, ethread);
137   tlp->sum -= decr;
138   tlp->count += 1;
139   return REC_ERR_OKAY;
140 }
141 
142 inline int
RecIncrRawStatSum(RecRawStatBlock * rsb,EThread * ethread,int id,int64_t incr)143 RecIncrRawStatSum(RecRawStatBlock *rsb, EThread *ethread, int id, int64_t incr)
144 {
145   RecRawStat *tlp = raw_stat_get_tlp(rsb, id, ethread);
146   tlp->sum += incr;
147   return REC_ERR_OKAY;
148 }
149 
150 inline int
RecIncrRawStatCount(RecRawStatBlock * rsb,EThread * ethread,int id,int64_t incr)151 RecIncrRawStatCount(RecRawStatBlock *rsb, EThread *ethread, int id, int64_t incr)
152 {
153   RecRawStat *tlp = raw_stat_get_tlp(rsb, id, ethread);
154   tlp->count += incr;
155   return REC_ERR_OKAY;
156 }
157