Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vvenc/source/Lib/CommonLib/dtrace.h
Line
Count
Source
1
/* -----------------------------------------------------------------------------
2
The copyright in this software is being made available under the Clear BSD
3
License, included below. No patent rights, trademark rights and/or 
4
other Intellectual Property Rights other than the copyrights concerning 
5
the Software are granted under this license.
6
7
The Clear BSD License
8
9
Copyright (c) 2019-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVenC Authors.
10
All rights reserved.
11
12
Redistribution and use in source and binary forms, with or without modification,
13
are permitted (subject to the limitations in the disclaimer below) provided that
14
the following conditions are met:
15
16
     * Redistributions of source code must retain the above copyright notice,
17
     this list of conditions and the following disclaimer.
18
19
     * Redistributions in binary form must reproduce the above copyright
20
     notice, this list of conditions and the following disclaimer in the
21
     documentation and/or other materials provided with the distribution.
22
23
     * Neither the name of the copyright holder nor the names of its
24
     contributors may be used to endorse or promote products derived from this
25
     software without specific prior written permission.
26
27
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY
28
THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
29
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
33
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
34
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
36
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38
POSSIBILITY OF SUCH DAMAGE.
39
40
41
------------------------------------------------------------------------------------------- */
42
/** \file     dtrace.h
43
 *  \brief    Implementation of trace messages support for debugging
44
 */
45
46
#pragma once
47
48
#include "CommonDef.h"
49
50
#include <stdio.h>
51
#include <string>
52
#include <list>
53
#include <map>
54
#include <set>
55
#include <vector>
56
#include <cstdarg>
57
58
//! \ingroup CommonLib
59
//! \{
60
61
namespace vvenc {
62
63
class CDTrace;
64
65
typedef std::string CType;
66
67
struct dtrace_channel
68
{
69
  int channel_number;
70
  std::string channel_name;
71
};
72
73
typedef std::vector< dtrace_channel > dtrace_channels_t;
74
75
class Condition
76
{
77
public:
78
    CType type;
79
    bool ( *eval )( int, int );
80
    int rval;
81
82
    Condition( CType t, bool ( *efunc )( int,int ), int refval )
83
    : type(t), eval(efunc), rval(refval)
84
0
    {}
85
};
86
typedef std::pair< CType, int > state_type;
87
88
typedef std::vector<Condition> Rule;
89
class Channel
90
{
91
public:
92
0
    Channel() : rule_list(), _active(false), _activeLocal(false), _counter(0) {}
93
    bool evaluate( state_type stateval );
94
    void update( state_type& stateval, bool localState );
95
    void update( std::map< CType, int > state );
96
0
    bool active() { return _active || _activeLocal; }
97
    void add( Rule rule );
98
0
    void enable( bool _enable ) { _activeLocal = _enable; }
99
0
    void incrementCounter() { _counter++; }
100
0
    void decrementCounter() { _counter--  ; }
101
0
    int64_t getCounter() { return _counter; }
102
private:
103
    std::list< Rule > rule_list;
104
    bool _active;
105
    bool _activeLocal;
106
    int64_t _counter;
107
};
108
109
class CDTrace
110
{
111
  //friend class Rules;
112
private:
113
    bool          copy;
114
    FILE         *m_trace_file;
115
    int           m_error_code;
116
117
    typedef std::string Key;
118
    typedef std::vector<std::string> vstring;
119
    typedef std::map< Key, int > channel_map_t;
120
    std::vector< Channel > chanRules;
121
    std::set< CType > condition_types;
122
    std::map< CType, int > state;
123
    std::map< Key, int > deserializationTable;
124
125
public:
126
0
    CDTrace() : copy(false), m_trace_file(NULL) {}
127
    CDTrace( const char *filename, vstring channel_names );
128
    CDTrace( const char *filename, const dtrace_channels_t& channels );
129
    CDTrace( const std::string& sTracingFile, const std::string& sTracingRule, const dtrace_channels_t& channels );
130
    CDTrace( const CDTrace& other );
131
    CDTrace& operator=( const CDTrace& other );
132
    ~CDTrace();
133
    void swap         ( CDTrace& other );
134
    int  addRule      ( std::string rulestring );
135
    template<bool bCount>
136
    void dtrace       ( int, const char *format, /*va_list args*/... );
137
    void dtrace_repeat( int, int i_times, const char* format, /*va_list args*/... );
138
    bool update       ( state_type stateval );
139
    bool updateChannel( int channel, state_type stateval );
140
    int  init( vstring channel_names );
141
0
    int  getLastError() { return m_error_code;  }
142
    const char*  getChannelName( int channel_number );
143
    void getChannelsList( std::string& sChannels );
144
    std::string getErrMessage();
145
0
    int64_t getChannelCounter( int channel ) { return chanRules[channel].getCounter(); }
146
0
    void decrementChannelCounter( int channel ) { chanRules[channel].decrementCounter(); }
147
0
    void enableChannel( int channel, bool _enable ) { chanRules[channel].enable(_enable); }
148
};
149
150
} // namespace vvenc
151
152
//! \}
153