Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VVCSoftware_VTM
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Keming Cao
VVCSoftware_VTM
Commits
c35e230e
Commit
c35e230e
authored
4 years ago
by
Frank Bossen
Browse files
Options
Downloads
Patches
Plain Diff
Fix indentation and braces
parent
281b04d9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
source/Lib/CommonLib/dtrace.cpp
+161
-114
161 additions, 114 deletions
source/Lib/CommonLib/dtrace.cpp
with
161 additions
and
114 deletions
source/Lib/CommonLib/dtrace.cpp
+
161
−
114
View file @
c35e230e
...
@@ -47,83 +47,88 @@
...
@@ -47,83 +47,88 @@
#include
"dtrace_next.h"
#include
"dtrace_next.h"
void
Channel
::
update
(
std
::
map
<
CType
,
int
>
state
)
void
Channel
::
update
(
std
::
map
<
CType
,
int
>
state
)
{
{
for
(
std
::
list
<
Rule
>::
iterator
rules_iter
=
rule_list
.
begin
();
rules_iter
!=
rule_list
.
end
();
++
rules_iter
)
for
(
std
::
list
<
Rule
>::
iterator
rules_iter
=
rule_list
.
begin
();
{
rules_iter
!=
rule_list
.
end
();
/* iterate over conditions, get the state of the condition type
++
rules_iter
)
{
* and check if contion is met:
/* iterate over conditions, get the state of the condition type
* if not -> go to next rule
* and check if contion is met:
* yes -> go to next condition
* if not -> go to next rule
* if all conditions are met: set channel active and return */
* yes -> go to next condition
bool
probe
=
true
;
* if all conditions are met: set channel active and return */
bool
probe
=
true
;
for
(
Rule
::
iterator
cond_iter
=
rules_iter
->
begin
();
cond_iter
!=
rules_iter
->
end
();
++
cond_iter
)
{
for
(
Rule
::
iterator
cond_iter
=
rules_iter
->
begin
();
int
sVal
=
state
[
cond_iter
->
type
];
cond_iter
!=
rules_iter
->
end
();
if
(
!
cond_iter
->
eval
(
cond_iter
->
rval
,
sVal
))
++
cond_iter
)
{
{
int
sVal
=
state
[
cond_iter
->
type
];
probe
=
false
;
if
(
!
cond_iter
->
eval
(
cond_iter
->
rval
,
sVal
)
)
{
break
;
probe
=
false
;
}
break
;
}
}
if
(
probe
)
{
_active
=
true
;
return
;
}
}
}
if
(
probe
)
{
_active
=
true
;
return
;
}
}
_active
=
false
;
_active
=
false
;
}
}
void
Channel
::
add
(
std
::
vector
<
Condition
>
rule
)
void
Channel
::
add
(
std
::
vector
<
Condition
>
rule
)
{
{
rule_list
.
push_back
(
rule
);
rule_list
.
push_back
(
rule
);
}
}
static
inline
static
inline
std
::
vector
<
std
::
string
>
&
split
(
const
std
::
string
&
s
,
char
delim
,
std
::
vector
<
std
::
string
>
&
elems
)
std
::
vector
<
std
::
string
>
&
split
(
const
std
::
string
&
s
,
char
delim
,
std
::
vector
<
std
::
string
>
&
elems
)
{
{
std
::
stringstream
ss
(
s
);
std
::
stringstream
ss
(
s
);
std
::
string
item
;
std
::
string
item
;
while
(
std
::
getline
(
ss
,
item
,
delim
)
)
{
while
(
std
::
getline
(
ss
,
item
,
delim
))
elems
.
push_back
(
item
);
{
}
elems
.
push_back
(
item
);
return
elems
;
}
return
elems
;
}
}
static
inline
static
inline
std
::
vector
<
std
::
string
>
split
(
const
std
::
string
&
s
,
char
delim
)
std
::
vector
<
std
::
string
>
split
(
const
std
::
string
&
s
,
char
delim
)
{
{
std
::
vector
<
std
::
string
>
elems
;
std
::
vector
<
std
::
string
>
elems
;
split
(
s
,
delim
,
elems
);
split
(
s
,
delim
,
elems
);
return
elems
;
return
elems
;
}
}
CDTrace
::
CDTrace
(
const
char
*
filename
,
vstring
channel_names
)
CDTrace
::
CDTrace
(
const
char
*
filename
,
vstring
channel_names
)
:
copy
(
false
),
m_trace_file
(
NULL
),
m_error_code
(
0
)
:
copy
(
false
),
m_trace_file
(
NULL
),
m_error_code
(
0
)
{
{
if
(
filename
)
if
(
filename
)
m_trace_file
=
fopen
(
filename
,
"w"
);
{
m_trace_file
=
fopen
(
filename
,
"w"
);
}
int
i
=
0
;
int
i
=
0
;
for
(
vstring
::
iterator
ci
=
channel_names
.
begin
();
ci
!=
channel_names
.
end
();
++
ci
)
{
for
(
vstring
::
iterator
ci
=
channel_names
.
begin
();
ci
!=
channel_names
.
end
();
++
ci
)
deserializationTable
[
*
ci
]
=
i
++
;
{
chanRules
.
push_back
(
Channel
()
);
deserializationTable
[
*
ci
]
=
i
++
;
}
chanRules
.
push_back
(
Channel
());
}
}
}
CDTrace
::
CDTrace
(
const
char
*
filename
,
const
dtrace_channels_t
&
channels
)
CDTrace
::
CDTrace
(
const
char
*
filename
,
const
dtrace_channels_t
&
channels
)
:
copy
(
false
),
m_trace_file
(
NULL
),
m_error_code
(
0
)
:
copy
(
false
),
m_trace_file
(
NULL
),
m_error_code
(
0
)
{
{
if
(
filename
)
if
(
filename
)
{
m_trace_file
=
fopen
(
filename
,
"w"
);
m_trace_file
=
fopen
(
filename
,
"w"
);
}
//int i = 0;
//int i = 0;
for
(
dtrace_channels_t
::
const_iterator
ci
=
channels
.
begin
();
ci
!=
channels
.
end
();
++
ci
)
{
for
(
dtrace_channels_t
::
const_iterator
ci
=
channels
.
begin
();
ci
!=
channels
.
end
();
++
ci
)
{
deserializationTable
[
ci
->
channel_name
]
=
ci
->
channel_number
/*i++*/
;
deserializationTable
[
ci
->
channel_name
]
=
ci
->
channel_number
/*i++*/
;
chanRules
.
push_back
(
Channel
()
);
chanRules
.
push_back
(
Channel
()
);
}
}
...
@@ -131,13 +136,13 @@ CDTrace::CDTrace( const char *filename, const dtrace_channels_t& channels )
...
@@ -131,13 +136,13 @@ CDTrace::CDTrace( const char *filename, const dtrace_channels_t& channels )
CDTrace
::
CDTrace
(
const
CDTrace
&
other
)
CDTrace
::
CDTrace
(
const
CDTrace
&
other
)
{
{
copy
=
true
;
copy
=
true
;
m_trace_file
=
other
.
m_trace_file
;
m_trace_file
=
other
.
m_trace_file
;
chanRules
=
other
.
chanRules
;
chanRules
=
other
.
chanRules
;
condition_types
=
other
.
condition_types
;
condition_types
=
other
.
condition_types
;
state
=
other
.
state
;
state
=
other
.
state
;
deserializationTable
=
other
.
deserializationTable
;
deserializationTable
=
other
.
deserializationTable
;
m_error_code
=
other
.
m_error_code
;
m_error_code
=
other
.
m_error_code
;
}
}
CDTrace
::
CDTrace
(
const
std
::
string
&
sTracingFile
,
const
std
::
string
&
sTracingRule
,
const
dtrace_channels_t
&
channels
)
CDTrace
::
CDTrace
(
const
std
::
string
&
sTracingFile
,
const
std
::
string
&
sTracingRule
,
const
dtrace_channels_t
&
channels
)
...
@@ -152,28 +157,30 @@ CDTrace::CDTrace( const std::string& sTracingFile, const std::string& sTracingRu
...
@@ -152,28 +157,30 @@ CDTrace::CDTrace( const std::string& sTracingFile, const std::string& sTracingRu
void
CDTrace
::
swap
(
CDTrace
&
other
)
void
CDTrace
::
swap
(
CDTrace
&
other
)
{
{
using
std
::
swap
;
using
std
::
swap
;
CDTrace
&
first
=
*
this
;
CDTrace
&
first
=
*
this
;
CDTrace
&
second
=
other
;
CDTrace
&
second
=
other
;
swap
(
first
.
copy
,
second
.
copy
);
swap
(
first
.
copy
,
second
.
copy
);
swap
(
first
.
m_trace_file
,
second
.
m_trace_file
);
swap
(
first
.
m_trace_file
,
second
.
m_trace_file
);
swap
(
first
.
chanRules
,
second
.
chanRules
);
swap
(
first
.
chanRules
,
second
.
chanRules
);
swap
(
first
.
condition_types
,
second
.
condition_types
);
swap
(
first
.
condition_types
,
second
.
condition_types
);
swap
(
first
.
state
,
second
.
state
);
swap
(
first
.
state
,
second
.
state
);
swap
(
first
.
deserializationTable
,
second
.
deserializationTable
);
swap
(
first
.
deserializationTable
,
second
.
deserializationTable
);
}
}
CDTrace
&
CDTrace
::
operator
=
(
const
CDTrace
&
other
)
CDTrace
&
CDTrace
::
operator
=
(
const
CDTrace
&
other
)
{
{
CDTrace
tmp
(
other
);
CDTrace
tmp
(
other
);
swap
(
tmp
);
swap
(
tmp
);
return
*
this
;
return
*
this
;
}
}
CDTrace
::~
CDTrace
()
CDTrace
::~
CDTrace
()
{
{
if
(
!
copy
&&
m_trace_file
)
if
(
!
copy
&&
m_trace_file
)
fclose
(
m_trace_file
);
{
fclose
(
m_trace_file
);
}
}
}
bool
_cf_eq
(
int
bound
,
int
val
)
{
return
(
val
==
bound
);
}
bool
_cf_eq
(
int
bound
,
int
val
)
{
return
(
val
==
bound
);
}
...
@@ -183,65 +190,93 @@ bool _cf_ge ( int bound, int val ) { return ( val>=bound ); }
...
@@ -183,65 +190,93 @@ bool _cf_ge ( int bound, int val ) { return ( val>=bound ); }
int
CDTrace
::
addRule
(
std
::
string
rulestring
)
int
CDTrace
::
addRule
(
std
::
string
rulestring
)
{
{
vstring
chans_conds
=
split
(
rulestring
,
':'
);
vstring
chans_conds
=
split
(
rulestring
,
':'
);
vstring
channels
=
split
(
chans_conds
[
0
],
','
);
vstring
channels
=
split
(
chans_conds
[
0
],
','
);
vstring
conditions
=
split
(
chans_conds
[
1
],
','
);
vstring
conditions
=
split
(
chans_conds
[
1
],
','
);
/* parse the rules first */
/* parse the rules first */
std
::
vector
<
Condition
>
rule
;
std
::
vector
<
Condition
>
rule
;
for
(
vstring
::
iterator
ci
=
conditions
.
begin
();
ci
!=
conditions
.
end
();
++
ci
)
{
for
(
vstring
::
iterator
ci
=
conditions
.
begin
();
ci
!=
conditions
.
end
();
++
ci
)
/* find one of "==", "!=", "<=", ">=" */
{
const
char
*
ops_
[]
=
{
"=="
,
"!="
,
"<="
,
">="
};
/* find one of "==", "!=", "<=", ">=" */
vstring
operators
(
ops_
,
&
ops_
[
sizeof
(
ops_
)
/
sizeof
(
ops_
[
0
]
)]
);
const
char
*
ops_
[]
=
{
"=="
,
"!="
,
"<="
,
">="
};
vstring
::
iterator
oi
=
operators
.
begin
();
vstring
operators
(
ops_
,
&
ops_
[
sizeof
(
ops_
)
/
sizeof
(
ops_
[
0
])]);
std
::
size_t
pos
=
std
::
string
::
npos
;
vstring
::
iterator
oi
=
operators
.
begin
();
do
{
std
::
size_t
pos
=
std
::
string
::
npos
;
if
(
(
pos
=
ci
->
find
(
*
oi
)
)
!=
std
::
string
::
npos
)
break
;
do
}
while
(
++
oi
!=
operators
.
end
()
);
{
if
((
pos
=
ci
->
find
(
*
oi
))
!=
std
::
string
::
npos
)
/* No operator found, malformed rules string -> abort */
{
if
(
pos
==
std
::
string
::
npos
)
return
-
2
;
break
;
}
CType
ctype
(
*
ci
,
0
,
pos
);
}
while
(
++
oi
!=
operators
.
end
());
int
value
=
std
::
atoi
(
ci
->
substr
(
pos
+
2
,
ci
->
length
()
-
(
pos
+
2
)
).
c_str
()
);
//if( condition_types.find( ctype ) == condition_types.end() ) return 0;
/* No operator found, malformed rules string -> abort */
if
(
pos
==
std
::
string
::
npos
)
/* partially apply the condition value to the associated
{
* condtion function and append it to the rule */
return
-
2
;
bool
(
*
cfunc
)(
int
,
int
);
}
if
(
"=="
==
*
oi
)
cfunc
=
_cf_eq
;
else
if
(
"!="
==
*
oi
)
cfunc
=
_cf_neq
;
CType
ctype
(
*
ci
,
0
,
pos
);
else
if
(
"<="
==
*
oi
)
cfunc
=
_cf_le
;
int
value
=
std
::
atoi
(
ci
->
substr
(
pos
+
2
,
ci
->
length
()
-
(
pos
+
2
)).
c_str
());
else
if
(
">="
==
*
oi
)
cfunc
=
_cf_ge
;
// if( condition_types.find( ctype ) == condition_types.end() ) return 0;
else
return
0
;
// this is already taken care of
/* partially apply the condition value to the associated
rule
.
push_back
(
Condition
(
ctype
,
cfunc
,
value
)
);
* condtion function and append it to the rule */
bool
(
*
cfunc
)(
int
,
int
);
if
(
"=="
==
*
oi
)
{
cfunc
=
_cf_eq
;
}
else
if
(
"!="
==
*
oi
)
{
cfunc
=
_cf_neq
;
}
else
if
(
"<="
==
*
oi
)
{
cfunc
=
_cf_le
;
}
else
if
(
">="
==
*
oi
)
{
cfunc
=
_cf_ge
;
}
else
{
return
0
;
// this is already taken care of
}
}
/* add the rule to each channel */
rule
.
push_back
(
Condition
(
ctype
,
cfunc
,
value
));
for
(
vstring
::
iterator
chan_iter
=
channels
.
begin
();
chan_iter
!=
channels
.
end
();
++
chan_iter
)
{
}
std
::
map
<
Key
,
int
>::
iterator
ichan
=
deserializationTable
.
find
(
*
chan_iter
);
if
(
ichan
!=
deserializationTable
.
end
()
)
/* add the rule to each channel */
chanRules
[
ichan
->
second
].
add
(
rule
);
for
(
vstring
::
iterator
chan_iter
=
channels
.
begin
();
chan_iter
!=
channels
.
end
();
++
chan_iter
)
else
{
return
-
3
;
std
::
map
<
Key
,
int
>::
iterator
ichan
=
deserializationTable
.
find
(
*
chan_iter
);
if
(
ichan
!=
deserializationTable
.
end
())
{
chanRules
[
ichan
->
second
].
add
(
rule
);
}
}
else
{
return
-
3
;
}
}
//return (int)channels.size();
//
return (int)channels.size();
return
0
;
return
0
;
}
}
bool
CDTrace
::
update
(
state_type
stateval
)
bool
CDTrace
::
update
(
state_type
stateval
)
{
{
state
[
stateval
.
first
]
=
stateval
.
second
;
state
[
stateval
.
first
]
=
stateval
.
second
;
/* pass over all the channel rules */
/* pass over all the channel rules */
for
(
std
::
vector
<
Channel
>::
iterator
citer
=
chanRules
.
begin
();
citer
!=
chanRules
.
end
();
++
citer
)
for
(
std
::
vector
<
Channel
>::
iterator
citer
=
chanRules
.
begin
();
citer
!=
chanRules
.
end
();
++
citer
)
{
{
citer
->
update
(
state
);
citer
->
update
(
state
);
}
}
return
true
;
return
true
;
}
}
void
CDTrace
::
getChannelsList
(
std
::
string
&
sChannels
)
void
CDTrace
::
getChannelsList
(
std
::
string
&
sChannels
)
...
@@ -251,7 +286,9 @@ void CDTrace::getChannelsList( std::string& sChannels )
...
@@ -251,7 +286,9 @@ void CDTrace::getChannelsList( std::string& sChannels )
if
(
deserializationTable
.
size
()
>
0
)
if
(
deserializationTable
.
size
()
>
0
)
{
{
for
(
channel_map_t
::
iterator
it
=
deserializationTable
.
begin
();
it
!=
deserializationTable
.
end
();
++
it
)
for
(
channel_map_t
::
iterator
it
=
deserializationTable
.
begin
();
it
!=
deserializationTable
.
end
();
++
it
)
{
sChannels
+=
it
->
first
+
"
\n
"
;
sChannels
+=
it
->
first
+
"
\n
"
;
}
}
}
}
}
...
@@ -261,8 +298,12 @@ const char* CDTrace::getChannelName( int channel_number )
...
@@ -261,8 +298,12 @@ const char* CDTrace::getChannelName( int channel_number )
if
(
deserializationTable
.
size
()
>
0
)
if
(
deserializationTable
.
size
()
>
0
)
{
{
for
(
channel_map_t
::
iterator
it
=
deserializationTable
.
begin
();
it
!=
deserializationTable
.
end
();
++
it
)
for
(
channel_map_t
::
iterator
it
=
deserializationTable
.
begin
();
it
!=
deserializationTable
.
end
();
++
it
)
{
if
(
it
->
second
==
channel_number
)
if
(
it
->
second
==
channel_number
)
{
return
it
->
first
.
c_str
();
return
it
->
first
.
c_str
();
}
}
}
}
return
not_found
;
return
not_found
;
}
}
...
@@ -273,9 +314,13 @@ std::string CDTrace::getErrMessage()
...
@@ -273,9 +314,13 @@ std::string CDTrace::getErrMessage()
if
(
m_error_code
)
if
(
m_error_code
)
{
{
if
(
m_error_code
==
-
2
)
if
(
m_error_code
==
-
2
)
{
str
=
(
" - DTrace ERROR: Add tracing rule failed: DECERR_DTRACE_BAD_RULE"
);
str
=
(
" - DTrace ERROR: Add tracing rule failed: DECERR_DTRACE_BAD_RULE"
);
}
else
if
(
m_error_code
==
-
3
)
else
if
(
m_error_code
==
-
3
)
{
str
=
(
" - DTrace ERROR: Add tracing rule failed: DECERR_DTRACE_UNKNOWN_CHANNEL"
);
str
=
(
" - DTrace ERROR: Add tracing rule failed: DECERR_DTRACE_UNKNOWN_CHANNEL"
);
}
else
else
{
{
str
=
" - DTrace ERROR: Undefined error"
;
str
=
" - DTrace ERROR: Undefined error"
;
...
@@ -296,7 +341,9 @@ void CDTrace::dtrace( int k, const char *format, /*va_list args*/... )
...
@@ -296,7 +341,9 @@ void CDTrace::dtrace( int k, const char *format, /*va_list args*/... )
fflush
(
m_trace_file
);
fflush
(
m_trace_file
);
va_end
(
args
);
va_end
(
args
);
if
(
bCount
)
if
(
bCount
)
{
chanRules
[
k
].
incrementCounter
();
chanRules
[
k
].
incrementCounter
();
}
}
}
return
;
return
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment