Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
acgl
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ACGL
acgl
Commits
ac88dd23
Commit
ac88dd23
authored
Feb 13, 2013
by
Robert Menzel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemented faster logging
parent
e4210c68
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
10 deletions
+37
-10
include/ACGL/Utils/Log.hh
include/ACGL/Utils/Log.hh
+17
-10
src/ACGL/Utils/Log.cc
src/ACGL/Utils/Log.cc
+20
-0
No files found.
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
Markdown
is supported
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