Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ACGL
acgl
Commits
ac88dd23
Commit
ac88dd23
authored
Feb 13, 2013
by
Robert Menzel
Browse files
implemented faster logging
parent
e4210c68
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/ACGL/Utils/Log.hh
View file @
ac88dd23
...
...
@@ -58,29 +58,31 @@ class CoutLikeStreamBuffer : public std::basic_streambuf<char, std::char_traits<
public:
CoutLikeStreamBuffer
();
~
CoutLikeStreamBuffer
();
//! sets the prefix of each line
void
setPrefix
(
const
std
::
string
&
_prefix
);
//! sets the filename of the file to mirror everything into, set to "" to disable mirroring
void
setFilename
(
const
std
::
string
&
_filename
);
private:
//virtual std::streamsize xsputn(const base_type::char_type* s, std::streamsize n)
//{
// TODO: implement me for better performance
//}
private:
//! gets called when multiple chars should get written
virtual
std
::
streamsize
xsputn
(
const
base_type
::
char_type
*
s
,
std
::
streamsize
n
);
//! gets called when the buffer is full ans a single char gets written
virtual
base_type
::
int_type
overflow
(
base_type
::
int_type
ch
);
// for each endl:
//
! gets called
for each endl:
virtual
int
sync
();
//! used to mirror the output also into a file
void
mirrorToFile
(
const
std
::
string
&
_token
);
private:
char
*
mBuffer
;
std
::
string
mPrefix
;
size_t
mBufferSize
;
// how many bytes are used
char
*
mBuffer
;
// string buffer
std
::
string
mPrefix
;
// prefix used for each new line of this stream
size_t
mBufferSize
;
// how many bytes are used
in the buffer
size_t
mBufferMaxSize
;
// size of the buffer
bool
mNewLineIsAboutToStart
;
...
...
@@ -138,6 +140,7 @@ public:
delete
mStreamBuffer
;
}
//! sets the prefix of each line
void
setPrefix
(
const
std
::
string
&
_prefix
)
{
if
(
mStreamBuffer
)
{
mStreamBuffer
->
setPrefix
(
_prefix
);
...
...
@@ -151,7 +154,11 @@ public:
mStreamBuffer
->
setFilename
(
_filename
);
}
}
//! disable all output from this stream
void
mute
()
{
rdbuf
(
NULL
);
}
//! reenable all output
void
unmute
()
{
rdbuf
(
mStreamBuffer
);
}
private:
CoutLikeStreamBuffer
*
mStreamBuffer
;
...
...
src/ACGL/Utils/Log.cc
View file @
ac88dd23
...
...
@@ -5,6 +5,7 @@
**********************************************************************/
#include <ACGL/Utils/Log.hh>
#include <ACGL/Math/Math.hh>
#include <cstdio>
#include <iostream>
...
...
@@ -54,6 +55,25 @@ void CoutLikeStreamBuffer::mirrorToFile( const std::string &_token ) {
file
.
close
();
}
std
::
streamsize
CoutLikeStreamBuffer
::
xsputn
(
const
base_type
::
char_type
*
s
,
std
::
streamsize
n
)
{
size_t
charsWritten
=
0
;
while
(
charsWritten
<
(
size_t
)
n
)
{
int
maxToCopy
=
std
::
min
(
(
size_t
)
n
-
charsWritten
,
mBufferMaxSize
-
mBufferSize
);
memcpy
(
mBuffer
+
mBufferSize
,
s
+
charsWritten
,
maxToCopy
);
charsWritten
+=
maxToCopy
;
mBufferSize
+=
maxToCopy
;
if
(
charsWritten
<
(
size_t
)
n
)
{
overflow
(
(
base_type
::
int_type
)
s
[
charsWritten
]
);
charsWritten
++
;
}
};
return
n
;
}
CoutLikeStreamBuffer
::
base_type
::
int_type
CoutLikeStreamBuffer
::
overflow
(
base_type
::
int_type
ch
)
{
// print buffer
if
((
mBufferSize
>=
mBufferMaxSize
)
||
(
base_type
::
traits_type
::
eq_int_type
(
ch
,
base_type
::
traits_type
::
eof
())))
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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