Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
dynamic-graph
Commits
73c5966a
Unverified
Commit
73c5966a
authored
Mar 03, 2020
by
Joseph Mirabel
Committed by
GitHub
Mar 03, 2020
Browse files
Merge pull request #62 from jmirabel/devel
[TracerRealTime] Check that output file is valid.
parents
3aa6df4d
982ab8f4
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/dynamic-graph/tracer-real-time.h
View file @
73c5966a
...
...
@@ -50,17 +50,18 @@ public:
DG_TRACERREALTIME_DLLAPI
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
const
TracerRealTime
&
t
);
protected:
virtual
void
openFile
(
const
SignalBase
<
int
>
&
sig
,
const
std
::
string
&
filename
);
virtual
void
recordSignal
(
std
::
ostream
&
os
,
const
SignalBase
<
int
>
&
sig
);
void
emptyBuffers
();
void
setBufferSize
(
const
int
&
SIZE
)
{
bufferSize
=
SIZE
;
}
const
int
&
getBufferSize
()
{
return
bufferSize
;
}
protected:
virtual
void
openFile
(
const
SignalBase
<
int
>
&
sig
,
const
std
::
string
&
filename
);
virtual
void
recordSignal
(
std
::
ostream
&
os
,
const
SignalBase
<
int
>
&
sig
);
typedef
std
::
list
<
std
::
ofstream
*>
HardFileList
;
static
const
int
BUFFER_SIZE_DEFAULT
=
1048576
;
// 1Mo
...
...
src/traces/tracer-real-time.cpp
View file @
73c5966a
...
...
@@ -125,6 +125,11 @@ void TracerRealTime::openFile(const SignalBase<int> &sig,
string
filename
=
rootdir
+
basename
+
signame
+
suffix
;
dgDEBUG
(
5
)
<<
"Sig <"
<<
sig
.
getName
()
<<
">: new file "
<<
filename
<<
endl
;
std
::
ofstream
*
newfile
=
new
std
::
ofstream
(
filename
.
c_str
());
if
(
!
newfile
->
good
())
{
delete
newfile
;
DG_THROW
ExceptionTraces
(
ExceptionTraces
::
NOT_OPEN
,
"Could not open file "
+
filename
+
" for signal "
+
signame
,
""
);
}
dgDEBUG
(
5
)
<<
"Newfile:"
<<
(
void
*
)
newfile
<<
endl
;
hardFiles
.
push_back
(
newfile
);
dgDEBUG
(
5
)
<<
"Creating Outstringstream"
<<
endl
;
...
...
@@ -264,7 +269,7 @@ void TracerRealTime::recordSignal(std::ostream &os,
<<
"> "
<<
endl
;
}
catch
(
ExceptionAbstract
&
exc
)
{
throw
exc
;
throw
;
}
catch
(...)
{
DG_THROW
ExceptionTraces
(
ExceptionTraces
::
NOT_OPEN
,
"The buffer is not open"
,
""
);
...
...
src/traces/tracer.cpp
View file @
73c5966a
...
...
@@ -88,11 +88,12 @@ Tracer::Tracer(const std::string n)
void
Tracer
::
addSignalToTrace
(
const
SignalBase
<
int
>
&
sig
,
const
string
&
filename
)
{
dgDEBUGIN
(
15
);
// openFile may throw so it should be called first.
if
(
namesSet
)
openFile
(
sig
,
filename
);
toTraceSignals
.
push_back
(
&
sig
);
dgDEBUGF
(
15
,
"%p"
,
&
sig
);
names
.
push_back
(
filename
);
if
(
namesSet
)
openFile
(
sig
,
filename
);
triger
.
addDependency
(
sig
);
dgDEBUGOUT
(
15
);
}
...
...
tests/debug-real-time-tracer.cpp
View file @
73c5966a
...
...
@@ -65,37 +65,43 @@ BOOST_AUTO_TEST_CASE(test_tracer) {
std
::
string
basename
(
"my-tracer"
);
std
::
string
suffix
(
".dat"
);
/// Test openfiles
atracer
.
openFiles
(
rootdir
,
basename
,
suffix
);
atracer
.
setBufferSize
(
1
<<
14
);
/// Add trace by name
// Check that an exception is thrown if the filename is invalid.
atracer
.
openFiles
(
rootdir
,
"invalid/filename"
,
suffix
);
BOOST_CHECK_THROW
(
atracer
.
addSignalToTraceByName
(
"my-entity.out_double"
,
"output"
),
ExceptionTraces
);
// Test openfiles
atracer
.
openFiles
(
rootdir
,
basename
,
suffix
);
// Add trace by name
atracer
.
addSignalToTraceByName
(
"my-entity.out_double"
,
"output"
);
/// Add trace by name
SignalBase
<
int
>
&
aSignal
=
entity
.
getSignal
(
"out2double"
);
entity
.
m_sigdTwoTimeDepSOUT
.
recompute
(
2
);
SignalBase
<
int
>
&
out_double
=
entity
.
getSignal
(
"out_double"
);
SignalBase
<
int
>
&
out_double_2
=
entity
.
getSignal
(
"out2double"
);
Signal
<
double
,
int
>
&
aSignalInt
=
Signal
<
double
,
int
>
&
in_double
=
*
(
dynamic_cast
<
Signal
<
double
,
int
>
*>
(
&
entity
.
getSignal
(
"in_double"
)));
aSignalInt
.
setConstant
(
1.5
);
in_double
.
setConstant
(
1.5
);
atracer
.
start
();
atracer
.
trace
();
std
::
string
emptybuf_cmd_str
(
"empty"
);
command
::
Command
*
acmd
=
atracer
.
getNewStyleCommand
(
emptybuf_cmd_str
);
acmd
->
execute
();
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
aSignal
.
setTime
(
i
);
aSignalInt
.
setTime
(
i
);
in_double
.
setTime
(
i
);
out_double
.
recompute
(
i
);
out_double_2
.
recompute
(
i
);
atracer
.
recordTrigger
(
i
,
i
);
}
output_test_stream
output
;
atracer
.
display
(
output
);
atracer
.
stop
();
atracer
.
trace
();
atracer
.
clearSignalToTrace
();
atracer
.
closeFiles
();
acmd
->
execute
();
...
...
@@ -105,5 +111,5 @@ BOOST_AUTO_TEST_CASE(test_tracer) {
"TracerRealTime my-tracer [mode=play] :
\n
"
" - Dep list:
\n
"
" -> MyEntity(my-entity)::input(double)::out_double (in output)"
" [
0M
o/1
M
o]
\n
"
));
" [
9K
o/1
6K
o]
\n
"
));
}
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment