Coverage Report

Created: 2026-06-11 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/trafficserver/include/records/RecProcess.h
Line
Count
Source
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 "iocore/eventsystem/EThread.h"
27
#include "records/RecDefs.h"
28
29
//-------------------------------------------------------------------------
30
// RawStat Registration
31
//-------------------------------------------------------------------------
32
33
using RecRawStatBlockAllocator = RecRawStatBlock *(*)(int num_stats);
34
35
void             SetRecAllocateRawStatBlockAllocator(RecRawStatBlockAllocator);
36
RecRawStatBlock *RecAllocateRawStatBlock(int num_stats);
37
38
int _RecRegisterRawStat(RecRawStatBlock *rsb, RecT rec_type, const char *name, RecDataT data_type, RecPersistT persist_type, int id,
39
                        RecRawStatSyncCb sync_cb);
40
#define RecRegisterRawStat(rsb, rec_type, name, data_type, persist_type, id, sync_cb) \
41
  _RecRegisterRawStat((rsb), (rec_type), (name), (data_type), REC_PERSISTENCE_TYPE(persist_type), (id), (sync_cb))
42
43
// RecRawStatRange* RecAllocateRawStatRange (int num_buckets);
44
45
// int RecRegisterRawStatRange (RecRawStatRange *rsr,
46
//                           RecT rec_type,
47
//                           char *name,
48
//                           RecPersistT persist_type,
49
//                           int id,
50
//                           RecInt min,
51
//                           RecInt max);
52
53
//-------------------------------------------------------------------------
54
// Predefined RawStat Callbacks
55
//-------------------------------------------------------------------------
56
int RecRawStatSyncSum(const char *name, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id);
57
int RecRawStatSyncCount(const char *name, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id);
58
int RecRawStatSyncAvg(const char *name, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id);
59
int RecRawStatSyncHrTimeAvg(const char *name, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id);
60
int RecRawStatSyncIntMsecsToFloatSeconds(const char *name, RecDataT data_type, RecData *data, RecRawStatBlock *rsb, int id);
61
62
int RecRegisterRawStatSyncCb(const char *name, RecRawStatSyncCb sync_cb, RecRawStatBlock *rsb, int id);
63
int RecRawStatUpdateSum(RecRawStatBlock *rsb, int id);
64
65
int RecExecRawStatSyncCbs();
66
67
using RecCallbackFunction = std::function<void()>;
68
void RecRegNewSyncStatSync(RecCallbackFunction callback);
69
70
//-------------------------------------------------------------------------
71
// RawStat Setting/Getting
72
//-------------------------------------------------------------------------
73
74
// Note: The following RecIncrRawStatXXX calls are fast and don't
75
// require any ink_atomic_xxx64()'s to be executed.  Use these RawStat
76
// functions over other RawStat functions whenever possible.
77
inline int RecIncrRawStat(RecRawStatBlock *rsb, EThread *ethread, int id, int64_t incr = 1);
78
inline int RecIncrRawStatSum(RecRawStatBlock *rsb, EThread *ethread, int id, int64_t incr = 1);
79
inline int RecIncrRawStatCount(RecRawStatBlock *rsb, EThread *ethread, int id, int64_t incr = 1);
80
81
int RecSetRawStatSum(RecRawStatBlock *rsb, int id, int64_t data);
82
int RecSetRawStatCount(RecRawStatBlock *rsb, int id, int64_t data);
83
84
int RecGetRawStatSum(RecRawStatBlock *rsb, int id, int64_t *data);
85
int RecGetRawStatCount(RecRawStatBlock *rsb, int id, int64_t *data);
86
87
//-------------------------------------------------------------------------
88
// Global RawStat Items (e.g. same as above, but no thread-local behavior)
89
//-------------------------------------------------------------------------
90
int RecIncrGlobalRawStat(RecRawStatBlock *rsb, int id, int64_t incr = 1);
91
int RecIncrGlobalRawStatSum(RecRawStatBlock *rsb, int id, int64_t incr = 1);
92
int RecIncrGlobalRawStatCount(RecRawStatBlock *rsb, int id, int64_t incr = 1);
93
94
int RecSetGlobalRawStatSum(RecRawStatBlock *rsb, int id, int64_t data);
95
int RecSetGlobalRawStatCount(RecRawStatBlock *rsb, int id, int64_t data);
96
97
int RecGetGlobalRawStatSum(RecRawStatBlock *rsb, int id, int64_t *data);
98
int RecGetGlobalRawStatCount(RecRawStatBlock *rsb, int id, int64_t *data);
99
100
RecRawStat *RecGetGlobalRawStatPtr(RecRawStatBlock *rsb, int id);
101
int64_t    *RecGetGlobalRawStatSumPtr(RecRawStatBlock *rsb, int id);
102
int64_t    *RecGetGlobalRawStatCountPtr(RecRawStatBlock *rsb, int id);
103
104
//-------------------------------------------------------------------------
105
// RecIncrRawStatXXX
106
//-------------------------------------------------------------------------
107
// inlined functions that are used very frequently.
108
// FIXME: move it to Inline.cc
109
inline RecRawStat *
110
raw_stat_get_tlp(RecRawStatBlock *rsb, int id, EThread *ethread)
111
0
{
112
0
  ink_assert((id >= 0) && (id < rsb->max_stats));
113
0
  if (ethread == nullptr) {
114
0
    ethread = this_ethread();
115
0
  }
116
0
  return ((reinterpret_cast<RecRawStat *>(reinterpret_cast<char *>(ethread) + rsb->ethr_stat_offset)) + id);
117
0
}
118
119
inline int
120
RecIncrRawStat(RecRawStatBlock *rsb, EThread *ethread, int id, int64_t incr)
121
0
{
122
0
  RecRawStat *tlp  = raw_stat_get_tlp(rsb, id, ethread);
123
0
  tlp->sum        += incr;
124
0
  tlp->count      += 1;
125
0
  return REC_ERR_OKAY;
126
0
}
127
128
inline int
129
RecDecrRawStat(RecRawStatBlock *rsb, EThread *ethread, int id, int64_t decr)
130
0
{
131
0
  RecRawStat *tlp  = raw_stat_get_tlp(rsb, id, ethread);
132
0
  tlp->sum        -= decr;
133
0
  tlp->count      += 1;
134
0
  return REC_ERR_OKAY;
135
0
}
136
137
inline int
138
RecIncrRawStatSum(RecRawStatBlock *rsb, EThread *ethread, int id, int64_t incr)
139
0
{
140
0
  RecRawStat *tlp  = raw_stat_get_tlp(rsb, id, ethread);
141
0
  tlp->sum        += incr;
142
0
  return REC_ERR_OKAY;
143
0
}
144
145
inline int
146
RecIncrRawStatCount(RecRawStatBlock *rsb, EThread *ethread, int id, int64_t incr)
147
0
{
148
0
  RecRawStat *tlp  = raw_stat_get_tlp(rsb, id, ethread);
149
0
  tlp->count      += incr;
150
0
  return REC_ERR_OKAY;
151
0
}