LCOV - code coverage report
Current view: top level - source3/winbindd - winbindd_traceid.c (source / functions) Hit Total Coverage
Test: coverage report for support-claim-type-attributes 6b5c566e Lines: 70 72 97.2 %
Date: 2023-11-21 12:31:41 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /*
       2             :     Authors:
       3             :         Pavel Březina <pbrezina@redhat.com>
       4             : 
       5             :     Copyright (C) 2021 Red Hat
       6             : 
       7             :     This program is free software; you can redistribute it and/or modify
       8             :     it under the terms of the GNU General Public License as published by
       9             :     the Free Software Foundation; either version 3 of the License, or
      10             :     (at your option) any later version.
      11             : 
      12             :     This program is distributed in the hope that it will be useful,
      13             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :     GNU General Public License for more details.
      16             : 
      17             :     You should have received a copy of the GNU General Public License
      18             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "lib/util/debug.h"
      22             : #include "winbindd_traceid.h"
      23             : #include "tevent.h"
      24             : 
      25     2210561 : static void debug_traceid_trace_fde(struct tevent_fd *fde,
      26             :                                    enum tevent_event_trace_point point,
      27             :                                    void *private_data)
      28             : {
      29     2210561 :     switch (point) {
      30      690744 :     case TEVENT_EVENT_TRACE_ATTACH:
      31             :         /* Assign the current traceid id when the event is created. */
      32      690744 :         tevent_fd_set_tag(fde, debug_traceid_get());
      33      690744 :         break;
      34      829442 :     case TEVENT_EVENT_TRACE_BEFORE_HANDLER:
      35             :         /* Set the traceid id when a handler is being called. */
      36      829442 :         debug_traceid_set(tevent_fd_get_tag(fde));
      37      829442 :         break;
      38      690375 :     default:
      39             :         /* Do nothing. */
      40      690375 :         break;
      41             :     }
      42     2210561 : }
      43             : 
      44         275 : static void debug_traceid_trace_signal(struct tevent_signal *se,
      45             :                                       enum tevent_event_trace_point point,
      46             :                                       void *private_data)
      47             : {
      48         275 :     switch (point) {
      49         246 :     case TEVENT_EVENT_TRACE_ATTACH:
      50             :         /* Assign the current traceid id when the event is created. */
      51         246 :         tevent_signal_set_tag(se, debug_traceid_get());
      52         246 :         break;
      53          29 :     case TEVENT_EVENT_TRACE_BEFORE_HANDLER:
      54             :         /* Set the traceid id when a handler is being called. */
      55          29 :         debug_traceid_set(tevent_signal_get_tag(se));
      56          29 :         break;
      57           0 :     default:
      58             :         /* Do nothing. */
      59           0 :         break;
      60             :     }
      61         275 : }
      62             : 
      63      258359 : static void debug_traceid_trace_timer(struct tevent_timer *timer,
      64             :                                      enum tevent_event_trace_point point,
      65             :                                      void *private_data)
      66             : {
      67      258359 :     switch (point) {
      68      126518 :     case TEVENT_EVENT_TRACE_ATTACH:
      69             :         /* Assign the current traceid id when the event is created. */
      70      126518 :         tevent_timer_set_tag(timer, debug_traceid_get());
      71      126518 :         break;
      72        5450 :     case TEVENT_EVENT_TRACE_BEFORE_HANDLER:
      73             :         /* Set the traceid id when a handler is being called. */
      74        5450 :         debug_traceid_set(tevent_timer_get_tag(timer));
      75        5450 :         break;
      76      126391 :     default:
      77             :         /* Do nothing. */
      78      126391 :         break;
      79             :     }
      80      258359 : }
      81             : 
      82     2821489 : static void debug_traceid_trace_immediate(struct tevent_immediate *im,
      83             :                                          enum tevent_event_trace_point point,
      84             :                                          void *private_data)
      85             : {
      86     2821489 :     switch (point) {
      87     1013958 :     case TEVENT_EVENT_TRACE_ATTACH:
      88             :         /* Assign the current traceid id when the event is created. */
      89     1013958 :         tevent_immediate_set_tag(im, debug_traceid_get());
      90     1013958 :         break;
      91      793573 :     case TEVENT_EVENT_TRACE_BEFORE_HANDLER:
      92             :         /* Set the traceid id when a handler is being called. */
      93      793573 :         debug_traceid_set(tevent_immediate_get_tag(im));
      94      793573 :         break;
      95     1013958 :     default:
      96             :         /* Do nothing. */
      97     1013958 :         break;
      98             :     }
      99     2821489 : }
     100             : 
     101     1091745 : static void debug_traceid_trace_queue(struct tevent_queue_entry *qe,
     102             :                                          enum tevent_event_trace_point point,
     103             :                                          void *private_data)
     104             : {
     105     1091745 :     switch (point) {
     106      363914 :     case TEVENT_EVENT_TRACE_ATTACH:
     107             :         /* Assign the current traceid id when the event is created. */
     108      363914 :         tevent_queue_entry_set_tag(qe, debug_traceid_get());
     109      363914 :         break;
     110      363917 :     case TEVENT_EVENT_TRACE_BEFORE_HANDLER:
     111             :         /* Set the traceid id when a handler is being called. */
     112      363917 :         debug_traceid_set(tevent_queue_entry_get_tag(qe));
     113      363917 :         break;
     114      363914 :     default:
     115             :         /* Do nothing. */
     116      363914 :         break;
     117             :     }
     118     1091745 : }
     119             : 
     120     4926545 : static void debug_traceid_trace_loop(enum tevent_trace_point point,
     121             :                                     void *private_data)
     122             : {
     123     4926545 :     switch (point) {
     124     1628453 :     case TEVENT_TRACE_AFTER_LOOP_ONCE:
     125             :         /* Reset traceid id when we got back to the loop. An event handler
     126             :          * that set traceid id was fired. This tracepoint represents a place
     127             :          * after the event handler was finished, we need to restore traceid
     128             :          * id to 1 (out of request). 0 means not initialized.
     129             :          */
     130     1628453 :         debug_traceid_set(1);
     131     1628453 :         break;
     132     3298092 :     default:
     133             :         /* Do nothing. */
     134     3298092 :         break;
     135             :     }
     136     4926545 : }
     137             : 
     138          41 : void winbind_debug_traceid_setup(struct tevent_context *ev)
     139             : {
     140          41 :     tevent_set_trace_callback(ev, debug_traceid_trace_loop, NULL);
     141          41 :     tevent_set_trace_fd_callback(ev, debug_traceid_trace_fde, NULL);
     142          41 :     tevent_set_trace_signal_callback(ev, debug_traceid_trace_signal, NULL);
     143          41 :     tevent_set_trace_timer_callback(ev, debug_traceid_trace_timer, NULL);
     144          41 :     tevent_set_trace_immediate_callback(ev, debug_traceid_trace_immediate, NULL);
     145          41 :     tevent_set_trace_queue_callback(ev, debug_traceid_trace_queue, NULL);
     146          41 :     debug_traceid_set(1);
     147          41 : }

Generated by: LCOV version 1.14