|
| 1 | +--[[ |
| 2 | +This file is part of darktable, |
| 3 | +copyright (c) 2014 Jérémy Rosen |
| 4 | +
|
| 5 | +darktable is free software: you can redistribute it and/or modify |
| 6 | +it under the terms of the GNU General Public License as published by |
| 7 | +the Free Software Foundation, either version 3 of the License, or |
| 8 | +(at your option) any later version. |
| 9 | +
|
| 10 | +darktable is distributed in the hope that it will be useful, |
| 11 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +GNU General Public License for more details. |
| 14 | +
|
| 15 | +You should have received a copy of the GNU General Public License |
| 16 | +along with darktable. If not, see <http://www.gnu.org/licenses/>. |
| 17 | +]] |
| 18 | +--[[ |
| 19 | +DEBUG HELPERS |
| 20 | +A collection of helper functions to help debugging lua scripts. |
| 21 | +
|
| 22 | +require it as |
| 23 | +
|
| 24 | +dhelpers = require "official/debug-helpers" |
| 25 | +
|
| 26 | +Each function is documented in its own header |
| 27 | +
|
| 28 | +
|
| 29 | +]] |
| 30 | + |
| 31 | + |
| 32 | +local dt = require "darktable" |
| 33 | +local io = require "io" |
| 34 | +local table = require "table" |
| 35 | +require "darktable.debug" |
| 36 | +local log = require "lib/libLog" |
| 37 | +local M = {} -- The actual content of the module |
| 38 | + |
| 39 | +M.libdoc = { |
| 40 | + Sections = {"Name", "Synopsis", "Description", "License"}, |
| 41 | + Name = [[dtutils.debug - debugging helpers used in developing darktable lua scripts]], |
| 42 | + Synopsis = [[local dd = require "lib/dtutils.debug"]], |
| 43 | + Description = [[dtutils.debug provides an interface to the darktable debugging routines.]], |
| 44 | + License = [[This program is free software: you can redistribute it and/or modify |
| 45 | + it under the terms of the GNU General Public License as published by |
| 46 | + the Free Software Foundation; either version 3 of the License, or |
| 47 | + (at your option) any later version. |
| 48 | +
|
| 49 | + This program is distributed in the hope that it will be useful, |
| 50 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 51 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 52 | + GNU General Public License for more details. |
| 53 | +
|
| 54 | + You should have received a copy of the GNU General Public License |
| 55 | + along with this program. If not, see <http://www.gnu.org/licenses/>.]], |
| 56 | + functions = {} |
| 57 | +} |
| 58 | + |
| 59 | +--[[ |
| 60 | + NAME |
| 61 | + tracepoint - print out a tracepoint and dump the arguments |
| 62 | +
|
| 63 | + SYNOPSIS |
| 64 | + local dd = require "lib/dtutils.debug" |
| 65 | +
|
| 66 | + local result = tracepoint(name, ...) |
| 67 | + name - string - the name of the tracepoint to print out |
| 68 | + ... - arguments - variables to dump the contents of |
| 69 | +
|
| 70 | + DESCRIPTION |
| 71 | + tracepoint prints its name and dumps its parameters using |
| 72 | + dt.debug |
| 73 | +
|
| 74 | + RETURN VALUE |
| 75 | + result - ... - the supplied argument list |
| 76 | +
|
| 77 | +]] |
| 78 | + |
| 79 | +M.libdoc.functions[#M.libdoc.functions + 1] = { |
| 80 | + Sections = {"Name", "Synopsis", "Description", "Return_Value"}, |
| 81 | + Name = [[tracepoint - print out a tracepoint and dump the arguments]], |
| 82 | + Synopsis = [[local dd = require "lib/dtutils.debug" |
| 83 | +
|
| 84 | + local result = tracepoint(name, ...) |
| 85 | + name - string - the name of the tracepoint to print out |
| 86 | + ... - arguments - variables to dump the contents of]], |
| 87 | + Description = [[tracepoint prints its name and dumps its parameters using |
| 88 | + dt.debug]], |
| 89 | + Return_Value = [[result - ... - the supplied argument list]], |
| 90 | +} |
| 91 | + |
| 92 | +function M.tracepoint(name,...) |
| 93 | + log.always(4, "***** "..name.." ****") |
| 94 | + params = {...} |
| 95 | + print(dt.debug.dump(params,"parameters")) |
| 96 | + return ...; |
| 97 | +end |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | +--[[ |
| 102 | + NAME |
| 103 | + new_tracepoint - create a function returning a tracepoint |
| 104 | +
|
| 105 | + SYNOPSIS |
| 106 | + local dd = require "lib/dtutils.debug" |
| 107 | +
|
| 108 | + local result = new_tracepoint(name, ...) |
| 109 | + name - string - the name of the tracepoint to print out |
| 110 | + ... - arguments - variables to dump the contents of |
| 111 | +
|
| 112 | +
|
| 113 | + DESCRIPTION |
| 114 | + A function that returns a tracepoint function with the given name |
| 115 | + This is mainly used to debug callbacks. |
| 116 | +
|
| 117 | + RETURN VALUE |
| 118 | + result - function - a function that returns the result of a tracepoint |
| 119 | +
|
| 120 | + EXAMPLE |
| 121 | + register_event(event, dd.new_tracepoint("hit callback")) |
| 122 | +
|
| 123 | + will print the following each time the callback is called |
| 124 | +
|
| 125 | + **** hit callback **** |
| 126 | + <all the callback's parameters dumped> |
| 127 | +
|
| 128 | +]] |
| 129 | + |
| 130 | +M.libdoc.functions[#M.libdoc.functions + 1] = { |
| 131 | + Sections = {"Name", "Synopsis", "Description", "Return_Value", "Example"}, |
| 132 | + Name = [[new_tracepoint - create a function returning a tracepoint]], |
| 133 | + Synopsis = [[local dd = require "lib/dtutils.debug" |
| 134 | +
|
| 135 | + local result = new_tracepoint(name, ...) |
| 136 | + name - string - the name of the tracepoint to print out |
| 137 | + ... - arguments - variables to dump the contents of]], |
| 138 | + Description = [[A function that returns a tracepoint function with the given name |
| 139 | + This is mainly used to debug callbacks.]], |
| 140 | + Return_Value = [[result - function - a function that returns the result of a tracepoint]], |
| 141 | + Example = [[register_event(event, dd.new_tracepoint("hit callback")) |
| 142 | +
|
| 143 | + will print the following each time the callback is called |
| 144 | +
|
| 145 | + **** hit callback **** |
| 146 | + <all the callback's parameters dumped>]], |
| 147 | +} |
| 148 | + |
| 149 | +function M.new_tracepoint(name) |
| 150 | + return function(...) return M.tracepoint(name,...) end |
| 151 | +end |
| 152 | + |
| 153 | + |
| 154 | +--[[ |
| 155 | + NAME |
| 156 | + dprint - pass a variable to dt.debug.dump and print the results to stdout |
| 157 | +
|
| 158 | + SYNOPSIS |
| 159 | + local dd = require "lib/dtutils.debug" |
| 160 | +
|
| 161 | + dd.dprint(var) |
| 162 | + var - variable - any variable that you want to see the contents of |
| 163 | +
|
| 164 | + DESCRIPTION |
| 165 | + Wrapper around debug.dump, will directly print to stdout, |
| 166 | + same calling convention |
| 167 | + |
| 168 | +]] |
| 169 | + |
| 170 | +M.libdoc.functions[#M.libdoc.functions + 1] = { |
| 171 | + Sections = {"Name", "Synopsis", "Description"}, |
| 172 | + Name = [[dprint - pass a variable to dt.debug.dump and print the results to stdout]], |
| 173 | + Synopsis = [[local dd = require "lib/dtutils.debug" |
| 174 | +
|
| 175 | + dd.dprint(var) |
| 176 | + var - variable - any variable that you want to see the contents of]], |
| 177 | + Description = [[Wrapper around debug.dump, will directly print to stdout, |
| 178 | + same calling convention]], |
| 179 | +} |
| 180 | + |
| 181 | +function M.dprint(...) |
| 182 | + log.always(4, dt.debug.dump(...)) |
| 183 | +end |
| 184 | + |
| 185 | +--[[ |
| 186 | + NAME |
| 187 | + terse_dump - set dt.debug.known to shorten all image dumps to a single line |
| 188 | +
|
| 189 | + SYNOPSIS |
| 190 | + local dd = require "lib/dtutils.debug" |
| 191 | +
|
| 192 | + dd.terse_dump() |
| 193 | +
|
| 194 | + DESCRIPTION |
| 195 | + terse_dump sets dt.debug.known to shorten all images to a single line. |
| 196 | + If you don't need to debug the content of images, this will avoid them flooding your logs |
| 197 | +]] |
| 198 | + |
| 199 | +M.libdoc.functions[#M.libdoc.functions + 1] = { |
| 200 | + Sections = {"Name", "Synopsis", "Description"}, |
| 201 | + Name = [[terse_dump - set dt.debug.known to shorten all image dumps to a single line]], |
| 202 | + Synopsis = [[local dd = require "lib/dtutils.debug" |
| 203 | +
|
| 204 | + dd.terse_dump()]], |
| 205 | + Description = [[terse_dump sets dt.debug.known to shorten all images to a single line. |
| 206 | + If you don't need to debug the content of images, this will avoid them flooding your logs]], |
| 207 | +} |
| 208 | + |
| 209 | +function M.terse_dump() |
| 210 | + for _,v in ipairs(dt.database) do |
| 211 | + dt.debug.known[v] = tostring(v) |
| 212 | + end |
| 213 | +end |
| 214 | + |
| 215 | + |
| 216 | + |
| 217 | +return M |
| 218 | +-- vim: shiftwidth=2 expandtab tabstop=2 cindent |
| 219 | +-- kate: tab-indents: off; indent-width 2; replace-tabs on; remove-trailing-space on; |
0 commit comments