|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": {}, |
| 6 | + "source": [ |
| 7 | + "# Riptide Logging\n", |
| 8 | + "\n", |
| 9 | + "Riptable supports logging from riptide_cpp, a C++ library that Riptable relies on for multithreaded processing of arrays and the SDS file format. This logging capability enables you to examine and understand the native functions called by Riptable." |
| 10 | + ] |
| 11 | + }, |
| 12 | + { |
| 13 | + "cell_type": "markdown", |
| 14 | + "metadata": {}, |
| 15 | + "source": [ |
| 16 | + "The following examples require you to import the following modules and functions:" |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "code", |
| 21 | + "execution_count": 1, |
| 22 | + "metadata": {}, |
| 23 | + "outputs": [], |
| 24 | + "source": [ |
| 25 | + "import riptable as rt\n", |
| 26 | + "import riptide_cpp as rc\n", |
| 27 | + "import logging\n", |
| 28 | + "import sys\n", |
| 29 | + "from riptable.rt_logging import enable_riptide_logs, disable_riptide_logs" |
| 30 | + ] |
| 31 | + }, |
| 32 | + { |
| 33 | + "cell_type": "markdown", |
| 34 | + "metadata": {}, |
| 35 | + "source": [ |
| 36 | + "View a list of available riptide_cpp loggers using `rc.GetRiptideLoggers()`:" |
| 37 | + ] |
| 38 | + }, |
| 39 | + { |
| 40 | + "cell_type": "code", |
| 41 | + "execution_count": 2, |
| 42 | + "metadata": {}, |
| 43 | + "outputs": [ |
| 44 | + { |
| 45 | + "data": { |
| 46 | + "text/plain": [ |
| 47 | + "['riptable.riptide_cpp.SDSFile',\n", |
| 48 | + " 'riptable.riptide_cpp.Recycler',\n", |
| 49 | + " 'riptable.riptide_cpp.GroupBy']" |
| 50 | + ] |
| 51 | + }, |
| 52 | + "execution_count": 2, |
| 53 | + "metadata": {}, |
| 54 | + "output_type": "execute_result" |
| 55 | + } |
| 56 | + ], |
| 57 | + "source": [ |
| 58 | + "rc.GetRiptideLoggers()" |
| 59 | + ] |
| 60 | + }, |
| 61 | + { |
| 62 | + "cell_type": "markdown", |
| 63 | + "metadata": {}, |
| 64 | + "source": [ |
| 65 | + "Logging in riptide_cpp is disabled by default. To enable logging capabilities, you must call the `enable_riptide_logs()` function from the `rt_logging` Riptable module:" |
| 66 | + ] |
| 67 | + }, |
| 68 | + { |
| 69 | + "cell_type": "code", |
| 70 | + "execution_count": 3, |
| 71 | + "metadata": {}, |
| 72 | + "outputs": [], |
| 73 | + "source": [ |
| 74 | + "enable_riptide_logs()" |
| 75 | + ] |
| 76 | + }, |
| 77 | + { |
| 78 | + "cell_type": "markdown", |
| 79 | + "metadata": {}, |
| 80 | + "source": [ |
| 81 | + "After enabling the riptide_cpp loggers, use the `logging` module from the Python standard library to configure them.\n", |
| 82 | + "\n", |
| 83 | + "\n" |
| 84 | + ] |
| 85 | + }, |
| 86 | + { |
| 87 | + "cell_type": "markdown", |
| 88 | + "metadata": {}, |
| 89 | + "source": [ |
| 90 | + "Setup an stdout handler with a custom formatter:" |
| 91 | + ] |
| 92 | + }, |
| 93 | + { |
| 94 | + "cell_type": "code", |
| 95 | + "execution_count": 4, |
| 96 | + "metadata": {}, |
| 97 | + "outputs": [], |
| 98 | + "source": [ |
| 99 | + "handler = logging.StreamHandler(sys.stdout)\n", |
| 100 | + "handler.setFormatter(logging.Formatter('%(name)s | %(levelname)s | %(message)s'))" |
| 101 | + ] |
| 102 | + }, |
| 103 | + { |
| 104 | + "cell_type": "markdown", |
| 105 | + "metadata": {}, |
| 106 | + "source": [ |
| 107 | + "Configure the SDSFile and GroupBy loggers. The Riptable and riptide_cpp loggers are in the following hierarchy:\n", |
| 108 | + "\n", |
| 109 | + "- riptable: root logger\n", |
| 110 | + " - riptable [riptable.riptable]: Logs for riptable side\n", |
| 111 | + " - rt_dataset [riptable.riptable.rt_dataset]\n", |
| 112 | + " - ...\n", |
| 113 | + " - riptide_cpp [riptable.riptide_cpp]: Logs for riptide_cpp\n", |
| 114 | + " - SDSFile [riptable.riptide_cpp.SDSFile]\n", |
| 115 | + " - GroupBy [riptable.riptide_cpp.GroupBy]\n", |
| 116 | + " - ..." |
| 117 | + ] |
| 118 | + }, |
| 119 | + { |
| 120 | + "cell_type": "code", |
| 121 | + "execution_count": 5, |
| 122 | + "metadata": {}, |
| 123 | + "outputs": [], |
| 124 | + "source": [ |
| 125 | + "sdsfile = logging.getLogger(\"riptable.riptide_cpp.SDSFile\")\n", |
| 126 | + "sdsfile.setLevel(logging.DEBUG)\n", |
| 127 | + "sdsfile.addHandler(handler)\n", |
| 128 | + "groupby = logging.getLogger(\"riptable.riptide_cpp.GroupBy\")\n", |
| 129 | + "groupby.setLevel(logging.DEBUG)\n", |
| 130 | + "groupby.addHandler(handler)" |
| 131 | + ] |
| 132 | + }, |
| 133 | + { |
| 134 | + "cell_type": "markdown", |
| 135 | + "metadata": {}, |
| 136 | + "source": [ |
| 137 | + "Create an example Dataset, and call functions that record events to the SDSFile and GroupBy\n", |
| 138 | + "loggers:" |
| 139 | + ] |
| 140 | + }, |
| 141 | + { |
| 142 | + "cell_type": "code", |
| 143 | + "execution_count": 6, |
| 144 | + "metadata": {}, |
| 145 | + "outputs": [ |
| 146 | + { |
| 147 | + "data": { |
| 148 | + "text/html": [ |
| 149 | + "\n", |
| 150 | + "<html>\n", |
| 151 | + "<head>\n", |
| 152 | + "<style>\n", |
| 153 | + " table.tbl-5286 tbody td{white-space: nowrap;}\n", |
| 154 | + " table.tbl-5286 .lc{font-weight:bold;background-color: var( --jp-rendermime-table-row-hover-background);}\n", |
| 155 | + " table.tbl-5286 .lg{background-color: #66da9940;}\n", |
| 156 | + " table.tbl-5286 .lp{font-weight:bold;background-color: #ac66da40;}\n", |
| 157 | + " table.tbl-5286 .msc{font-weight:normal;background-color:#00000011;}\n", |
| 158 | + " table.tbl-5286 .al{text-align:left;}\n", |
| 159 | + " table.tbl-5286 .ar{text-align:right;}\n", |
| 160 | + " table.tbl-5286 .ac{text-align:center;}\n", |
| 161 | + " table.tbl-5286 .bld{font-weight:bold;}\n", |
| 162 | + " table.tbl-5286 .it{font-style:italic;}\n", |
| 163 | + " table.tbl-5286 .ul{text-decoration:underline;}\n", |
| 164 | + " table.tbl-5286 .st{text-decoration:line-through;}\n", |
| 165 | + "\n", |
| 166 | + "</style>\n", |
| 167 | + "</head>\n", |
| 168 | + " <body><table class='tbl-5286'><thead><tr><td class='lc bld ar'>#</td><td class='lc bld ar'>a</td><td class='lc bld ar'>b</td><td class='lc bld ar'>c</td></tr></thead><tbody><tr><td class='lc ar '>0</td><td class=' ar '>1</td><td class=' ar '>4</td><td class=' ar '>9</td></tr><tr><td class='lc ar '>1</td><td class=' ar '>1</td><td class=' ar '>5</td><td class=' ar '>9</td></tr><tr><td class='lc ar '>2</td><td class=' ar '>2</td><td class=' ar '>6</td><td class=' ar '>6</td></tr></tbody></table></body></html>\n", |
| 169 | + "\n", |
| 170 | + "[3 rows x 3 columns] total bytes: 72.0 B" |
| 171 | + ], |
| 172 | + "text/plain": [ |
| 173 | + "\u001b[1;36m#\u001b[0m \u001b[1;36ma\u001b[0m \u001b[1;36mb\u001b[0m \u001b[1;36mc\u001b[0m\n", |
| 174 | + "- - - -\n", |
| 175 | + "\u001b[1;36m0\u001b[0m 1\u001b[0m 4\u001b[0m 9\u001b[0m\n", |
| 176 | + "\u001b[1;36m1\u001b[0m 1\u001b[0m 5\u001b[0m 9\u001b[0m\n", |
| 177 | + "\u001b[1;36m2\u001b[0m 2\u001b[0m 6\u001b[0m 6\u001b[0m\n", |
| 178 | + "\n", |
| 179 | + "[3 rows x 3 columns] total bytes: 72.0 B" |
| 180 | + ] |
| 181 | + }, |
| 182 | + "metadata": {}, |
| 183 | + "output_type": "display_data" |
| 184 | + }, |
| 185 | + { |
| 186 | + "name": "stdout", |
| 187 | + "output_type": "stream", |
| 188 | + "text": [ |
| 189 | + "riptable.riptide_cpp.GroupBy | DEBUG | GroupByCall: col 0 ==> outsize 3 len: 3 numpy types 7 --> 7 8 8\n", |
| 190 | + "riptable.riptide_cpp.GroupBy | DEBUG | GroupByCall: 0 typeCall 4 numpyOutType 7\n", |
| 191 | + "riptable.riptide_cpp.GroupBy | DEBUG | !!groupby done 1\n", |
| 192 | + "riptable.riptide_cpp.GroupBy | DEBUG | !!groupby returning\n", |
| 193 | + "\n", |
| 194 | + "riptable.riptide_cpp.SDSFile | DEBUG | Clearing errors\n", |
| 195 | + "riptable.riptide_cpp.SDSFile | DEBUG | linux handle open\n", |
| 196 | + "riptable.riptide_cpp.SDSFile | DEBUG | Using fileOffset 0\n", |
| 197 | + "riptable.riptide_cpp.SDSFile | DEBUG | main offsets 1024 1536 2048\n", |
| 198 | + "riptable.riptide_cpp.SDSFile | DEBUG | meta compressed to 148 vs 187 512\n", |
| 199 | + "riptable.riptide_cpp.SDSFile | DEBUG | Current fileoffset is 0\n", |
| 200 | + "riptable.riptide_cpp.SDSFile | DEBUG | -\n", |
| 201 | + "riptable.riptide_cpp.SDSFile | DEBUG | -\n", |
| 202 | + "riptable.riptide_cpp.SDSFile | DEBUG | -\n", |
| 203 | + "riptable.riptide_cpp.SDSFile | DEBUG | [0] started 24 0x7fc21c000b70\n", |
| 204 | + "riptable.riptide_cpp.SDSFile | DEBUG | [1] started 24 0x7fc214000b70\n", |
| 205 | + "riptable.riptide_cpp.SDSFile | DEBUG | [2] started 24 0x7fc218000b70\n", |
| 206 | + "riptable.riptide_cpp.SDSFile | DEBUG | [1][1] seek to fileOffset 2048 sz: 24\n", |
| 207 | + "riptable.riptide_cpp.SDSFile | DEBUG | [0][0] seek to fileOffset 2560 sz: 24\n", |
| 208 | + "riptable.riptide_cpp.SDSFile | DEBUG | [2][2] seek to fileOffset 3072 sz: 24\n", |
| 209 | + "riptable.riptide_cpp.SDSFile | DEBUG | End of compressing\n", |
| 210 | + "riptable.riptide_cpp.SDSFile | DEBUG | SDS: Array first offset --- 2048 Total comp size 1536\n", |
| 211 | + "riptable.riptide_cpp.SDSFile | DEBUG | Total arrays written 3 --- 512 512\n", |
| 212 | + "riptable.riptide_cpp.SDSFile | DEBUG | array block offset --- 1536 384 2560\n" |
| 213 | + ] |
| 214 | + } |
| 215 | + ], |
| 216 | + "source": [ |
| 217 | + "import tempfile\n", |
| 218 | + "\n", |
| 219 | + "with tempfile.TemporaryDirectory() as tmpdir:\n", |
| 220 | + " ds = rt.Dataset({'a': rt.FA([1, 1, 2]), 'b': rt.FA([4, 5, 6])})\n", |
| 221 | + " ds.c = rt.Cat(ds.a).sum(ds.b, transform=True)\n", |
| 222 | + " ds.save(f'{tmpdir}/a.sds')\n", |
| 223 | + " display(ds)" |
| 224 | + ] |
| 225 | + } |
| 226 | + ], |
| 227 | + "metadata": { |
| 228 | + "kernelspec": { |
| 229 | + "display_name": "riptide-dev", |
| 230 | + "language": "python", |
| 231 | + "name": "python3" |
| 232 | + }, |
| 233 | + "language_info": { |
| 234 | + "codemirror_mode": { |
| 235 | + "name": "ipython", |
| 236 | + "version": 3 |
| 237 | + }, |
| 238 | + "file_extension": ".py", |
| 239 | + "mimetype": "text/x-python", |
| 240 | + "name": "python", |
| 241 | + "nbconvert_exporter": "python", |
| 242 | + "pygments_lexer": "ipython3", |
| 243 | + "version": "3.11.8" |
| 244 | + } |
| 245 | + }, |
| 246 | + "nbformat": 4, |
| 247 | + "nbformat_minor": 2 |
| 248 | +} |
0 commit comments