Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 2 | # |
| 3 | # Copyright (c) 2021 Cisco and/or its affiliates. |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at: |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 16 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 17 | """ |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 18 | This module implement Python access to the VPP statistics segment. It |
| 19 | accesses the data structures directly in shared memory. |
| 20 | VPP uses optimistic locking, so data structures may change underneath |
| 21 | us while we are reading. Data is copied out and it's important to |
| 22 | spend as little time as possible "holding the lock". |
| 23 | |
| 24 | Counters are stored in VPP as a two dimensional array. |
| 25 | Index by thread and index (typically sw_if_index). |
| 26 | Simple counters count only packets, Combined counters count packets |
| 27 | and octets. |
| 28 | |
| 29 | Counters can be accessed in either dimension. |
| 30 | stat['/if/rx'] - returns 2D lists |
| 31 | stat['/if/rx'][0] - returns counters for all interfaces for thread 0 |
| 32 | stat['/if/rx'][0][1] - returns counter for interface 1 on thread 0 |
| 33 | stat['/if/rx'][0][1]['packets'] - returns the packet counter |
| 34 | for interface 1 on thread 0 |
| 35 | stat['/if/rx'][:, 1] - returns the counters for interface 1 on all threads |
| 36 | stat['/if/rx'][:, 1].packets() - returns the packet counters for |
| 37 | interface 1 on all threads |
| 38 | stat['/if/rx'][:, 1].sum_packets() - returns the sum of packet counters for |
| 39 | interface 1 on all threads |
| 40 | stat['/if/rx-miss'][:, 1].sum() - returns the sum of packet counters for |
| 41 | interface 1 on all threads for simple counters |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 42 | """ |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 43 | |
| 44 | import os |
| 45 | import socket |
| 46 | import array |
| 47 | import mmap |
| 48 | from struct import Struct |
Paul Vinciguerra | 5642109 | 2018-11-21 16:34:09 -0800 | [diff] [blame] | 49 | import time |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 50 | import unittest |
| 51 | import re |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 52 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 53 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 54 | def recv_fd(sock): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 55 | """Get file descriptor for memory map""" |
| 56 | fds = array.array("i") # Array of ints |
Tom Jones | b10561b | 2024-02-07 13:31:50 +0000 | [diff] [blame] | 57 | _, ancdata, _, _ = sock.recvmsg(0, socket.CMSG_SPACE(4)) |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 58 | for cmsg_level, cmsg_type, cmsg_data in ancdata: |
| 59 | if cmsg_level == socket.SOL_SOCKET and cmsg_type == socket.SCM_RIGHTS: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 60 | fds.frombytes(cmsg_data[: len(cmsg_data) - (len(cmsg_data) % fds.itemsize)]) |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 61 | return list(fds)[0] |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 62 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 63 | |
| 64 | VEC_LEN_FMT = Struct("I") |
| 65 | |
| 66 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 67 | def get_vec_len(stats, vector_offset): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 68 | """Equivalent to VPP vec_len()""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 69 | return VEC_LEN_FMT.unpack_from(stats.statseg, vector_offset - 8)[0] |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 70 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 71 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 72 | def get_string(stats, ptr): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 73 | """Get a string from a VPP vector""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 74 | namevector = ptr - stats.base |
| 75 | namevectorlen = get_vec_len(stats, namevector) |
| 76 | if namevector + namevectorlen >= stats.size: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 77 | raise IOError("String overruns stats segment") |
| 78 | return stats.statseg[namevector : namevector + namevectorlen - 1].decode("ascii") |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 79 | |
| 80 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 81 | class StatsVector: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 82 | """A class representing a VPP vector""" |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 83 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 84 | def __init__(self, stats, ptr, fmt): |
| 85 | self.vec_start = ptr - stats.base |
| 86 | self.vec_len = get_vec_len(stats, ptr - stats.base) |
| 87 | self.struct = Struct(fmt) |
| 88 | self.fmtlen = len(fmt) |
| 89 | self.elementsize = self.struct.size |
| 90 | self.statseg = stats.statseg |
| 91 | self.stats = stats |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 92 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 93 | if self.vec_start + self.vec_len * self.elementsize >= stats.size: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 94 | raise IOError("Vector overruns stats segment") |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 95 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 96 | def __iter__(self): |
| 97 | with self.stats.lock: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 98 | return self.struct.iter_unpack( |
| 99 | self.statseg[ |
| 100 | self.vec_start : self.vec_start + self.elementsize * self.vec_len |
| 101 | ] |
| 102 | ) |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 103 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 104 | def __getitem__(self, index): |
| 105 | if index > self.vec_len: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 106 | raise IOError("Index beyond end of vector") |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 107 | with self.stats.lock: |
| 108 | if self.fmtlen == 1: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 109 | return self.struct.unpack_from( |
| 110 | self.statseg, self.vec_start + (index * self.elementsize) |
| 111 | )[0] |
| 112 | return self.struct.unpack_from( |
| 113 | self.statseg, self.vec_start + (index * self.elementsize) |
| 114 | ) |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 115 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 116 | |
| 117 | class VPPStats: |
| 118 | """Main class implementing Python access to the VPP statistics segment""" |
| 119 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 120 | # pylint: disable=too-many-instance-attributes |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 121 | shared_headerfmt = Struct("QPQQPP") |
| 122 | default_socketname = "/run/vpp/stats.sock" |
Paul Vinciguerra | 6ccc6e9 | 2018-11-27 08:15:22 -0800 | [diff] [blame] | 123 | |
| 124 | def __init__(self, socketname=default_socketname, timeout=10): |
Paul Vinciguerra | e090f4d | 2019-11-29 17:41:20 -0500 | [diff] [blame] | 125 | self.socketname = socketname |
| 126 | self.timeout = timeout |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 127 | self.directory = {} |
| 128 | self.lock = StatsLock(self) |
Paul Vinciguerra | e090f4d | 2019-11-29 17:41:20 -0500 | [diff] [blame] | 129 | self.connected = False |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 130 | self.size = 0 |
| 131 | self.last_epoch = 0 |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 132 | self.statseg = 0 |
Paul Vinciguerra | e090f4d | 2019-11-29 17:41:20 -0500 | [diff] [blame] | 133 | |
| 134 | def connect(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 135 | """Connect to stats segment""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 136 | if self.connected: |
| 137 | return |
| 138 | sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET) |
Tom Jones | b3ee84d | 2024-02-07 13:34:56 +0000 | [diff] [blame] | 139 | |
| 140 | # Our connect races the corresponding recv_fds call in VPP, if we beat |
| 141 | # VPP then we will try (unsuccessfully) to receive file descriptors and |
| 142 | # will have gone away before VPP can respond to our connect. A short |
| 143 | # timeout here stops this error occurring. |
| 144 | sock.settimeout(1) |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 145 | sock.connect(self.socketname) |
Paul Vinciguerra | 5642109 | 2018-11-21 16:34:09 -0800 | [diff] [blame] | 146 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 147 | mfd = recv_fd(sock) |
| 148 | sock.close() |
Paul Vinciguerra | 5642109 | 2018-11-21 16:34:09 -0800 | [diff] [blame] | 149 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 150 | stat_result = os.fstat(mfd) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 151 | self.statseg = mmap.mmap( |
| 152 | mfd, stat_result.st_size, mmap.PROT_READ, mmap.MAP_SHARED |
| 153 | ) |
Tianyu Li | 0e79bc1 | 2021-04-14 12:36:20 +0800 | [diff] [blame] | 154 | os.close(mfd) |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 155 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 156 | self.size = stat_result.st_size |
| 157 | if self.version != 2: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 158 | raise Exception("Incompatbile stat segment version {}".format(self.version)) |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 159 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 160 | self.refresh() |
| 161 | self.connected = True |
Ole Troan | 233e468 | 2019-05-16 15:01:34 +0200 | [diff] [blame] | 162 | |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 163 | def disconnect(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 164 | """Disconnect from stats segment""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 165 | if self.connected: |
| 166 | self.statseg.close() |
Paul Vinciguerra | e090f4d | 2019-11-29 17:41:20 -0500 | [diff] [blame] | 167 | self.connected = False |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 168 | |
| 169 | @property |
| 170 | def version(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 171 | """Get version of stats segment""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 172 | return self.shared_headerfmt.unpack_from(self.statseg)[0] |
| 173 | |
| 174 | @property |
| 175 | def base(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 176 | """Get base pointer of stats segment""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 177 | return self.shared_headerfmt.unpack_from(self.statseg)[1] |
| 178 | |
| 179 | @property |
| 180 | def epoch(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 181 | """Get current epoch value from stats segment""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 182 | return self.shared_headerfmt.unpack_from(self.statseg)[2] |
| 183 | |
| 184 | @property |
| 185 | def in_progress(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 186 | """Get value of in_progress from stats segment""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 187 | return self.shared_headerfmt.unpack_from(self.statseg)[3] |
| 188 | |
| 189 | @property |
| 190 | def directory_vector(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 191 | """Get pointer of directory vector""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 192 | return self.shared_headerfmt.unpack_from(self.statseg)[4] |
| 193 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 194 | elementfmt = "IQ128s" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 195 | |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 196 | def refresh(self, blocking=True): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 197 | """Refresh directory vector cache (epoch changed)""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 198 | directory = {} |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 199 | directory_by_idx = {} |
| 200 | while True: |
| 201 | try: |
| 202 | with self.lock: |
Arthur de Kerhor | c9ae8cf | 2021-06-24 19:39:44 +0200 | [diff] [blame] | 203 | self.last_epoch = self.epoch |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 204 | for i, direntry in enumerate( |
| 205 | StatsVector(self, self.directory_vector, self.elementfmt) |
| 206 | ): |
| 207 | path_raw = direntry[2].find(b"\x00") |
| 208 | path = direntry[2][:path_raw].decode("ascii") |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 209 | directory[path] = StatsEntry(direntry[0], direntry[1]) |
| 210 | directory_by_idx[i] = path |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 211 | self.directory = directory |
| 212 | self.directory_by_idx = directory_by_idx |
Arthur de Kerhor | 905c153 | 2021-06-25 18:03:24 +0200 | [diff] [blame] | 213 | return |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 214 | except IOError: |
| 215 | if not blocking: |
| 216 | raise |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 217 | |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 218 | def __getitem__(self, item, blocking=True): |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 219 | if not self.connected: |
| 220 | self.connect() |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 221 | while True: |
| 222 | try: |
| 223 | if self.last_epoch != self.epoch: |
| 224 | self.refresh(blocking) |
| 225 | with self.lock: |
Arthur de Kerhor | 905c153 | 2021-06-25 18:03:24 +0200 | [diff] [blame] | 226 | return self.directory[item].get_counter(self) |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 227 | except IOError: |
| 228 | if not blocking: |
| 229 | raise |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 230 | |
| 231 | def __iter__(self): |
| 232 | return iter(self.directory.items()) |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 233 | |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 234 | def set_errors(self, blocking=True): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 235 | """Return dictionary of error counters > 0""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 236 | if not self.connected: |
| 237 | self.connect() |
Paul Vinciguerra | 5642109 | 2018-11-21 16:34:09 -0800 | [diff] [blame] | 238 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 239 | errors = {k: v for k, v in self.directory.items() if k.startswith("/err/")} |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 240 | result = {} |
Damjan Marion | 66c8583 | 2022-03-14 13:04:38 +0100 | [diff] [blame] | 241 | for k in errors: |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 242 | try: |
Damjan Marion | 66c8583 | 2022-03-14 13:04:38 +0100 | [diff] [blame] | 243 | total = self[k].sum() |
| 244 | if total: |
| 245 | result[k] = total |
| 246 | except KeyError: |
| 247 | pass |
| 248 | return result |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 249 | |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 250 | def set_errors_str(self, blocking=True): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 251 | """Return all errors counters > 0 pretty printed""" |
| 252 | error_string = ["ERRORS:"] |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 253 | error_counters = self.set_errors(blocking) |
Ole Troan | 7320210 | 2018-08-31 00:29:48 +0200 | [diff] [blame] | 254 | for k in sorted(error_counters): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 255 | error_string.append("{:<60}{:>10}".format(k, error_counters[k])) |
| 256 | return "%s\n" % "\n".join(error_string) |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 257 | |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 258 | def get_counter(self, name, blocking=True): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 259 | """Alternative call to __getitem__""" |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 260 | return self.__getitem__(name, blocking) |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 261 | |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 262 | def get_err_counter(self, name, blocking=True): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 263 | """Alternative call to __getitem__""" |
Damjan Marion | 66c8583 | 2022-03-14 13:04:38 +0100 | [diff] [blame] | 264 | return self.__getitem__(name, blocking).sum() |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 265 | |
| 266 | def ls(self, patterns): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 267 | """Returns list of counters matching pattern""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 268 | # pylint: disable=invalid-name |
| 269 | if not self.connected: |
| 270 | self.connect() |
Ole Troan | 3daca3f | 2021-03-29 21:12:53 +0200 | [diff] [blame] | 271 | if not isinstance(patterns, list): |
| 272 | patterns = [patterns] |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 273 | regex = [re.compile(i) for i in patterns] |
Ole Troan | 43eb608 | 2021-08-31 10:47:45 +0200 | [diff] [blame] | 274 | if self.last_epoch != self.epoch: |
| 275 | self.refresh() |
| 276 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 277 | return [ |
| 278 | k |
| 279 | for k, v in self.directory.items() |
| 280 | if any(re.match(pattern, k) for pattern in regex) |
| 281 | ] |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 282 | |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 283 | def dump(self, counters, blocking=True): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 284 | """Given a list of counters return a dictionary of results""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 285 | if not self.connected: |
| 286 | self.connect() |
| 287 | result = {} |
| 288 | for cnt in counters: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 289 | result[cnt] = self.__getitem__(cnt, blocking) |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 290 | return result |
| 291 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 292 | |
| 293 | class StatsLock: |
| 294 | """Stat segment optimistic locking""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 295 | |
| 296 | def __init__(self, stats): |
| 297 | self.stats = stats |
| 298 | self.epoch = 0 |
| 299 | |
| 300 | def __enter__(self): |
| 301 | acquired = self.acquire(blocking=True) |
| 302 | assert acquired, "Lock wasn't acquired, but blocking=True" |
| 303 | return self |
| 304 | |
| 305 | def __exit__(self, exc_type=None, exc_value=None, traceback=None): |
| 306 | self.release() |
| 307 | |
| 308 | def acquire(self, blocking=True, timeout=-1): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 309 | """Acquire the lock. Await in progress to go false. Record epoch.""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 310 | self.epoch = self.stats.epoch |
| 311 | if timeout > 0: |
| 312 | start = time.monotonic() |
| 313 | while self.stats.in_progress: |
| 314 | if not blocking: |
| 315 | time.sleep(0.01) |
| 316 | if timeout > 0: |
| 317 | if start + time.monotonic() > timeout: |
| 318 | return False |
| 319 | return True |
| 320 | |
| 321 | def release(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 322 | """Check if data read while locked is valid""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 323 | if self.stats.in_progress or self.stats.epoch != self.epoch: |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 324 | raise IOError("Optimistic lock failed, retry") |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 325 | |
| 326 | def locked(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 327 | """Not used""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 328 | |
| 329 | |
| 330 | class StatsCombinedList(list): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 331 | """Column slicing for Combined counters list""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 332 | |
| 333 | def __getitem__(self, item): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 334 | """Supports partial numpy style 2d support. Slice by column [:,1]""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 335 | if isinstance(item, int): |
| 336 | return list.__getitem__(self, item) |
| 337 | return CombinedList([row[item[1]] for row in self]) |
| 338 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 339 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 340 | class CombinedList(list): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 341 | """Combined Counters 2-dimensional by thread by index of packets/octets""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 342 | |
| 343 | def packets(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 344 | """Return column (2nd dimension). Packets for all threads""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 345 | return [pair[0] for pair in self] |
| 346 | |
| 347 | def octets(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 348 | """Return column (2nd dimension). Octets for all threads""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 349 | return [pair[1] for pair in self] |
| 350 | |
| 351 | def sum_packets(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 352 | """Return column (2nd dimension). Sum of all packets for all threads""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 353 | return sum(self.packets()) |
| 354 | |
| 355 | def sum_octets(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 356 | """Return column (2nd dimension). Sum of all octets for all threads""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 357 | return sum(self.octets()) |
| 358 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 359 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 360 | class StatsTuple(tuple): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 361 | """A Combined vector tuple (packets, octets)""" |
| 362 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 363 | def __init__(self, data): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 364 | self.dictionary = {"packets": data[0], "bytes": data[1]} |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 365 | super().__init__() |
| 366 | |
| 367 | def __repr__(self): |
| 368 | return dict.__repr__(self.dictionary) |
| 369 | |
| 370 | def __getitem__(self, item): |
| 371 | if isinstance(item, int): |
| 372 | return tuple.__getitem__(self, item) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 373 | if item == "packets": |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 374 | return tuple.__getitem__(self, 0) |
| 375 | return tuple.__getitem__(self, 1) |
| 376 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 377 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 378 | class StatsSimpleList(list): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 379 | """Simple Counters 2-dimensional by thread by index of packets""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 380 | |
| 381 | def __getitem__(self, item): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 382 | """Supports partial numpy style 2d support. Slice by column [:,1]""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 383 | if isinstance(item, int): |
| 384 | return list.__getitem__(self, item) |
| 385 | return SimpleList([row[item[1]] for row in self]) |
| 386 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 387 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 388 | class SimpleList(list): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 389 | """Simple counter""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 390 | |
| 391 | def sum(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 392 | """Sum the vector""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 393 | return sum(self) |
| 394 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 395 | |
| 396 | class StatsEntry: |
| 397 | """An individual stats entry""" |
| 398 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 399 | # pylint: disable=unused-argument,no-self-use |
| 400 | |
| 401 | def __init__(self, stattype, statvalue): |
| 402 | self.type = stattype |
| 403 | self.value = statvalue |
| 404 | |
| 405 | if stattype == 1: |
| 406 | self.function = self.scalar |
| 407 | elif stattype == 2: |
| 408 | self.function = self.simple |
| 409 | elif stattype == 3: |
| 410 | self.function = self.combined |
| 411 | elif stattype == 4: |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 412 | self.function = self.name |
Damjan Marion | 66c8583 | 2022-03-14 13:04:38 +0100 | [diff] [blame] | 413 | elif stattype == 6: |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 414 | self.function = self.symlink |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 415 | else: |
| 416 | self.function = self.illegal |
| 417 | |
| 418 | def illegal(self, stats): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 419 | """Invalid or unknown counter type""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 420 | return None |
| 421 | |
| 422 | def scalar(self, stats): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 423 | """Scalar counter""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 424 | return self.value |
| 425 | |
| 426 | def simple(self, stats): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 427 | """Simple counter""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 428 | counter = StatsSimpleList() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 429 | for threads in StatsVector(stats, self.value, "P"): |
| 430 | clist = [v[0] for v in StatsVector(stats, threads[0], "Q")] |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 431 | counter.append(clist) |
| 432 | return counter |
| 433 | |
| 434 | def combined(self, stats): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 435 | """Combined counter""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 436 | counter = StatsCombinedList() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 437 | for threads in StatsVector(stats, self.value, "P"): |
| 438 | clist = [StatsTuple(cnt) for cnt in StatsVector(stats, threads[0], "QQ")] |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 439 | counter.append(clist) |
| 440 | return counter |
| 441 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 442 | def name(self, stats): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 443 | """Name counter""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 444 | counter = [] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 445 | for name in StatsVector(stats, self.value, "P"): |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 446 | if name[0]: |
| 447 | counter.append(get_string(stats, name[0])) |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 448 | return counter |
| 449 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 450 | SYMLINK_FMT1 = Struct("II") |
| 451 | SYMLINK_FMT2 = Struct("Q") |
| 452 | |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 453 | def symlink(self, stats): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 454 | """Symlink counter""" |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 455 | b = self.SYMLINK_FMT2.pack(self.value) |
| 456 | index1, index2 = self.SYMLINK_FMT1.unpack(b) |
| 457 | name = stats.directory_by_idx[index1] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 458 | return stats[name][:, index2] |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 459 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 460 | def get_counter(self, stats): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 461 | """Return a list of counters""" |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 462 | if stats: |
| 463 | return self.function(stats) |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 464 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 465 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 466 | class TestStats(unittest.TestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 467 | """Basic statseg tests""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 468 | |
| 469 | def setUp(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 470 | """Connect to statseg""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 471 | self.stat = VPPStats() |
| 472 | self.stat.connect() |
| 473 | self.profile = cProfile.Profile() |
| 474 | self.profile.enable() |
| 475 | |
| 476 | def tearDown(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 477 | """Disconnect from statseg""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 478 | self.stat.disconnect() |
| 479 | profile = Stats(self.profile) |
| 480 | profile.strip_dirs() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 481 | profile.sort_stats("cumtime") |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 482 | profile.print_stats() |
| 483 | print("\n--->>>") |
| 484 | |
| 485 | def test_counters(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 486 | """Test access to statseg""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 487 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 488 | print("/err/abf-input-ip4/missed", self.stat["/err/abf-input-ip4/missed"]) |
| 489 | print("/sys/heartbeat", self.stat["/sys/heartbeat"]) |
| 490 | print("/if/names", self.stat["/if/names"]) |
| 491 | print("/if/rx-miss", self.stat["/if/rx-miss"]) |
| 492 | print("/if/rx-miss", self.stat["/if/rx-miss"][1]) |
| 493 | print( |
| 494 | "/nat44-ed/out2in/slowpath/drops", |
| 495 | self.stat["/nat44-ed/out2in/slowpath/drops"], |
| 496 | ) |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 497 | with self.assertRaises(KeyError): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 498 | print("NO SUCH COUNTER", self.stat["foobar"]) |
| 499 | print("/if/rx", self.stat.get_counter("/if/rx")) |
| 500 | print( |
| 501 | "/err/ethernet-input/no_error", |
| 502 | self.stat.get_counter("/err/ethernet-input/no_error"), |
| 503 | ) |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 504 | |
| 505 | def test_column(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 506 | """Test column slicing""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 507 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 508 | print("/if/rx-miss", self.stat["/if/rx-miss"]) |
| 509 | print("/if/rx", self.stat["/if/rx"]) # All interfaces for thread #1 |
| 510 | print( |
| 511 | "/if/rx thread #1", self.stat["/if/rx"][0] |
| 512 | ) # All interfaces for thread #1 |
| 513 | print( |
| 514 | "/if/rx thread #1, interface #1", self.stat["/if/rx"][0][1] |
| 515 | ) # All interfaces for thread #1 |
| 516 | print("/if/rx if_index #1", self.stat["/if/rx"][:, 1]) |
| 517 | print("/if/rx if_index #1 packets", self.stat["/if/rx"][:, 1].packets()) |
| 518 | print("/if/rx if_index #1 packets", self.stat["/if/rx"][:, 1].sum_packets()) |
| 519 | print("/if/rx if_index #1 packets", self.stat["/if/rx"][:, 1].octets()) |
| 520 | print("/if/rx-miss", self.stat["/if/rx-miss"]) |
| 521 | print("/if/rx-miss if_index #1 packets", self.stat["/if/rx-miss"][:, 1].sum()) |
| 522 | print("/if/rx if_index #1 packets", self.stat["/if/rx"][0][1]["packets"]) |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 523 | |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 524 | def test_nat44(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 525 | """Test the nat counters""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 526 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 527 | print("/nat44-ei/ha/del-event-recv", self.stat["/nat44-ei/ha/del-event-recv"]) |
| 528 | print( |
| 529 | "/err/nat44-ei-ha/pkts-processed", |
| 530 | self.stat["/err/nat44-ei-ha/pkts-processed"].sum(), |
| 531 | ) |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 532 | |
| 533 | def test_legacy(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 534 | """Legacy interface""" |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 535 | directory = self.stat.ls(["^/if", "/err/ip4-input", "/sys/node/ip4-input"]) |
| 536 | data = self.stat.dump(directory) |
| 537 | print(data) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 538 | print("Looking up sys node") |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 539 | directory = self.stat.ls(["^/sys/node"]) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 540 | print("Dumping sys node") |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 541 | data = self.stat.dump(directory) |
| 542 | print(data) |
| 543 | directory = self.stat.ls(["^/foobar"]) |
| 544 | data = self.stat.dump(directory) |
| 545 | print(data) |
| 546 | |
Ole Troan | 3daca3f | 2021-03-29 21:12:53 +0200 | [diff] [blame] | 547 | def test_sys_nodes(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 548 | """Test /sys/nodes""" |
| 549 | counters = self.stat.ls("^/sys/node") |
| 550 | print("COUNTERS:", counters) |
| 551 | print("/sys/node", self.stat.dump(counters)) |
| 552 | print("/net/route/to", self.stat["/net/route/to"]) |
Ole Troan | 3daca3f | 2021-03-29 21:12:53 +0200 | [diff] [blame] | 553 | |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 554 | def test_symlink(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 555 | """Symbolic links""" |
| 556 | print("/interface/local0/rx", self.stat["/interfaces/local0/rx"]) |
| 557 | print("/sys/nodes/unix-epoll-input", self.stat["/nodes/unix-epoll-input/calls"]) |
Arthur de Kerhor | db02380 | 2021-03-11 10:26:54 -0800 | [diff] [blame] | 558 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 559 | |
| 560 | if __name__ == "__main__": |
Ole Troan | e66443c | 2021-03-18 11:12:01 +0100 | [diff] [blame] | 561 | import cProfile |
| 562 | from pstats import Stats |
| 563 | |
| 564 | unittest.main() |