/usr/lib/python3/dist-packages/babeltrace.py is in python3-babeltrace 1.3.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 | # This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.8
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
"""
Babeltrace 1.3.2
Babeltrace is a trace viewer and converter reading and writing the
Common Trace Format (CTF). Its main use is to pretty-print CTF
traces into a human-readable text output.
To use this module, the first step is to create a TraceCollection and add a
trace to it.
"""
from sys import version_info
if version_info >= (2, 6, 0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_babeltrace', [dirname(__file__)])
except ImportError:
import _babeltrace
return _babeltrace
if fp is not None:
try:
_mod = imp.load_module('_babeltrace', fp, pathname, description)
finally:
fp.close()
return _mod
_babeltrace = swig_import_helper()
del swig_import_helper
else:
import _babeltrace
del version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
if (name == "thisown"):
return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name, None)
if method:
return method(self, value)
if (not static):
if _newclass:
object.__setattr__(self, name, value)
else:
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self, class_type, name, value):
return _swig_setattr_nondynamic(self, class_type, name, value, 0)
def _swig_getattr_nondynamic(self, class_type, name, static=1):
if (name == "thisown"):
return self.this.own()
method = class_type.__swig_getmethods__.get(name, None)
if method:
return method(self)
if (not static):
return object.__getattr__(self, name)
else:
raise AttributeError(name)
def _swig_getattr(self, class_type, name):
return _swig_getattr_nondynamic(self, class_type, name, 0)
def _swig_repr(self):
try:
strthis = "proxy of " + self.this.__repr__()
except Exception:
strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
try:
_object = object
_newclass = 1
except AttributeError:
class _object:
pass
_newclass = 0
def _bt_file_open(file_path, mode):
return _babeltrace._bt_file_open(file_path, mode)
_bt_file_open = _babeltrace._bt_file_open
def _bt_file_close(fp):
return _babeltrace._bt_file_close(fp)
_bt_file_close = _babeltrace._bt_file_close
def _bt_python_field_listcaller(ctf_event, scope):
return _babeltrace._bt_python_field_listcaller(ctf_event, scope)
_bt_python_field_listcaller = _babeltrace._bt_python_field_listcaller
def _bt_python_field_one_from_list(list, index):
return _babeltrace._bt_python_field_one_from_list(list, index)
_bt_python_field_one_from_list = _babeltrace._bt_python_field_one_from_list
def _bt_python_event_decl_listcaller(handle_id, ctx):
return _babeltrace._bt_python_event_decl_listcaller(handle_id, ctx)
_bt_python_event_decl_listcaller = _babeltrace._bt_python_event_decl_listcaller
def _bt_python_decl_one_from_list(list, index):
return _babeltrace._bt_python_decl_one_from_list(list, index)
_bt_python_decl_one_from_list = _babeltrace._bt_python_decl_one_from_list
def _by_python_field_decl_listcaller(event_decl, scope):
return _babeltrace._by_python_field_decl_listcaller(event_decl, scope)
_by_python_field_decl_listcaller = _babeltrace._by_python_field_decl_listcaller
def _bt_python_field_decl_one_from_list(list, index):
return _babeltrace._bt_python_field_decl_one_from_list(list, index)
_bt_python_field_decl_one_from_list = _babeltrace._bt_python_field_decl_one_from_list
def _bt_python_get_array_from_def(field):
return _babeltrace._bt_python_get_array_from_def(field)
_bt_python_get_array_from_def = _babeltrace._bt_python_get_array_from_def
def _bt_python_get_sequence_from_def(field):
return _babeltrace._bt_python_get_sequence_from_def(field)
_bt_python_get_sequence_from_def = _babeltrace._bt_python_get_sequence_from_def
def _bt_python_get_array_element_declaration(field):
return _babeltrace._bt_python_get_array_element_declaration(field)
_bt_python_get_array_element_declaration = _babeltrace._bt_python_get_array_element_declaration
def _bt_python_get_sequence_element_declaration(field):
return _babeltrace._bt_python_get_sequence_element_declaration(field)
_bt_python_get_sequence_element_declaration = _babeltrace._bt_python_get_sequence_element_declaration
def _bt_python_get_array_string(field):
return _babeltrace._bt_python_get_array_string(field)
_bt_python_get_array_string = _babeltrace._bt_python_get_array_string
def _bt_python_get_sequence_string(field):
return _babeltrace._bt_python_get_sequence_string(field)
_bt_python_get_sequence_string = _babeltrace._bt_python_get_sequence_string
def _bt_python_field_integer_get_signedness(field):
return _babeltrace._bt_python_field_integer_get_signedness(field)
_bt_python_field_integer_get_signedness = _babeltrace._bt_python_field_integer_get_signedness
def _bt_python_get_field_type(field):
return _babeltrace._bt_python_get_field_type(field)
_bt_python_get_field_type = _babeltrace._bt_python_get_field_type
def _bt_python_create_iter_pos():
return _babeltrace._bt_python_create_iter_pos()
_bt_python_create_iter_pos = _babeltrace._bt_python_create_iter_pos
def _bt_context_create():
return _babeltrace._bt_context_create()
_bt_context_create = _babeltrace._bt_context_create
def _bt_context_add_trace(ctx, path, format, packet_seek, stream_list, metadata):
return _babeltrace._bt_context_add_trace(ctx, path, format, packet_seek, stream_list, metadata)
_bt_context_add_trace = _babeltrace._bt_context_add_trace
def _bt_context_remove_trace(ctx, trace_id):
return _babeltrace._bt_context_remove_trace(ctx, trace_id)
_bt_context_remove_trace = _babeltrace._bt_context_remove_trace
def _bt_context_get(ctx):
return _babeltrace._bt_context_get(ctx)
_bt_context_get = _babeltrace._bt_context_get
def _bt_context_put(ctx):
return _babeltrace._bt_context_put(ctx)
_bt_context_put = _babeltrace._bt_context_put
def _bt_ctf_event_get_context(event):
return _babeltrace._bt_ctf_event_get_context(event)
_bt_ctf_event_get_context = _babeltrace._bt_ctf_event_get_context
class TraceCollection:
"""
The TraceCollection is the object that contains all currently opened traces.
"""
def __init__(self):
self._tc = _bt_context_create()
def __del__(self):
_bt_context_put(self._tc)
def add_trace(self, path, format_str):
"""
Add a trace by path to the TraceCollection.
Open a trace.
path is the path to the trace, it is not recursive.
If "path" is None, stream_list is used instead as a list
of mmap streams to open for the trace.
format is a string containing the format name in which the trace was
produced.
Return: the corresponding TraceHandle on success or None on error.
"""
ret = _bt_context_add_trace(self._tc, path, format_str, None, None, None)
if ret < 0:
return None
th = TraceHandle.__new__(TraceHandle)
th._id = ret
th._trace_collection = self
return th
def add_traces_recursive(self, path, format_str):
"""
Open a trace recursively.
Find each trace present in the subdirectory starting from the given
path, and add them to the TraceCollection.
Return a dict of TraceHandle instances (the full path is the key).
Return None on error.
"""
import os
trace_handles = {}
noTrace = True
error = False
for fullpath, dirs, files in os.walk(path):
if "metadata" in files:
trace_handle = self.add_trace(fullpath, format_str)
if trace_handle is None:
error = True
continue
trace_handles[fullpath] = trace_handle
noTrace = False
if noTrace and error:
return None
return trace_handles
def remove_trace(self, trace_handle):
"""
Remove a trace from the TraceCollection.
Effectively closing the trace.
"""
try:
_bt_context_remove_trace(self._tc, trace_handle._id)
except AttributeError:
raise TypeError("in remove_trace, "
"argument 2 must be a TraceHandle instance")
@property
def events(self):
"""
Generator function to iterate over the events of open in the current
TraceCollection.
Due to limitations of the native Babeltrace API, only one event
may be "alive" at a time (i.e. a user should never store a copy
of the events returned by this function for ulterior use). Users
shall make sure to copy the information they need from an event
before accessing the next one.
Furthermore, event objects become invalid when the generator goes
out of scope as the underlying iterator will be reclaimed. Using an
event after the the generator has gone out of scope may result in a
crash or data corruption.
"""
begin_pos_ptr = _bt_python_create_iter_pos()
end_pos_ptr = _bt_python_create_iter_pos()
begin_pos_ptr.type = SEEK_BEGIN
end_pos_ptr.type = SEEK_LAST
for event in self._events(begin_pos_ptr, end_pos_ptr):
yield event
_bt_iter_free_pos(begin_pos_ptr)
_bt_iter_free_pos(end_pos_ptr)
def events_timestamps(self, timestamp_begin, timestamp_end):
"""
Generator function to iterate over the events of open in the current
TraceCollection from timestamp_begin to timestamp_end.
"""
begin_pos_ptr = _bt_python_create_iter_pos()
end_pos_ptr = _bt_python_create_iter_pos()
begin_pos_ptr.type = end_pos_ptr.type = SEEK_TIME
begin_pos_ptr.u.seek_time = timestamp_begin
end_pos_ptr.u.seek_time = timestamp_end
for event in self._events(begin_pos_ptr, end_pos_ptr):
yield event
_bt_iter_free_pos(begin_pos_ptr)
_bt_iter_free_pos(end_pos_ptr)
@property
def timestamp_begin(self):
pos_ptr = _bt_iter_pos()
pos_ptr.type = SEEK_BEGIN
return self._timestamp_at_pos(pos_ptr)
@property
def timestamp_end(self):
pos_ptr = _bt_iter_pos()
pos_ptr.type = SEEK_LAST
return self._timestamp_at_pos(pos_ptr)
def _timestamp_at_pos(self, pos_ptr):
ctf_it_ptr = _bt_ctf_iter_create(self._tc, pos_ptr, pos_ptr)
if ctf_it_ptr is None:
raise NotImplementedError("Creation of multiple iterators is unsupported.")
ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
_bt_ctf_iter_destroy(ctf_it_ptr)
if ev_ptr is None:
return None;
def _events(self, begin_pos_ptr, end_pos_ptr):
ctf_it_ptr = _bt_ctf_iter_create(self._tc, begin_pos_ptr, end_pos_ptr)
if ctf_it_ptr is None:
raise NotImplementedError(
"Creation of multiple iterators is unsupported.")
while True:
ev_ptr = _bt_ctf_iter_read_event(ctf_it_ptr)
if ev_ptr is None:
break
ev = Event.__new__(Event)
ev._e = ev_ptr
try:
yield ev
except GeneratorExit:
break
ret = _bt_iter_next(_bt_ctf_get_iter(ctf_it_ptr))
if ret != 0:
break
_bt_ctf_iter_destroy(ctf_it_ptr)
def lookup_format(qname):
return _babeltrace.lookup_format(qname)
lookup_format = _babeltrace.lookup_format
def _bt_print_format_list(fp):
return _babeltrace._bt_print_format_list(fp)
_bt_print_format_list = _babeltrace._bt_print_format_list
def bt_register_format(format):
return _babeltrace.bt_register_format(format)
bt_register_format = _babeltrace.bt_register_format
def unregister_format(format):
return _babeltrace.unregister_format(format)
unregister_format = _babeltrace.unregister_format
def print_format_list(babeltrace_file):
"""
Print a list of available formats to file.
babeltrace_file must be a File instance opened in write mode.
"""
try:
if babeltrace_file._file is not None:
_bt_print_format_list(babeltrace_file._file)
except AttributeError:
raise TypeError("in print_format_list, "
"argument 1 must be a File instance")
def _bt_iter_create(ctx, begin_pos, end_pos):
return _babeltrace._bt_iter_create(ctx, begin_pos, end_pos)
_bt_iter_create = _babeltrace._bt_iter_create
def _bt_iter_destroy(iter):
return _babeltrace._bt_iter_destroy(iter)
_bt_iter_destroy = _babeltrace._bt_iter_destroy
def _bt_iter_next(iter):
return _babeltrace._bt_iter_next(iter)
_bt_iter_next = _babeltrace._bt_iter_next
def _bt_iter_get_pos(iter):
return _babeltrace._bt_iter_get_pos(iter)
_bt_iter_get_pos = _babeltrace._bt_iter_get_pos
def _bt_iter_free_pos(pos):
return _babeltrace._bt_iter_free_pos(pos)
_bt_iter_free_pos = _babeltrace._bt_iter_free_pos
def _bt_iter_set_pos(iter, pos):
return _babeltrace._bt_iter_set_pos(iter, pos)
_bt_iter_set_pos = _babeltrace._bt_iter_set_pos
def _bt_iter_create_time_pos(iter, timestamp):
return _babeltrace._bt_iter_create_time_pos(iter, timestamp)
_bt_iter_create_time_pos = _babeltrace._bt_iter_create_time_pos
class _bt_iter_pos(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, _bt_iter_pos, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, _bt_iter_pos, name)
__repr__ = _swig_repr
__swig_setmethods__["type"] = _babeltrace._bt_iter_pos_type_set
__swig_getmethods__["type"] = _babeltrace._bt_iter_pos_type_get
if _newclass:
type = _swig_property(_babeltrace._bt_iter_pos_type_get, _babeltrace._bt_iter_pos_type_set)
__swig_getmethods__["u"] = _babeltrace._bt_iter_pos_u_get
if _newclass:
u = _swig_property(_babeltrace._bt_iter_pos_u_get)
def __init__(self):
this = _babeltrace.new__bt_iter_pos()
try:
self.this.append(this)
except Exception:
self.this = this
__swig_destroy__ = _babeltrace.delete__bt_iter_pos
__del__ = lambda self: None
_bt_iter_pos_swigregister = _babeltrace._bt_iter_pos_swigregister
_bt_iter_pos_swigregister(_bt_iter_pos)
_babeltrace.SEEK_TIME_swigconstant(_babeltrace)
SEEK_TIME = _babeltrace.SEEK_TIME
_babeltrace.SEEK_RESTORE_swigconstant(_babeltrace)
SEEK_RESTORE = _babeltrace.SEEK_RESTORE
_babeltrace.SEEK_CUR_swigconstant(_babeltrace)
SEEK_CUR = _babeltrace.SEEK_CUR
_babeltrace.SEEK_BEGIN_swigconstant(_babeltrace)
SEEK_BEGIN = _babeltrace.SEEK_BEGIN
_babeltrace.SEEK_LAST_swigconstant(_babeltrace)
SEEK_LAST = _babeltrace.SEEK_LAST
class bt_iter_pos_u(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, bt_iter_pos_u, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, bt_iter_pos_u, name)
__repr__ = _swig_repr
__swig_setmethods__["seek_time"] = _babeltrace.bt_iter_pos_u_seek_time_set
__swig_getmethods__["seek_time"] = _babeltrace.bt_iter_pos_u_seek_time_get
if _newclass:
seek_time = _swig_property(_babeltrace.bt_iter_pos_u_seek_time_get, _babeltrace.bt_iter_pos_u_seek_time_set)
__swig_setmethods__["restore"] = _babeltrace.bt_iter_pos_u_restore_set
__swig_getmethods__["restore"] = _babeltrace.bt_iter_pos_u_restore_get
if _newclass:
restore = _swig_property(_babeltrace.bt_iter_pos_u_restore_get, _babeltrace.bt_iter_pos_u_restore_set)
def __init__(self):
this = _babeltrace.new_bt_iter_pos_u()
try:
self.this.append(this)
except Exception:
self.this = this
__swig_destroy__ = _babeltrace.delete_bt_iter_pos_u
__del__ = lambda self: None
bt_iter_pos_u_swigregister = _babeltrace.bt_iter_pos_u_swigregister
bt_iter_pos_u_swigregister(bt_iter_pos_u)
def _bt_trace_handle_create(ctx):
return _babeltrace._bt_trace_handle_create(ctx)
_bt_trace_handle_create = _babeltrace._bt_trace_handle_create
def _bt_trace_handle_destroy(bt):
return _babeltrace._bt_trace_handle_destroy(bt)
_bt_trace_handle_destroy = _babeltrace._bt_trace_handle_destroy
def _bt_trace_handle_get_path(ctx, handle_id):
return _babeltrace._bt_trace_handle_get_path(ctx, handle_id)
_bt_trace_handle_get_path = _babeltrace._bt_trace_handle_get_path
def _bt_trace_handle_get_timestamp_begin(ctx, handle_id, type):
return _babeltrace._bt_trace_handle_get_timestamp_begin(ctx, handle_id, type)
_bt_trace_handle_get_timestamp_begin = _babeltrace._bt_trace_handle_get_timestamp_begin
def _bt_trace_handle_get_timestamp_end(ctx, handle_id, type):
return _babeltrace._bt_trace_handle_get_timestamp_end(ctx, handle_id, type)
_bt_trace_handle_get_timestamp_end = _babeltrace._bt_trace_handle_get_timestamp_end
def _bt_ctf_event_get_handle_id(event):
return _babeltrace._bt_ctf_event_get_handle_id(event)
_bt_ctf_event_get_handle_id = _babeltrace._bt_ctf_event_get_handle_id
# Based on enum bt_clock_type in clock-type.h
class ClockType:
CLOCK_CYCLES = 0
CLOCK_REAL = 1
class TraceHandle(object):
"""
The TraceHandle allows the user to manipulate a trace file directly.
It is a unique identifier representing a trace file.
Do not instantiate.
"""
def __init__(self):
raise NotImplementedError("TraceHandle cannot be instantiated")
def __repr__(self):
return "Babeltrace TraceHandle: trace_id('{0}')".format(self._id)
@property
def id(self):
"""Return the TraceHandle id."""
return self._id
@property
def path(self):
"""Return the path of a TraceHandle."""
return _bt_trace_handle_get_path(self._trace_collection._tc, self._id)
@property
def timestamp_begin(self):
"""Return the creation time of the buffers of a trace."""
return _bt_trace_handle_get_timestamp_begin(
self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
@property
def timestamp_end(self):
"""Return the destruction timestamp of the buffers of a trace."""
return _bt_trace_handle_get_timestamp_end(
self._trace_collection._tc, self._id, ClockType.CLOCK_REAL)
@property
def events(self):
"""
Generator returning all events (EventDeclaration) in a trace.
"""
ret = _bt_python_event_decl_listcaller(self.id, self._trace_collection._tc)
if not isinstance(ret, list):
return
ptr_list, count = ret
for i in range(count):
tmp = EventDeclaration.__new__(EventDeclaration)
tmp._ed = _bt_python_decl_one_from_list(ptr_list, i)
yield tmp
def _bt_ctf_iter_create(ctx, begin_pos, end_pos):
return _babeltrace._bt_ctf_iter_create(ctx, begin_pos, end_pos)
_bt_ctf_iter_create = _babeltrace._bt_ctf_iter_create
def _bt_ctf_get_iter(iter):
return _babeltrace._bt_ctf_get_iter(iter)
_bt_ctf_get_iter = _babeltrace._bt_ctf_get_iter
def _bt_ctf_iter_destroy(iter):
return _babeltrace._bt_ctf_iter_destroy(iter)
_bt_ctf_iter_destroy = _babeltrace._bt_ctf_iter_destroy
def _bt_ctf_iter_read_event(iter):
return _babeltrace._bt_ctf_iter_read_event(iter)
_bt_ctf_iter_read_event = _babeltrace._bt_ctf_iter_read_event
def _bt_ctf_get_top_level_scope(ctf_event, scope):
return _babeltrace._bt_ctf_get_top_level_scope(ctf_event, scope)
_bt_ctf_get_top_level_scope = _babeltrace._bt_ctf_get_top_level_scope
def _bt_ctf_event_name(ctf_event):
return _babeltrace._bt_ctf_event_name(ctf_event)
_bt_ctf_event_name = _babeltrace._bt_ctf_event_name
def _bt_ctf_get_timestamp(ctf_event):
return _babeltrace._bt_ctf_get_timestamp(ctf_event)
_bt_ctf_get_timestamp = _babeltrace._bt_ctf_get_timestamp
def _bt_ctf_get_cycles(ctf_event):
return _babeltrace._bt_ctf_get_cycles(ctf_event)
_bt_ctf_get_cycles = _babeltrace._bt_ctf_get_cycles
def _bt_ctf_get_field(ctf_event, scope, field):
return _babeltrace._bt_ctf_get_field(ctf_event, scope, field)
_bt_ctf_get_field = _babeltrace._bt_ctf_get_field
def _bt_ctf_get_index(ctf_event, field, index):
return _babeltrace._bt_ctf_get_index(ctf_event, field, index)
_bt_ctf_get_index = _babeltrace._bt_ctf_get_index
def _bt_ctf_field_name(field):
return _babeltrace._bt_ctf_field_name(field)
_bt_ctf_field_name = _babeltrace._bt_ctf_field_name
def _bt_ctf_field_type(field):
return _babeltrace._bt_ctf_field_type(field)
_bt_ctf_field_type = _babeltrace._bt_ctf_field_type
def _bt_ctf_get_int_signedness(field):
return _babeltrace._bt_ctf_get_int_signedness(field)
_bt_ctf_get_int_signedness = _babeltrace._bt_ctf_get_int_signedness
def _bt_ctf_get_int_base(field):
return _babeltrace._bt_ctf_get_int_base(field)
_bt_ctf_get_int_base = _babeltrace._bt_ctf_get_int_base
def _bt_ctf_get_int_byte_order(field):
return _babeltrace._bt_ctf_get_int_byte_order(field)
_bt_ctf_get_int_byte_order = _babeltrace._bt_ctf_get_int_byte_order
def _bt_ctf_get_int_len(field):
return _babeltrace._bt_ctf_get_int_len(field)
_bt_ctf_get_int_len = _babeltrace._bt_ctf_get_int_len
def _bt_ctf_get_enum_int(field):
return _babeltrace._bt_ctf_get_enum_int(field)
_bt_ctf_get_enum_int = _babeltrace._bt_ctf_get_enum_int
def _bt_ctf_get_enum_str(field):
return _babeltrace._bt_ctf_get_enum_str(field)
_bt_ctf_get_enum_str = _babeltrace._bt_ctf_get_enum_str
def _bt_ctf_get_encoding(field):
return _babeltrace._bt_ctf_get_encoding(field)
_bt_ctf_get_encoding = _babeltrace._bt_ctf_get_encoding
def _bt_ctf_get_array_len(field):
return _babeltrace._bt_ctf_get_array_len(field)
_bt_ctf_get_array_len = _babeltrace._bt_ctf_get_array_len
def _bt_array_index(array, i):
return _babeltrace._bt_array_index(array, i)
_bt_array_index = _babeltrace._bt_array_index
def _bt_ctf_get_uint64(field):
return _babeltrace._bt_ctf_get_uint64(field)
_bt_ctf_get_uint64 = _babeltrace._bt_ctf_get_uint64
def _bt_ctf_get_int64(field):
return _babeltrace._bt_ctf_get_int64(field)
_bt_ctf_get_int64 = _babeltrace._bt_ctf_get_int64
def _bt_ctf_get_char_array(field):
return _babeltrace._bt_ctf_get_char_array(field)
_bt_ctf_get_char_array = _babeltrace._bt_ctf_get_char_array
def _bt_ctf_get_string(field):
return _babeltrace._bt_ctf_get_string(field)
_bt_ctf_get_string = _babeltrace._bt_ctf_get_string
def _bt_ctf_get_float(field):
return _babeltrace._bt_ctf_get_float(field)
_bt_ctf_get_float = _babeltrace._bt_ctf_get_float
def _bt_ctf_get_variant(field):
return _babeltrace._bt_ctf_get_variant(field)
_bt_ctf_get_variant = _babeltrace._bt_ctf_get_variant
def _bt_ctf_field_get_error():
return _babeltrace._bt_ctf_field_get_error()
_bt_ctf_field_get_error = _babeltrace._bt_ctf_field_get_error
def _bt_ctf_get_decl_event_name(event):
return _babeltrace._bt_ctf_get_decl_event_name(event)
_bt_ctf_get_decl_event_name = _babeltrace._bt_ctf_get_decl_event_name
def _bt_ctf_get_decl_field_name(field):
return _babeltrace._bt_ctf_get_decl_field_name(field)
_bt_ctf_get_decl_field_name = _babeltrace._bt_ctf_get_decl_field_name
def _bt_ctf_get_decl_from_def(field):
return _babeltrace._bt_ctf_get_decl_from_def(field)
_bt_ctf_get_decl_from_def = _babeltrace._bt_ctf_get_decl_from_def
def _bt_ctf_get_decl_from_field_decl(field):
return _babeltrace._bt_ctf_get_decl_from_field_decl(field)
_bt_ctf_get_decl_from_field_decl = _babeltrace._bt_ctf_get_decl_from_field_decl
def _bt_sequence_len(sequence):
return _babeltrace._bt_sequence_len(sequence)
_bt_sequence_len = _babeltrace._bt_sequence_len
def _bt_sequence_index(sequence, i):
return _babeltrace._bt_sequence_index(sequence, i)
_bt_sequence_index = _babeltrace._bt_sequence_index
def _bt_ctf_get_struct_field_count(structure):
return _babeltrace._bt_ctf_get_struct_field_count(structure)
_bt_ctf_get_struct_field_count = _babeltrace._bt_ctf_get_struct_field_count
def _bt_ctf_get_struct_field_index(structure, i):
return _babeltrace._bt_ctf_get_struct_field_index(structure, i)
_bt_ctf_get_struct_field_index = _babeltrace._bt_ctf_get_struct_field_index
class CTFStringEncoding:
NONE = 0
UTF8 = 1
ASCII = 2
UNKNOWN = 3
# Based on the enum in ctf-writer/writer.h
class ByteOrder:
BYTE_ORDER_NATIVE = 0
BYTE_ORDER_LITTLE_ENDIAN = 1
BYTE_ORDER_BIG_ENDIAN = 2
BYTE_ORDER_NETWORK = 3
BYTE_ORDER_UNKNOWN = 4 # Python-specific entry
#enum equivalent, accessible constants
#These are taken directly from ctf/events.h
#All changes to enums must also be made here
class CTFTypeId:
UNKNOWN = 0
INTEGER = 1
FLOAT = 2
ENUM = 3
STRING = 4
STRUCT = 5
UNTAGGED_VARIANT = 6
VARIANT = 7
ARRAY = 8
SEQUENCE = 9
NR_CTF_TYPES = 10
def type_name(id):
name = "UNKNOWN_TYPE"
constants = [attr for attr in dir(CTFTypeId) if not callable(getattr(CTFTypeId, attr)) and not attr.startswith("__")]
for attr in constants:
if getattr(CTFTypeId, attr) == id:
name = attr
break
return name
class CTFScope:
TRACE_PACKET_HEADER = 0
STREAM_PACKET_CONTEXT = 1
STREAM_EVENT_HEADER = 2
STREAM_EVENT_CONTEXT = 3
EVENT_CONTEXT = 4
EVENT_FIELDS = 5
def scope_name(scope):
name = "UNKNOWN_SCOPE"
constants = [attr for attr in dir(CTFScope) if not callable(getattr(CTFScope, attr)) and not attr.startswith("__")]
for attr in constants:
if getattr(CTFScope, attr) == scope:
name = attr
break
return name
# Priority of the scopes when searching for event fields
_scopes = [CTFScope.EVENT_FIELDS, CTFScope.EVENT_CONTEXT, CTFScope.STREAM_EVENT_CONTEXT,
CTFScope.STREAM_EVENT_HEADER, CTFScope.STREAM_PACKET_CONTEXT, CTFScope.TRACE_PACKET_HEADER]
import collections
class Event(collections.Mapping):
"""
This class represents an event from the trace.
It is obtained using the TraceCollection generator functions.
Do not instantiate.
"""
def __init__(self):
raise NotImplementedError("Event cannot be instantiated")
@property
def name(self):
"""Return the name of the event or None on error."""
return _bt_ctf_event_name(self._e)
@property
def cycles(self):
"""
Return the timestamp of the event as written in
the packet (in cycles) or -1ULL on error.
"""
return _bt_ctf_get_cycles(self._e)
@property
def timestamp(self):
"""
Return the timestamp of the event offset with the
system clock source or -1ULL on error.
"""
return _bt_ctf_get_timestamp(self._e)
def field_with_scope(self, field_name, scope):
"""
Get field_name's value in scope.
None is returned if no field matches field_name.
"""
if not scope in _scopes:
raise ValueError("Invalid scope provided")
field = self._field_with_scope(field_name, scope)
if field is not None:
return field.value
return None
def field_list_with_scope(self, scope):
"""Return a list of field names in scope."""
if not scope in _scopes:
raise ValueError("Invalid scope provided")
field_names = []
for field in self._field_list_with_scope(scope):
field_names.append(field.name)
return field_names
@property
def handle(self):
"""
Get the TraceHandle associated with this event
Return None on error
"""
ret = _bt_ctf_event_get_handle_id(self._e)
if ret < 0:
return None
th = TraceHandle.__new__(TraceHandle)
th._id = ret
th._trace_collection = self.get_trace_collection()
return th
@property
def trace_collection(self):
"""
Get the TraceCollection associated with this event.
Return None on error.
"""
trace_collection = TraceCollection()
trace_collection._tc = _bt_ctf_event_get_context(self._e);
if trace_collection._tc is None:
return None
else:
return trace_collection
def __getitem__(self, field_name):
"""
Get field_name's value. If the field_name exists in multiple
scopes, the first field found is returned. The scopes are searched
in the following order:
1) EVENT_FIELDS
2) EVENT_CONTEXT
3) STREAM_EVENT_CONTEXT
4) STREAM_EVENT_HEADER
5) STREAM_PACKET_CONTEXT
6) TRACE_PACKET_HEADER
None is returned if no field matches field_name.
Use field_with_scope() to explicitly access fields in a given
scope.
"""
field = self._field(field_name)
if field is not None:
return field.value
raise KeyError(field_name)
def __iter__(self):
for key in self.keys():
yield key
def __len__(self):
count = 0
for scope in _scopes:
scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
ret = _bt_python_field_listcaller(self._e, scope_ptr)
if isinstance(ret, list):
count += ret[1]
return count
def __contains__(self, field_name):
return self._field(field_name) is not None
def keys(self):
"""Return a list of field names."""
field_names = set()
for scope in _scopes:
for name in self.field_list_with_scope(scope):
field_names.add(name)
return list(field_names)
def get(self, field_name, default = None):
field = self._field(field_name)
if field is None:
return default
return field.value
def items(self):
for field in self.keys():
yield (field, self[field])
def _field_with_scope(self, field_name, scope):
scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
if scope_ptr is None:
return None
definition_ptr = _bt_ctf_get_field(self._e, scope_ptr, field_name)
if definition_ptr is None:
return None
field = _Definition(definition_ptr, scope)
return field
def _field(self, field_name):
field = None
for scope in _scopes:
field = self._field_with_scope(field_name, scope)
if field is not None:
break
return field
def _field_list_with_scope(self, scope):
fields = []
scope_ptr = _bt_ctf_get_top_level_scope(self._e, scope)
# Returns a list [list_ptr, count]. If list_ptr is NULL, SWIG will only
# provide the "count" return value
count = 0
list_ptr = None
ret = _bt_python_field_listcaller(self._e, scope_ptr)
if isinstance(ret, list):
list_ptr, count = ret
for i in range(count):
definition_ptr = _bt_python_field_one_from_list(list_ptr, i)
if definition_ptr is not None:
definition = _Definition(definition_ptr, scope)
fields.append(definition)
return fields
class FieldError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
class EventDeclaration(object):
"""Event declaration class. Do not instantiate."""
def __init__(self):
raise NotImplementedError("EventDeclaration cannot be instantiated")
@property
def name(self):
"""Return the name of the event or None on error"""
return _bt_ctf_get_decl_event_name(self._ed)
@property
def fields(self):
"""
Generator returning all FieldDeclarations of an event, going through
each scope in the following order:
1) EVENT_FIELDS
2) EVENT_CONTEXT
3) STREAM_EVENT_CONTEXT
4) STREAM_EVENT_HEADER
5) STREAM_PACKET_CONTEXT
6) TRACE_PACKET_HEADER
"""
for scope in _scopes:
for declaration in self.fields_scope(scope):
yield declaration
def fields_scope(self, scope):
"""
Generator returning FieldDeclarations of the current event in scope.
"""
ret = _by_python_field_decl_listcaller(self._ed, scope)
if not isinstance(ret, list):
return
list_ptr, count = ret
for i in range(count):
field_declaration_ptr = _bt_python_field_decl_one_from_list(list_ptr, i)
if field_declaration_ptr is not None:
declaration_ptr = _bt_ctf_get_decl_from_field_decl(field_declaration_ptr)
field_declaration = _create_field_declaration(declaration_ptr, _bt_ctf_get_decl_field_name(field_declaration_ptr), scope)
yield field_declaration
class FieldDeclaration(object):
"""Field declaration class. Do not instantiate."""
def __init__(self):
raise NotImplementedError("FieldDeclaration cannot be instantiated")
def __repr__(self):
return "({0}) {1} {2}".format(CTFScope.scope_name(self.scope), CTFTypeId.type_name(self.type), self.name)
@property
def name(self):
"""Return the name of a FieldDeclaration or None on error."""
return self._name
@property
def type(self):
"""
Return the FieldDeclaration's type. One of the entries in class
CTFTypeId.
"""
return _bt_ctf_field_type(self._fd)
@property
def scope(self):
"""
Return the FieldDeclaration's scope.
"""
return self._s
class IntegerFieldDeclaration(FieldDeclaration):
"""Do not instantiate."""
def __init__(self):
raise NotImplementedError("IntegerFieldDeclaration cannot be instantiated")
@property
def signedness(self):
"""
Return the signedness of an integer:
0 if unsigned; 1 if signed; -1 on error.
"""
return _bt_ctf_get_int_signedness(self._fd)
@property
def base(self):
"""Return the base of an int or a negative value on error."""
return _bt_ctf_get_int_base(self._fd)
@property
def byte_order(self):
"""
Return the byte order. One of class ByteOrder's entries.
"""
ret = _bt_ctf_get_int_byte_order(self._fd)
if ret == 1234:
return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
elif ret == 4321:
return ByteOrder.BYTE_ORDER_BIG_ENDIAN
else:
return ByteOrder.BYTE_ORDER_UNKNOWN
@property
def length(self):
"""
Return the size, in bits, of an int or a negative
value on error.
"""
return _bt_ctf_get_int_len(self._fd)
@property
def encoding(self):
"""
Return the encoding. One of class CTFStringEncoding's entries.
Return a negative value on error.
"""
return _bt_ctf_get_encoding(self._fd)
class EnumerationFieldDeclaration(FieldDeclaration):
"""Do not instantiate."""
def __init__(self):
raise NotImplementedError("EnumerationFieldDeclaration cannot be instantiated")
class ArrayFieldDeclaration(FieldDeclaration):
"""Do not instantiate."""
def __init__(self):
raise NotImplementedError("ArrayFieldDeclaration cannot be instantiated")
@property
def length(self):
"""
Return the length of an array or a negative
value on error.
"""
return _bt_ctf_get_array_len(self._fd)
@property
def element_declaration(self):
"""
Return element declaration.
"""
field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
return _create_field_declaration(field_decl_ptr, "", self.scope)
class SequenceFieldDeclaration(FieldDeclaration):
"""Do not instantiate."""
def __init__(self):
raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
@property
def element_declaration(self):
"""
Return element declaration.
"""
field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
return _create_field_declaration(field_decl_ptr, "", self.scope)
class FloatFieldDeclaration(FieldDeclaration):
"""Do not instantiate."""
def __init__(self):
raise NotImplementedError("FloatFieldDeclaration cannot be instantiated")
class StructureFieldDeclaration(FieldDeclaration):
"""Do not instantiate."""
def __init__(self):
raise NotImplementedError("StructureFieldDeclaration cannot be instantiated")
class StringFieldDeclaration(FieldDeclaration):
"""Do not instantiate."""
def __init__(self):
raise NotImplementedError("StringFieldDeclaration cannot be instantiated")
class VariantFieldDeclaration(FieldDeclaration):
"""Do not instantiate."""
def __init__(self):
raise NotImplementedError("VariantFieldDeclaration cannot be instantiated")
def field_error():
"""
Return the last error code encountered while
accessing a field and reset the error flag.
Return 0 if no error, a negative value otherwise.
"""
return _bt_ctf_field_get_error()
def _create_field_declaration(declaration_ptr, name, scope):
"""
Private field declaration factory.
"""
if declaration_ptr is None:
raise ValueError("declaration_ptr must be valid")
if not scope in _scopes:
raise ValueError("Invalid scope provided")
type = _bt_ctf_field_type(declaration_ptr)
declaration = None
if type == CTFTypeId.INTEGER:
declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
elif type == CTFTypeId.ENUM:
declaration = EnumerationFieldDeclaration.__new__(EnumerationFieldDeclaration)
elif type == CTFTypeId.ARRAY:
declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
elif type == CTFTypeId.SEQUENCE:
declaration = SequenceFieldDeclaration.__new__(SequenceFieldDeclaration)
elif type == CTFTypeId.FLOAT:
declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
elif type == CTFTypeId.STRUCT:
declaration = StructureFieldDeclaration.__new__(StructureFieldDeclaration)
elif type == CTFTypeId.STRING:
declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
elif type == CTFTypeId.VARIANT:
declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
else:
return declaration
declaration._fd = declaration_ptr
declaration._s = scope
declaration._name = name
return declaration
class _Definition(object):
def __init__(self, definition_ptr, scope):
self._d = definition_ptr
self._s = scope
if not scope in _scopes:
ValueError("Invalid scope provided")
@property
def name(self):
"""Return the name of a field or None on error."""
return _bt_ctf_field_name(self._d)
@property
def type(self):
"""Return the type of a field or -1 if unknown."""
return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
@property
def declaration(self):
"""Return the associated Definition object."""
return _create_field_declaration(_bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
def _get_enum_str(self):
"""
Return the string matching the current enumeration.
Return None on error.
"""
return _bt_ctf_get_enum_str(self._d)
def _get_array_element_at(self, index):
"""
Return the array's element at position index.
Return None on error
"""
array_ptr = _bt_python_get_array_from_def(self._d)
if array_ptr is None:
return None
definition_ptr = _bt_array_index(array_ptr, index)
if definition_ptr is None:
return None
return _Definition(definition_ptr, self.scope)
def _get_sequence_len(self):
"""
Return the len of a sequence or a negative
value on error.
"""
seq = _bt_python_get_sequence_from_def(self._d)
return _bt_sequence_len(seq)
def _get_sequence_element_at(self, index):
"""
Return the sequence's element at position index,
otherwise return None
"""
seq = _bt_python_get_sequence_from_def(self._d)
if seq is not None:
definition_ptr = _bt_sequence_index(seq, index)
if definition_ptr is not None:
return _Definition(definition_ptr, self.scope)
return None
def _get_uint64(self):
"""
Return the value associated with the field.
If the field does not exist or is not of the type requested,
the value returned is undefined. To check if an error occured,
use the field_error() function after accessing a field.
"""
return _bt_ctf_get_uint64(self._d)
def _get_int64(self):
"""
Return the value associated with the field.
If the field does not exist or is not of the type requested,
the value returned is undefined. To check if an error occured,
use the field_error() function after accessing a field.
"""
return _bt_ctf_get_int64(self._d)
def _get_char_array(self):
"""
Return the value associated with the field.
If the field does not exist or is not of the type requested,
the value returned is undefined. To check if an error occurred,
use the field_error() function after accessing a field.
"""
return _bt_ctf_get_char_array(self._d)
def _get_str(self):
"""
Return the value associated with the field.
If the field does not exist or is not of the type requested,
the value returned is undefined. To check if an error occurred,
use the field_error() function after accessing a field.
"""
return _bt_ctf_get_string(self._d)
def _get_float(self):
"""
Return the value associated with the field.
If the field does not exist or is not of the type requested,
the value returned is undefined. To check if an error occurred,
use the field_error() function after accessing a field.
"""
return _bt_ctf_get_float(self._d)
def _get_variant(self):
"""
Return the variant's selected field.
If the field does not exist or is not of the type requested,
the value returned is undefined. To check if an error occurred,
use the field_error() function after accessing a field.
"""
return _bt_ctf_get_variant(self._d)
def _get_struct_field_count(self):
"""
Return the number of fields contained in the structure.
If the field does not exist or is not of the type requested,
the value returned is undefined.
"""
return _bt_ctf_get_struct_field_count(self._d)
def _get_struct_field_at(self, i):
"""
Return the structure's field at position i.
If the field does not exist or is not of the type requested,
the value returned is undefined. To check if an error occurred,
use the field_error() function after accessing a field.
"""
return _bt_ctf_get_struct_field_index(self._d, i)
@property
def value(self):
"""
Return the value associated with the field according to its type.
Return None on error.
"""
id = self.type
value = None
if id == CTFTypeId.STRING:
value = self._get_str()
elif id == CTFTypeId.ARRAY:
element_decl = self.declaration.element_declaration
if ((element_decl.type == CTFTypeId.INTEGER
and element_decl.length == 8)
and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
value = _bt_python_get_array_string(self._d)
else:
value = []
for i in range(self.declaration.length):
element = self._get_array_element_at(i)
value.append(element.value)
elif id == CTFTypeId.INTEGER:
if self.declaration.signedness == 0:
value = self._get_uint64()
else:
value = self._get_int64()
elif id == CTFTypeId.ENUM:
value = self._get_enum_str()
elif id == CTFTypeId.SEQUENCE:
element_decl = self.declaration.element_declaration
if ((element_decl.type == CTFTypeId.INTEGER
and element_decl.length == 8)
and (element_decl.encoding == CTFStringEncoding.ASCII or element_decl.encoding == CTFStringEncoding.UTF8)):
value = _bt_python_get_sequence_string(self._d)
else:
seq_len = self._get_sequence_len()
value = []
for i in range(seq_len):
evDef = self._get_sequence_element_at(i)
value.append(evDef.value)
elif id == CTFTypeId.FLOAT:
value = self._get_float()
elif id == CTFTypeId.VARIANT:
variant = _Definition.__new__(_Definition)
variant._d = self._get_variant();
value = variant.value
elif id == CTFTypeId.STRUCT:
value = {}
for i in range(self._get_struct_field_count()):
member = _Definition(self._get_struct_field_at(i), self.scope)
value[member.name] = member.value
if field_error():
raise FieldError("Error occurred while accessing field {} of type {}".format(self.name, CTFTypeId.type_name(id)))
return value
@property
def scope(self):
"""Return the scope of a field or None on error."""
return self._s
def _bt_ctf_clock_create(name):
return _babeltrace._bt_ctf_clock_create(name)
_bt_ctf_clock_create = _babeltrace._bt_ctf_clock_create
def _bt_ctf_clock_set_description(clock, desc):
return _babeltrace._bt_ctf_clock_set_description(clock, desc)
_bt_ctf_clock_set_description = _babeltrace._bt_ctf_clock_set_description
def _bt_ctf_clock_set_frequency(clock, freq):
return _babeltrace._bt_ctf_clock_set_frequency(clock, freq)
_bt_ctf_clock_set_frequency = _babeltrace._bt_ctf_clock_set_frequency
def _bt_ctf_clock_set_precision(clock, precision):
return _babeltrace._bt_ctf_clock_set_precision(clock, precision)
_bt_ctf_clock_set_precision = _babeltrace._bt_ctf_clock_set_precision
def _bt_ctf_clock_set_offset_s(clock, offset_s):
return _babeltrace._bt_ctf_clock_set_offset_s(clock, offset_s)
_bt_ctf_clock_set_offset_s = _babeltrace._bt_ctf_clock_set_offset_s
def _bt_ctf_clock_set_offset(clock, offset):
return _babeltrace._bt_ctf_clock_set_offset(clock, offset)
_bt_ctf_clock_set_offset = _babeltrace._bt_ctf_clock_set_offset
def _bt_ctf_clock_set_is_absolute(clock, is_absolute):
return _babeltrace._bt_ctf_clock_set_is_absolute(clock, is_absolute)
_bt_ctf_clock_set_is_absolute = _babeltrace._bt_ctf_clock_set_is_absolute
def _bt_ctf_clock_set_time(clock, time):
return _babeltrace._bt_ctf_clock_set_time(clock, time)
_bt_ctf_clock_set_time = _babeltrace._bt_ctf_clock_set_time
def _bt_ctf_clock_get(clock):
return _babeltrace._bt_ctf_clock_get(clock)
_bt_ctf_clock_get = _babeltrace._bt_ctf_clock_get
def _bt_ctf_clock_put(clock):
return _babeltrace._bt_ctf_clock_put(clock)
_bt_ctf_clock_put = _babeltrace._bt_ctf_clock_put
def _bt_ctf_field_type_integer_create(size):
return _babeltrace._bt_ctf_field_type_integer_create(size)
_bt_ctf_field_type_integer_create = _babeltrace._bt_ctf_field_type_integer_create
def _bt_ctf_field_type_integer_set_signed(integer, is_signed):
return _babeltrace._bt_ctf_field_type_integer_set_signed(integer, is_signed)
_bt_ctf_field_type_integer_set_signed = _babeltrace._bt_ctf_field_type_integer_set_signed
def _bt_ctf_field_type_integer_set_base(integer, base):
return _babeltrace._bt_ctf_field_type_integer_set_base(integer, base)
_bt_ctf_field_type_integer_set_base = _babeltrace._bt_ctf_field_type_integer_set_base
def _bt_ctf_field_type_integer_set_encoding(integer, encoding):
return _babeltrace._bt_ctf_field_type_integer_set_encoding(integer, encoding)
_bt_ctf_field_type_integer_set_encoding = _babeltrace._bt_ctf_field_type_integer_set_encoding
def _bt_ctf_field_type_enumeration_create(integer_container_type):
return _babeltrace._bt_ctf_field_type_enumeration_create(integer_container_type)
_bt_ctf_field_type_enumeration_create = _babeltrace._bt_ctf_field_type_enumeration_create
def _bt_ctf_field_type_enumeration_add_mapping(enumeration, string, range_start, range_end):
return _babeltrace._bt_ctf_field_type_enumeration_add_mapping(enumeration, string, range_start, range_end)
_bt_ctf_field_type_enumeration_add_mapping = _babeltrace._bt_ctf_field_type_enumeration_add_mapping
def _bt_ctf_field_type_floating_point_create():
return _babeltrace._bt_ctf_field_type_floating_point_create()
_bt_ctf_field_type_floating_point_create = _babeltrace._bt_ctf_field_type_floating_point_create
def _bt_ctf_field_type_floating_point_set_exponent_digits(floating_point, exponent_digits):
return _babeltrace._bt_ctf_field_type_floating_point_set_exponent_digits(floating_point, exponent_digits)
_bt_ctf_field_type_floating_point_set_exponent_digits = _babeltrace._bt_ctf_field_type_floating_point_set_exponent_digits
def _bt_ctf_field_type_floating_point_set_mantissa_digits(floating_point, mantissa_digits):
return _babeltrace._bt_ctf_field_type_floating_point_set_mantissa_digits(floating_point, mantissa_digits)
_bt_ctf_field_type_floating_point_set_mantissa_digits = _babeltrace._bt_ctf_field_type_floating_point_set_mantissa_digits
def _bt_ctf_field_type_structure_create():
return _babeltrace._bt_ctf_field_type_structure_create()
_bt_ctf_field_type_structure_create = _babeltrace._bt_ctf_field_type_structure_create
def _bt_ctf_field_type_structure_add_field(structure, field_type, field_name):
return _babeltrace._bt_ctf_field_type_structure_add_field(structure, field_type, field_name)
_bt_ctf_field_type_structure_add_field = _babeltrace._bt_ctf_field_type_structure_add_field
def _bt_ctf_field_type_variant_create(enum_tag, tag_name):
return _babeltrace._bt_ctf_field_type_variant_create(enum_tag, tag_name)
_bt_ctf_field_type_variant_create = _babeltrace._bt_ctf_field_type_variant_create
def _bt_ctf_field_type_variant_add_field(variant, field_type, field_name):
return _babeltrace._bt_ctf_field_type_variant_add_field(variant, field_type, field_name)
_bt_ctf_field_type_variant_add_field = _babeltrace._bt_ctf_field_type_variant_add_field
def _bt_ctf_field_type_array_create(element_type, length):
return _babeltrace._bt_ctf_field_type_array_create(element_type, length)
_bt_ctf_field_type_array_create = _babeltrace._bt_ctf_field_type_array_create
def _bt_ctf_field_type_sequence_create(element_type, length_field_name):
return _babeltrace._bt_ctf_field_type_sequence_create(element_type, length_field_name)
_bt_ctf_field_type_sequence_create = _babeltrace._bt_ctf_field_type_sequence_create
def _bt_ctf_field_type_string_create():
return _babeltrace._bt_ctf_field_type_string_create()
_bt_ctf_field_type_string_create = _babeltrace._bt_ctf_field_type_string_create
def _bt_ctf_field_type_string_set_encoding(string, encoding):
return _babeltrace._bt_ctf_field_type_string_set_encoding(string, encoding)
_bt_ctf_field_type_string_set_encoding = _babeltrace._bt_ctf_field_type_string_set_encoding
def _bt_ctf_field_type_set_alignment(type, alignment):
return _babeltrace._bt_ctf_field_type_set_alignment(type, alignment)
_bt_ctf_field_type_set_alignment = _babeltrace._bt_ctf_field_type_set_alignment
def _bt_ctf_field_type_set_byte_order(type, byte_order):
return _babeltrace._bt_ctf_field_type_set_byte_order(type, byte_order)
_bt_ctf_field_type_set_byte_order = _babeltrace._bt_ctf_field_type_set_byte_order
def _bt_ctf_field_type_get(type):
return _babeltrace._bt_ctf_field_type_get(type)
_bt_ctf_field_type_get = _babeltrace._bt_ctf_field_type_get
def _bt_ctf_field_type_put(type):
return _babeltrace._bt_ctf_field_type_put(type)
_bt_ctf_field_type_put = _babeltrace._bt_ctf_field_type_put
def _bt_ctf_field_create(type):
return _babeltrace._bt_ctf_field_create(type)
_bt_ctf_field_create = _babeltrace._bt_ctf_field_create
def _bt_ctf_field_structure_get_field(structure, name):
return _babeltrace._bt_ctf_field_structure_get_field(structure, name)
_bt_ctf_field_structure_get_field = _babeltrace._bt_ctf_field_structure_get_field
def _bt_ctf_field_array_get_field(array, index):
return _babeltrace._bt_ctf_field_array_get_field(array, index)
_bt_ctf_field_array_get_field = _babeltrace._bt_ctf_field_array_get_field
def _bt_ctf_field_sequence_set_length(sequence, length_field):
return _babeltrace._bt_ctf_field_sequence_set_length(sequence, length_field)
_bt_ctf_field_sequence_set_length = _babeltrace._bt_ctf_field_sequence_set_length
def _bt_ctf_field_sequence_get_field(sequence, index):
return _babeltrace._bt_ctf_field_sequence_get_field(sequence, index)
_bt_ctf_field_sequence_get_field = _babeltrace._bt_ctf_field_sequence_get_field
def _bt_ctf_field_variant_get_field(variant, tag):
return _babeltrace._bt_ctf_field_variant_get_field(variant, tag)
_bt_ctf_field_variant_get_field = _babeltrace._bt_ctf_field_variant_get_field
def _bt_ctf_field_enumeration_get_container(enumeration):
return _babeltrace._bt_ctf_field_enumeration_get_container(enumeration)
_bt_ctf_field_enumeration_get_container = _babeltrace._bt_ctf_field_enumeration_get_container
def _bt_ctf_field_signed_integer_set_value(integer, value):
return _babeltrace._bt_ctf_field_signed_integer_set_value(integer, value)
_bt_ctf_field_signed_integer_set_value = _babeltrace._bt_ctf_field_signed_integer_set_value
def _bt_ctf_field_unsigned_integer_set_value(integer, value):
return _babeltrace._bt_ctf_field_unsigned_integer_set_value(integer, value)
_bt_ctf_field_unsigned_integer_set_value = _babeltrace._bt_ctf_field_unsigned_integer_set_value
def _bt_ctf_field_floating_point_set_value(floating_point, value):
return _babeltrace._bt_ctf_field_floating_point_set_value(floating_point, value)
_bt_ctf_field_floating_point_set_value = _babeltrace._bt_ctf_field_floating_point_set_value
def _bt_ctf_field_string_set_value(string, value):
return _babeltrace._bt_ctf_field_string_set_value(string, value)
_bt_ctf_field_string_set_value = _babeltrace._bt_ctf_field_string_set_value
def _bt_ctf_field_get(field):
return _babeltrace._bt_ctf_field_get(field)
_bt_ctf_field_get = _babeltrace._bt_ctf_field_get
def _bt_ctf_field_put(field):
return _babeltrace._bt_ctf_field_put(field)
_bt_ctf_field_put = _babeltrace._bt_ctf_field_put
def _bt_ctf_event_class_create(name):
return _babeltrace._bt_ctf_event_class_create(name)
_bt_ctf_event_class_create = _babeltrace._bt_ctf_event_class_create
def _bt_ctf_event_class_add_field(event_class, type, name):
return _babeltrace._bt_ctf_event_class_add_field(event_class, type, name)
_bt_ctf_event_class_add_field = _babeltrace._bt_ctf_event_class_add_field
def _bt_ctf_event_class_get(event_class):
return _babeltrace._bt_ctf_event_class_get(event_class)
_bt_ctf_event_class_get = _babeltrace._bt_ctf_event_class_get
def _bt_ctf_event_class_put(event_class):
return _babeltrace._bt_ctf_event_class_put(event_class)
_bt_ctf_event_class_put = _babeltrace._bt_ctf_event_class_put
def _bt_ctf_event_create(event_class):
return _babeltrace._bt_ctf_event_create(event_class)
_bt_ctf_event_create = _babeltrace._bt_ctf_event_create
def _bt_ctf_event_set_payload(event, name, value):
return _babeltrace._bt_ctf_event_set_payload(event, name, value)
_bt_ctf_event_set_payload = _babeltrace._bt_ctf_event_set_payload
def _bt_ctf_event_get_payload(event, name):
return _babeltrace._bt_ctf_event_get_payload(event, name)
_bt_ctf_event_get_payload = _babeltrace._bt_ctf_event_get_payload
def _bt_ctf_event_get(event):
return _babeltrace._bt_ctf_event_get(event)
_bt_ctf_event_get = _babeltrace._bt_ctf_event_get
def _bt_ctf_event_put(event):
return _babeltrace._bt_ctf_event_put(event)
_bt_ctf_event_put = _babeltrace._bt_ctf_event_put
def _bt_ctf_stream_class_create(name):
return _babeltrace._bt_ctf_stream_class_create(name)
_bt_ctf_stream_class_create = _babeltrace._bt_ctf_stream_class_create
def _bt_ctf_stream_class_set_clock(stream_class, clock):
return _babeltrace._bt_ctf_stream_class_set_clock(stream_class, clock)
_bt_ctf_stream_class_set_clock = _babeltrace._bt_ctf_stream_class_set_clock
def _bt_ctf_stream_class_add_event_class(stream_class, event_class):
return _babeltrace._bt_ctf_stream_class_add_event_class(stream_class, event_class)
_bt_ctf_stream_class_add_event_class = _babeltrace._bt_ctf_stream_class_add_event_class
def _bt_ctf_stream_class_get(stream_class):
return _babeltrace._bt_ctf_stream_class_get(stream_class)
_bt_ctf_stream_class_get = _babeltrace._bt_ctf_stream_class_get
def _bt_ctf_stream_class_put(stream_class):
return _babeltrace._bt_ctf_stream_class_put(stream_class)
_bt_ctf_stream_class_put = _babeltrace._bt_ctf_stream_class_put
def _bt_ctf_stream_append_discarded_events(stream, event_count):
return _babeltrace._bt_ctf_stream_append_discarded_events(stream, event_count)
_bt_ctf_stream_append_discarded_events = _babeltrace._bt_ctf_stream_append_discarded_events
def _bt_ctf_stream_append_event(stream, event):
return _babeltrace._bt_ctf_stream_append_event(stream, event)
_bt_ctf_stream_append_event = _babeltrace._bt_ctf_stream_append_event
def _bt_ctf_stream_flush(stream):
return _babeltrace._bt_ctf_stream_flush(stream)
_bt_ctf_stream_flush = _babeltrace._bt_ctf_stream_flush
def _bt_ctf_stream_get(stream):
return _babeltrace._bt_ctf_stream_get(stream)
_bt_ctf_stream_get = _babeltrace._bt_ctf_stream_get
def _bt_ctf_stream_put(stream):
return _babeltrace._bt_ctf_stream_put(stream)
_bt_ctf_stream_put = _babeltrace._bt_ctf_stream_put
def _bt_ctf_writer_create(path):
return _babeltrace._bt_ctf_writer_create(path)
_bt_ctf_writer_create = _babeltrace._bt_ctf_writer_create
def _bt_ctf_writer_create_stream(writer, stream_class):
return _babeltrace._bt_ctf_writer_create_stream(writer, stream_class)
_bt_ctf_writer_create_stream = _babeltrace._bt_ctf_writer_create_stream
def _bt_ctf_writer_add_environment_field(writer, name, value):
return _babeltrace._bt_ctf_writer_add_environment_field(writer, name, value)
_bt_ctf_writer_add_environment_field = _babeltrace._bt_ctf_writer_add_environment_field
def _bt_ctf_writer_add_clock(writer, clock):
return _babeltrace._bt_ctf_writer_add_clock(writer, clock)
_bt_ctf_writer_add_clock = _babeltrace._bt_ctf_writer_add_clock
def _bt_ctf_writer_get_metadata_string(writer):
return _babeltrace._bt_ctf_writer_get_metadata_string(writer)
_bt_ctf_writer_get_metadata_string = _babeltrace._bt_ctf_writer_get_metadata_string
def _bt_ctf_writer_flush_metadata(writer):
return _babeltrace._bt_ctf_writer_flush_metadata(writer)
_bt_ctf_writer_flush_metadata = _babeltrace._bt_ctf_writer_flush_metadata
def _bt_ctf_writer_set_byte_order(writer, byte_order):
return _babeltrace._bt_ctf_writer_set_byte_order(writer, byte_order)
_bt_ctf_writer_set_byte_order = _babeltrace._bt_ctf_writer_set_byte_order
def _bt_ctf_writer_get(writer):
return _babeltrace._bt_ctf_writer_get(writer)
_bt_ctf_writer_get = _babeltrace._bt_ctf_writer_get
def _bt_ctf_writer_put(writer):
return _babeltrace._bt_ctf_writer_put(writer)
_bt_ctf_writer_put = _babeltrace._bt_ctf_writer_put
class CTFWriter:
class Clock:
def __init__(self, name):
self._c = _bt_ctf_clock_create(name)
if self._c is None:
raise ValueError("Invalid clock name.")
def __del__(self):
_bt_ctf_clock_put(self._c)
"""
Get the clock's description.
"""
@property
def description(self):
raise NotImplementedError("Getter not implemented.")
"""
Set the clock's description. The description appears in the clock's TSDL
meta-data.
"""
@description.setter
def description(self, desc):
ret = _bt_ctf_clock_set_description(self._c, str(desc))
if ret < 0:
raise ValueError("Invalid clock description.")
"""
Get the clock's frequency (Hz).
"""
@property
def frequency(self):
raise NotImplementedError("Getter not implemented.")
"""
Set the clock's frequency (Hz).
"""
@frequency.setter
def frequency(self, freq):
ret = _bt_ctf_clock_set_frequency(self._c, freq)
if ret < 0:
raise ValueError("Invalid frequency value.")
"""
Get the clock's precision (in clock ticks).
"""
@property
def precision(self):
raise NotImplementedError("Getter not implemented.")
"""
Set the clock's precision (in clock ticks).
"""
@precision.setter
def precision(self, precision):
ret = _bt_ctf_clock_set_precision(self._c, precision)
"""
Get the clock's offset in seconds from POSIX.1 Epoch.
"""
@property
def offset_seconds(self):
raise NotImplementedError("Getter not implemented.")
"""
Set the clock's offset in seconds from POSIX.1 Epoch.
"""
@offset_seconds.setter
def offset_seconds(self, offset_s):
ret = _bt_ctf_clock_set_offset_s(self._c, offset_s)
if ret < 0:
raise ValueError("Invalid offset value.")
"""
Get the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
"""
@property
def offset(self):
raise NotImplementedError("Getter not implemented.")
"""
Set the clock's offset in ticks from POSIX.1 Epoch + offset in seconds.
"""
@offset.setter
def offset(self, offset):
ret = _bt_ctf_clock_set_offset(self._c, offset)
if ret < 0:
raise ValueError("Invalid offset value.")
"""
Get a clock's absolute attribute. A clock is absolute if the clock
is a global reference across the trace's other clocks.
"""
@property
def absolute(self):
raise NotImplementedError("Getter not implemented.")
"""
Set a clock's absolute attribute. A clock is absolute if the clock
is a global reference across the trace's other clocks.
"""
@absolute.setter
def absolute(self, is_absolute):
ret = _bt_ctf_clock_set_is_absolute(self._c, int(is_absolute))
if ret < 0:
raise ValueError("Could not set the clock's absolute attribute.")
"""
Get the current time in nanoseconds since the clock's origin (offset and
offset_s attributes).
"""
@property
def time(self):
raise NotImplementedError("Getter not implemented.")
"""
Set the current time in nanoseconds since the clock's origin (offset and
offset_s attributes). The clock's value will be sampled as events are
appended to a stream.
"""
@time.setter
def time(self, time):
ret = _bt_ctf_clock_set_time(self._c, time)
if ret < 0:
raise ValueError("Invalid time value.")
class FieldDeclaration:
"""
FieldDeclaration should not be instantiated directly. Please instantiate
one of the concrete FieldDeclaration classes.
"""
class IntegerBase:
# These values are based on the bt_ctf_integer_base enum
# declared in event-types.h.
INTEGER_BASE_UNKNOWN = -1
INTEGER_BASE_BINARY = 2
INTEGER_BASE_OCTAL = 8
INTEGER_BASE_DECIMAL = 10
INTEGER_BASE_HEXADECIMAL = 16
def __init__(self):
if self._ft is None:
raise ValueError("FieldDeclaration creation failed.")
def __del__(self):
_bt_ctf_field_type_put(self._ft)
"""
Get the field type's alignment.
"""
@property
def alignment(self):
raise NotImplementedError("Getter not implemented.")
"""
Set the field type's alignment. Defaults to 1 (bit-aligned). However,
some types, such as structures and string, may impose other alignment
constraints.
"""
@alignment.setter
def alignment(self, alignment):
ret = _bt_ctf_field_type_set_alignment(self._ft, alignment)
if ret < 0:
raise ValueError("Invalid alignment value.")
"""
Get the field type's byte order. One of the ByteOrder's constant.
"""
@property
def byte_order(self):
raise NotImplementedError("Getter not implemented.")
"""
Set the field type's byte order. Use constants defined in the ByteOrder
class.
"""
@byte_order.setter
def byte_order(self, byte_order):
ret = _bt_ctf_field_type_set_byte_order(self._ft, byte_order)
if ret < 0:
raise ValueError("Could not set byte order value.")
class IntegerFieldDeclaration(FieldDeclaration):
"""
Create a new integer field type of the given size.
"""
def __init__(self, size):
self._ft = _bt_ctf_field_type_integer_create(size)
super().__init__()
"""
Get an integer's signedness attribute.
"""
@property
def signed(self):
raise NotImplementedError("Getter not implemented.")
"""
Set an integer's signedness attribute.
"""
@signed.setter
def signed(self, signed):
ret = _bt_ctf_field_type_integer_set_signed(self._ft, signed)
if ret < 0:
raise ValueError("Could not set signed attribute.")
"""
Get the integer's base used to pretty-print the resulting trace.
"""
@property
def base(self):
raise NotImplementedError("Getter not implemented.")
"""
Set the integer's base used to pretty-print the resulting trace.
The base must be a constant of the IntegerBase class.
"""
@base.setter
def base(self, base):
ret = _bt_ctf_field_type_integer_set_base(self._ft, base)
if ret < 0:
raise ValueError("Could not set base value.")
"""
Get the integer's encoding (one of the constants of the
CTFStringEncoding class).
"""
@property
def encoding(self):
raise NotImplementedError("Getter not implemented.")
"""
An integer encoding may be set to signal that the integer must be printed
as a text character. Must be a constant from the CTFStringEncoding class.
"""
@encoding.setter
def encoding(self, encoding):
ret = _bt_ctf_field_type_integer_set_encoding(self._ft, encoding)
if ret < 0:
raise ValueError("Could not set integer encoding.")
class EnumerationFieldDeclaration(FieldDeclaration):
"""
Create a new enumeration field type with the given underlying type.
"""
def __init__(self, integer_type):
if integer_type is None or not isinstance(integer_type, CTFWriter.IntegerFieldDeclaration):
raise TypeError("Invalid integer container.")
self._ft = _bt_ctf_field_type_enumeration_create(integer_type._ft)
super().__init__()
"""
Add a mapping to the enumeration. The range's values are inclusive.
"""
def add_mapping(self, name, range_start, range_end):
ret = _bt_ctf_field_type_enumeration_add_mapping(self._ft, str(name), range_start, range_end)
if ret < 0:
raise ValueError("Could not add mapping to enumeration type.")
class FloatFieldDeclaration(FieldDeclaration):
FLT_EXP_DIG = 8
DBL_EXP_DIG = 11
FLT_MANT_DIG = 24
DBL_MANT_DIG = 53
"""
Create a new floating point field type.
"""
def __init__(self):
self._ft = _bt_ctf_field_type_floating_point_create()
super().__init__()
"""
Get the number of exponent digits to use to store the floating point field.
"""
@property
def exponent_digits(self):
raise NotImplementedError("Getter not implemented.")
"""
Set the number of exponent digits to use to store the floating point field.
The only values currently supported are FLT_EXP_DIG and DBL_EXP_DIG which
are defined as constants of this class.
"""
@exponent_digits.setter
def exponent_digits(self, exponent_digits):
ret = _bt_ctf_field_type_floating_point_set_exponent_digits(self._ft, exponent_digits)
if ret < 0:
raise ValueError("Could not set exponent digit count.")
"""
Get the number of mantissa digits to use to store the floating point field.
"""
@property
def mantissa_digits(self):
raise NotImplementedError("Getter not implemented.")
"""
Set the number of mantissa digits to use to store the floating point field.
The only values currently supported are FLT_MANT_DIG and DBL_MANT_DIG which
are defined as constants of this class.
"""
@mantissa_digits.setter
def mantissa_digits(self, mantissa_digits):
ret = _bt_ctf_field_type_floating_point_set_mantissa_digits(self._ft, mantissa_digits)
if ret < 0:
raise ValueError("Could not set mantissa digit count.")
class StructureFieldDeclaration(FieldDeclaration):
"""
Create a new structure field type.
"""
def __init__(self):
self._ft = _bt_ctf_field_type_structure_create()
super().__init__()
"""
Add a field of type "field_type" to the structure.
"""
def add_field(self, field_type, field_name):
ret = _bt_ctf_field_type_structure_add_field(self._ft, field_type._ft, str(field_name))
if ret < 0:
raise ValueError("Could not add field to structure.")
class VariantFieldDeclaration(FieldDeclaration):
"""
Create a new variant field type.
"""
def __init__(self, enum_tag, tag_name):
if enum_tag is None or not isinstance(enum_tag, CTFWriter.EnumerationFieldDeclaration):
raise TypeError("Invalid tag type; must be of type EnumerationFieldDeclaration.")
self._ft = _bt_ctf_field_type_variant_create(enum_tag._ft, str(tag_name))
super().__init__()
"""
Add a field of type "field_type" to the variant.
"""
def add_field(self, field_type, field_name):
ret = _bt_ctf_field_type_variant_add_field(self._ft, field_type._ft, str(field_name))
if ret < 0:
raise ValueError("Could not add field to variant.")
class ArrayFieldDeclaration(FieldDeclaration):
"""
Create a new array field type.
"""
def __init__(self, element_type, length):
self._ft = _bt_ctf_field_type_array_create(element_type._ft, length)
super().__init__()
class SequenceFieldDeclaration(FieldDeclaration):
"""
Create a new sequence field type.
"""
def __init__(self, element_type, length_field_name):
self._ft = _bt_ctf_field_type_sequence_create(element_type._ft, str(length_field_name))
super().__init__()
class StringFieldDeclaration(FieldDeclaration):
"""
Create a new string field type.
"""
def __init__(self):
self._ft = _bt_ctf_field_type_string_create()
super().__init__()
"""
Get a string type's encoding (a constant from the CTFStringEncoding class).
"""
@property
def encoding(self):
raise NotImplementedError("Getter not implemented.")
"""
Set a string type's encoding. Must be a constant from the CTFStringEncoding class.
"""
@encoding.setter
def encoding(self, encoding):
ret = _bt_ctf_field_type_string_set_encoding(self._ft, encoding)
if ret < 0:
raise ValueError("Could not set string encoding.")
"""
Create an instance of a field.
"""
@staticmethod
def create_field(self, field_type):
if field_type is None or not isinstance(field_type, CTFWriter.FieldDeclaration):
raise TypeError("Invalid field_type. Type must be a FieldDeclaration-derived class.")
if isinstance(field_type, CTFWriter.IntegerFieldDeclaration):
return CTFWriter.IntegerField(field_type)
elif isinstance(field_type, CTFWriter.EnumerationFieldDeclaration):
return CTFWriter.EnumerationField(field_type)
elif isinstance(field_type, CTFWriter.FloatFieldDeclaration):
return CTFWriter.FloatFieldingPoint(field_type)
elif isinstance(field_type, CTFWriter.StructureFieldDeclaration):
return CTFWriter.StructureField(field_type)
elif isinstance(field_type, CTFWriter.VariantFieldDeclaration):
return CTFWriter.VariantField(field_type)
elif isinstance(field_type, CTFWriter.ArrayFieldDeclaration):
return CTFWriter.ArrayField(field_type)
elif isinstance(field_type, CTFWriter.SequenceFieldDeclaration):
return CTFWriter.SequenceField(field_type)
elif isinstance(field_type, CTFWriter.StringFieldDeclaration):
return CTFWriter.StringField(field_type)
class Field:
"""
Base class, do not instantiate.
"""
def __init__(self, field_type):
if not isinstance(field_type, CTFWriter.FieldDeclaration):
raise TypeError("Invalid field_type argument.")
self._f = _bt_ctf_field_create(field_type._ft)
if self._f is None:
raise ValueError("Field creation failed.")
def __del__(self):
_bt_ctf_field_put(self._f)
@staticmethod
def _create_field_from_native_instance(native_field_instance):
type_dict = {
CTFTypeId.INTEGER : CTFWriter.IntegerField,
CTFTypeId.FLOAT : CTFWriter.FloatFieldingPoint,
CTFTypeId.ENUM : CTFWriter.EnumerationField,
CTFTypeId.STRING : CTFWriter.StringField,
CTFTypeId.STRUCT : CTFWriter.StructureField,
CTFTypeId.VARIANT : CTFWriter.VariantField,
CTFTypeId.ARRAY : CTFWriter.ArrayField,
CTFTypeId.SEQUENCE : CTFWriter.SequenceField
}
field_type = _bt_python_get_field_type(native_field_instance)
if field_type == CTFTypeId.UNKNOWN:
raise TypeError("Invalid field instance")
field = CTFWriter.Field.__new__(CTFWriter.Field)
field._f = native_field_instance
field.__class__ = type_dict[field_type]
return field
class IntegerField(Field):
"""
Get an integer field's value.
"""
@property
def value(self):
raise NotImplementedError("Getter not implemented.")
"""
Set an integer field's value.
"""
@value.setter
def value(self, value):
signedness = _bt_python_field_integer_get_signedness(self._f)
if signedness < 0:
raise TypeError("Invalid integer instance.")
if signedness == 0:
ret = _bt_ctf_field_unsigned_integer_set_value(self._f, value)
else:
ret = _bt_ctf_field_signed_integer_set_value(self._f, value)
if ret < 0:
raise ValueError("Could not set integer field value.")
class EnumerationField(Field):
"""
Return the enumeration's underlying container field (an integer field).
"""
@property
def container(self):
container = CTFWriter.IntegerField.__new__(CTFWriter.IntegerField)
container._f = _bt_ctf_field_enumeration_get_container(self._f)
if container._f is None:
raise TypeError("Invalid enumeration field type.")
return container
class FloatFieldingPoint(Field):
"""
Get a floating point field's value.
"""
@property
def value(self):
raise NotImplementedError("Getter not implemented.")
"""
Set a floating point field's value.
"""
@value.setter
def value(self, value):
ret = _bt_ctf_field_floating_point_set_value(self._f, float(value))
if ret < 0:
raise ValueError("Could not set floating point field value.")
class StructureField(Field):
"""
Get the structure's field corresponding to the provided field name.
"""
def field(self, field_name):
native_instance = _bt_ctf_field_structure_get_field(self._f, str(field_name))
if native_instance is None:
raise ValueError("Invalid field_name provided.")
return CTFWriter.Field._create_field_from_native_instance(native_instance)
class VariantField(Field):
"""
Return the variant's selected field. The "tag" field is the selector enum field.
"""
def field(self, tag):
native_instance = _bt_ctf_field_variant_get_field(self._f, tag._f)
if native_instance is None:
raise ValueError("Invalid tag provided.")
return CTFWriter.Field._create_field_from_native_instance(native_instance)
class ArrayField(Field):
"""
Return the array's field at position "index".
"""
def field(self, index):
native_instance = _bt_ctf_field_array_get_field(self._f, index)
if native_instance is None:
raise IndexError("Invalid index provided.")
return CTFWriter.Field._create_field_from_native_instance(native_instance)
class SequenceField(Field):
"""
Get the sequence's length field (IntegerField).
"""
@property
def length(self):
raise NotImplementedError("Getter not implemented.")
"""
Set the sequence's length field (IntegerField).
"""
@length.setter
def length(self, length_field):
if not isinstance(length_field, CTFWriter.IntegerField):
raise TypeError("Invalid length field.")
ret = _bt_ctf_field_sequence_set_length(self._f, length_field._f)
if ret < 0:
raise ValueError("Could not set sequence length.")
"""
Return the sequence's field at position "index".
"""
def field(self, index):
native_instance = _bt_ctf_field_sequence_get_field(self._f, index)
if native_instance is None:
raise ValueError("Could not get sequence element at index.")
return CTFWriter.Field._create_field_from_native_instance(native_instance)
class StringField(Field):
"""
Get a string field's value.
"""
@property
def value(self):
raise NotImplementedError("Getter not implemented.")
"""
Set a string field's value.
"""
@value.setter
def value(self, value):
ret = _bt_ctf_field_string_set_value(self._f, str(value))
if ret < 0:
raise ValueError("Could not set string field value.")
class EventClass:
"""
Create a new event class of the given name.
"""
def __init__(self, name):
self._ec = _bt_ctf_event_class_create(name)
if self._ec is None:
raise ValueError("Event class creation failed.")
def __del__(self):
_bt_ctf_event_class_put(self._ec)
"""
Add a field of type "field_type" to the event class.
"""
def add_field(self, field_type, field_name):
ret = _bt_ctf_event_class_add_field(self._ec, field_type._ft, str(field_name))
if ret < 0:
raise ValueError("Could not add field to event class.")
class Event:
"""
Create a new event of the given event class.
"""
def __init__(self, event_class):
if not isinstance(event_class, CTFWriter.EventClass):
raise TypeError("Invalid event_class argument.")
self._e = _bt_ctf_event_create(event_class._ec)
if self._e is None:
raise ValueError("Event creation failed.")
def __del__(self):
_bt_ctf_event_put(self._e)
"""
Set a manually created field as an event's payload.
"""
def set_payload(self, field_name, value_field):
if not isinstance(value, CTFWriter.Field):
raise TypeError("Invalid value type.")
ret = _bt_ctf_event_set_payload(self._e, str(field_name), value_field._f)
if ret < 0:
raise ValueError("Could not set event field payload.")
"""
Get a field from event.
"""
def payload(self, field_name):
native_instance = _bt_ctf_event_get_payload(self._e, str(field_name))
if native_instance is None:
raise ValueError("Could not get event payload.")
return CTFWriter.Field._create_field_from_native_instance(native_instance)
class StreamClass:
"""
Create a new stream class of the given name.
"""
def __init__(self, name):
self._sc = _bt_ctf_stream_class_create(name)
if self._sc is None:
raise ValueError("Stream class creation failed.")
def __del__(self):
_bt_ctf_stream_class_put(self._sc)
"""
Get a stream class' clock.
"""
@property
def clock(self):
raise NotImplementedError("Getter not implemented.")
"""
Assign a clock to a stream class.
"""
@clock.setter
def clock(self, clock):
if not isinstance(clock, CTFWriter.Clock):
raise TypeError("Invalid clock type.")
ret = _bt_ctf_stream_class_set_clock(self._sc, clock._c)
if ret < 0:
raise ValueError("Could not set stream class clock.")
"""
Add an event class to a stream class. New events can be added even after a
stream has been instantiated and events have been appended. However, a stream
will not accept events of a class that has not been registered beforehand.
"""
def add_event_class(self, event_class):
if not isinstance(event_class, CTFWriter.EventClass):
raise TypeError("Invalid event_class type.")
ret = _bt_ctf_stream_class_add_event_class(self._sc, event_class._ec)
if ret < 0:
raise ValueError("Could not add event class.")
class Stream:
"""
Create a stream of the given class.
"""
def __init__(self, stream_class):
if not isinstance(stream_class, CTFWriter.StreamClass):
raise TypeError("Invalid stream_class type.")
self._s = _bt_ctf_stream_create(stream_class._sc)
if self._s is None:
raise ValueError("Stream creation failed.")
def __del__(self):
_bt_ctf_stream_put(self._s)
"""
Increase the current packet's discarded event count.
"""
def append_discarded_events(self, event_count):
_bt_ctf_stream_append_discarded_events(self._s, event_count)
"""
Append "event" to the stream's current packet. The stream's associated clock
will be sampled during this call. The event shall not be modified after
being appended to a stream.
"""
def append_event(self, event):
ret = _bt_ctf_stream_append_event(self._s, event._e)
if ret < 0:
raise ValueError("Could not append event to stream.")
"""
The stream's current packet's events will be flushed to disk. Events
subsequently appended to the stream will be added to a new packet.
"""
def flush(self):
ret = _bt_ctf_stream_flush(self._s)
if ret < 0:
raise ValueError("Could not flush stream.")
class Writer:
"""
Create a new writer that will produce a trace in the given path.
"""
def __init__(self, path):
self._w = _bt_ctf_writer_create(path)
if self._w is None:
raise ValueError("Writer creation failed.")
def __del__(self):
_bt_ctf_writer_put(self._w)
"""
Create a new stream instance and register it to the writer.
"""
def create_stream(self, stream_class):
if not isinstance(stream_class, CTFWriter.StreamClass):
raise TypeError("Invalid stream_class type.")
stream = CTFWriter.Stream.__new__(CTFWriter.Stream)
stream._s = _bt_ctf_writer_create_stream(self._w, stream_class._sc)
return stream
"""
Add an environment field to the trace.
"""
def add_environment_field(self, name, value):
ret = _bt_ctf_writer_add_environment_field(self._w, str(name), str(value))
if ret < 0:
raise ValueError("Could not add environment field to trace.")
"""
Add a clock to the trace. Clocks assigned to stream classes must be
registered to the writer.
"""
def add_clock(self, clock):
ret = _bt_ctf_writer_add_clock(self._w, clock._c)
if ret < 0:
raise ValueError("Could not add clock to Writer.")
"""
Get the trace's TSDL meta-data.
"""
@property
def metadata(self):
return _bt_ctf_writer_get_metadata_string(self._w)
"""
Flush the trace's metadata to the metadata file.
"""
def flush_metadata(self):
_bt_ctf_writer_flush_metadata(self._w)
"""
Get the trace's byte order. Must be a constant from the ByteOrder
class.
"""
@property
def byte_order(self):
raise NotImplementedError("Getter not implemented.")
"""
Set the trace's byte order. Must be a constant from the ByteOrder
class. Defaults to BYTE_ORDER_NATIVE, the host machine's endianness.
"""
@byte_order.setter
def byte_order(self, byte_order):
ret = _bt_ctf_writer_set_byte_order(self._w, byte_order)
if ret < 0:
raise ValueError("Could not set trace's byte order.")
# This file is compatible with both classic and new-style classes.
|