LCOV - code coverage report
Current view: top level - monetdb5/modules/mal - tracer.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 53 3.8 %
Date: 2021-01-13 20:07:21 Functions: 1 11 9.1 %

          Line data    Source code
       1             : /*
       2             :  * This Source Code Form is subject to the terms of the Mozilla Public
       3             :  * License, v. 2.0.  If a copy of the MPL was not distributed with this
       4             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       5             :  *
       6             :  * Copyright 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
       7             :  */
       8             : 
       9             : /*
      10             :  * GDKtracer exposes routines where an occuring failure should reach the
      11             :  * client immediately. For that reason, GDKtracer reports those errors
      12             :  * directly to the stream.
      13             :  *
      14             :  */
      15             : 
      16             : #include "monetdb_config.h"
      17             : #include "mal.h"
      18             : #include "mal_interpreter.h"
      19             : 
      20             : 
      21             : static str
      22           0 : TRACERflush_buffer(void *ret)
      23             : {
      24             :     (void) ret;
      25           0 :     GDKtracer_flush_buffer();
      26           0 :     return MAL_SUCCEED;
      27             : }
      28             : 
      29             : 
      30             : static str
      31           0 : TRACERset_component_level(void *ret, str *comp_id, str *lvl_id)
      32             : {
      33             :     (void) ret;
      34           0 :     if (GDKtracer_set_component_level(*comp_id, *lvl_id) != GDK_SUCCEED)
      35           0 :         throw(MAL, "logging.setcomplevel", ILLEGAL_ARGUMENT);
      36             : 
      37             :     return MAL_SUCCEED;
      38             : }
      39             : 
      40             : 
      41             : static str
      42           0 : TRACERreset_component_level(void *ret, str *comp_id)
      43             : {
      44             :     (void) ret;
      45           0 :     if (GDKtracer_reset_component_level(*comp_id) != GDK_SUCCEED)
      46           0 :         throw(MAL, "logging.resetcomplevel", ILLEGAL_ARGUMENT"\n");
      47             : 
      48             :     return MAL_SUCCEED;
      49             : }
      50             : 
      51             : 
      52             : static str
      53           0 : TRACERset_layer_level(void *ret, str *layer_id, str *lvl_id)
      54             : {
      55             :     (void) ret;
      56           0 :     if (GDKtracer_set_layer_level(*layer_id, *lvl_id) != GDK_SUCCEED)
      57           0 :         throw(MAL, "logging.setlayerlevel", ILLEGAL_ARGUMENT"\n");
      58             : 
      59             :     return MAL_SUCCEED;
      60             : }
      61             : 
      62             : 
      63             : static str
      64           0 : TRACERreset_layer_level(void *ret, str *layer_id)
      65             : {
      66             :     (void) ret;
      67           0 :     if (GDKtracer_reset_layer_level(*layer_id) != GDK_SUCCEED)
      68           0 :         throw(MAL, "logging.resetlayerlevel", ILLEGAL_ARGUMENT"\n");
      69             : 
      70             :     return MAL_SUCCEED;
      71             : }
      72             : 
      73             : 
      74             : static str
      75           0 : TRACERset_flush_level(void *ret, str *lvl_id)
      76             : {
      77             :     (void) ret;
      78           0 :     if (GDKtracer_set_flush_level(*lvl_id) != GDK_SUCCEED)
      79           0 :         throw(MAL, "logging.setflushlevel", ILLEGAL_ARGUMENT"\n");
      80             : 
      81             :     return MAL_SUCCEED;
      82             : }
      83             : 
      84             : 
      85             : static str
      86           0 : TRACERreset_flush_level(void *ret)
      87             : {
      88             :     (void) ret;
      89           0 :     if (GDKtracer_reset_flush_level() != GDK_SUCCEED)
      90           0 :         throw(MAL, "logging.resetflushlevel", _OPERATION_FAILED"\n");
      91             : 
      92             :     return MAL_SUCCEED;
      93             : }
      94             : 
      95             : 
      96             : static str
      97           0 : TRACERset_adapter(void *ret, str *adapter_id)
      98             : {
      99             :     (void) ret;
     100           0 :     if (GDKtracer_set_adapter(*adapter_id) != GDK_SUCCEED)
     101           0 :         throw(MAL, "logging.setadapter", ILLEGAL_ARGUMENT"\n");
     102             : 
     103             :     return MAL_SUCCEED;
     104             : }
     105             : 
     106             : 
     107             : static str
     108           0 : TRACERreset_adapter(void *ret)
     109             : {
     110             :     (void) ret;
     111           0 :     if (GDKtracer_reset_adapter() != GDK_SUCCEED)
     112           0 :         throw(MAL, "logging.resetadapter", _OPERATION_FAILED"\n");
     113             : 
     114             :     return MAL_SUCCEED;
     115             : }
     116             : 
     117             : 
     118             : static str
     119           0 : TRACERcomp_info(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
     120             : {
     121             :     (void) cntxt;
     122             :     (void) mb;
     123             : 
     124             :     BAT *id, *component, *log_level;
     125           0 :     bat *i = getArgReference_bat(stk, pci, 0);
     126           0 :     bat *c = getArgReference_bat(stk, pci, 1);
     127           0 :     bat *l = getArgReference_bat(stk, pci, 2);
     128             : 
     129           0 :     id = COLnew(0, TYPE_int, (BUN) COMPONENTS_COUNT, TRANSIENT);
     130           0 :     component = COLnew(0, TYPE_str, (BUN) COMPONENTS_COUNT, TRANSIENT);
     131           0 :     log_level = COLnew(0, TYPE_str, (BUN) COMPONENTS_COUNT, TRANSIENT);
     132             : 
     133           0 :     if ( id == NULL || component == NULL || log_level == NULL ) {
     134           0 :                 BBPreclaim(id);
     135           0 :                 BBPreclaim(component);
     136           0 :                 BBPreclaim(log_level);
     137           0 :                 throw(MAL, "logging.compinfo", SQLSTATE(HY013) MAL_MALLOC_FAIL);
     138             :         }
     139             : 
     140             :     // Fill the BATs
     141           0 :     MT_lock_set(&mal_delayLock);
     142           0 :         if(GDKtracer_fill_comp_info(id, component, log_level) == GDK_FAIL) {
     143           0 :                 MT_lock_unset(&mal_delayLock);
     144           0 :                 BBPunfix(id->batCacheid);
     145           0 :                 BBPunfix(component->batCacheid);
     146           0 :                 BBPunfix(log_level->batCacheid);
     147           0 :                 throw(MAL, "logging.compinfo", GDK_EXCEPTION);
     148             :         }
     149           0 :     MT_lock_unset(&mal_delayLock);
     150             : 
     151           0 :     BBPkeepref(*i = id->batCacheid);
     152           0 :     BBPkeepref(*c = component->batCacheid);
     153           0 :     BBPkeepref(*l = log_level->batCacheid);
     154           0 :     return MAL_SUCCEED;
     155             : }
     156             : 
     157             : #include "mel.h"
     158             : mel_func tracer_init_funcs[] = {
     159             :  command("logging", "flush", TRACERflush_buffer, false, "Flush the buffer", args(1,1, arg("",void))),
     160             :  command("logging", "setcomplevel", TRACERset_component_level, false, "Sets the log level for a specific component", args(1,3, arg("",void),arg("comp",str),arg("lvl",str))),
     161             :  command("logging", "resetcomplevel", TRACERreset_component_level, false, "Resets the log level for a specific component back to the default", args(1,2, arg("",void),arg("comp",str))),
     162             :  command("logging", "setlayerlevel", TRACERset_layer_level, false, "Sets the log level for a specific layer", args(1,3, arg("",void),arg("layer",str),arg("lvl",str))),
     163             :  command("logging", "resetlayerlevel", TRACERreset_layer_level, false, "Resets the log level for a specific layer back to the default", args(1,2, arg("",void),arg("layer",str))),
     164             :  command("logging", "setflushlevel", TRACERset_flush_level, false, "Sets the flush level", args(1,2, arg("",void),arg("lvl",str))),
     165             :  command("logging", "resetflushlevel", TRACERreset_flush_level, false, "Resets the flush level back to the default", args(1,1, arg("",void))),
     166             :  command("logging", "setadapter", TRACERset_adapter, false, "Sets the adapter", args(1,2, arg("",void),arg("adapter",str))),
     167             :  command("logging", "resetadapter", TRACERreset_adapter, false, "Resets the adapter back to the default", args(1,1, arg("",void))),
     168             :  pattern("logging", "compinfo", TRACERcomp_info, false, "Returns in the form of a SQL result-set all the components along with their ID\nand the their current logging level being set", args(3,3, batarg("id",int),batarg("component",str),batarg("log_level",str))),
     169             :  { .imp=NULL }
     170             : };
     171             : #include "mal_import.h"
     172             : #ifdef _MSC_VER
     173             : #undef read
     174             : #pragma section(".CRT$XCU",read)
     175             : #endif
     176         255 : LIB_STARTUP_FUNC(init_tracer_mal)
     177         255 : { mal_module("tracer", NULL, tracer_init_funcs); }

Generated by: LCOV version 1.14