Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
509656b2
Commit
509656b2
authored
Oct 30, 2019
by
Michael Ott
Browse files
Reformatted dcdbpusher code with clang-format to establish common coding style
parent
2d8dc277
Changes
90
Expand all
Show whitespace changes
Inline
Side-by-side
.clang-format
0 → 100644
View file @
509656b2
BasedOnStyle: LLVM
IndentWidth: 8
UseTab: ForContinuationAndIndentation
BreakBeforeBraces: Attach
AlignConsecutiveDeclarations: true
AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: Inline
ColumnLimit: 0
IndentCaseLabels: true
dcdbpusher/Caliper/dcdbpusher/DcdbPusher.cpp
View file @
509656b2
...
...
@@ -63,10 +63,10 @@
#include <errno.h>
#include <fcntl.h>
#include <features.h>
#include <shared_mutex>
#include <sched.h>
#include <semaphore.h>
#include <set>
#include <shared_mutex>
#include <string.h>
#include <thread>
#include <unistd.h>
...
...
@@ -78,17 +78,17 @@
#include <sys/types.h>
#include <sys/un.h>
#include <libelf.h>
#include <gelf.h>
#include <libelf.h>
using
namespace
cali
;
namespace
{
//TODO move definitions into common header file for cali service and pusher plugin
#define MSGQ_SIZE
16*
1024
*
1024
#define MSGQ_SIZE
16 *
1024
*
1024
#define STR_PREFIX "/cali_dcdb_"
#define SHM_SIZE
(17*
1024
*
1024)
#define SHM_SIZE
(17 *
1024
*
1024)
#define SOCK_NAME "DCDBPusherCaliSocket"
/*
...
...
@@ -114,7 +114,7 @@ class DcdbPusher {
std
::
string
name
;
/* make it sortable for faster lookups */
bool
operator
<
(
const
func_symbol
&
rhs
)
const
{
bool
operator
<
(
const
func_symbol
&
rhs
)
const
{
return
end_addr
<
rhs
.
end_addr
;
}
};
...
...
@@ -129,13 +129,12 @@ class DcdbPusher {
// "[Anonymous]" if unknown
/* make it sortable for faster lookups */
bool
operator
<
(
const
addr_range
&
rhs
)
const
{
bool
operator
<
(
const
addr_range
&
rhs
)
const
{
return
end_addr
<
rhs
.
end_addr
;
}
};
private:
private:
static
const
ConfigSet
::
Entry
s_configdata
[];
/* General service attributes */
...
...
@@ -144,12 +143,12 @@ private:
unsigned
snapshots_sampler
=
0
;
unsigned
snapshots_event
=
0
;
Attribute
sampler_pc
{
Attribute
::
invalid
};
Attribute
event_begin
{
Attribute
::
invalid
};
Attribute
event_set
{
Attribute
::
invalid
};
Attribute
event_end
{
Attribute
::
invalid
};
Attribute
timestamp
{
Attribute
::
invalid
};
Attribute
thread_id
{
Attribute
::
invalid
};
Attribute
sampler_pc
{
Attribute
::
invalid
};
Attribute
event_begin
{
Attribute
::
invalid
};
Attribute
event_set
{
Attribute
::
invalid
};
Attribute
event_end
{
Attribute
::
invalid
};
Attribute
timestamp
{
Attribute
::
invalid
};
Attribute
thread_id
{
Attribute
::
invalid
};
/* We store information about function symbols and their addresses here */
std
::
set
<
addr_range
>
addr_data
;
...
...
@@ -168,7 +167,7 @@ private:
*/
//TODO investigate consequences of fork() on Caliper - DCDBPusher construct
void
*
shm
;
// pointer to shared memory object
void
*
shm
;
// pointer to shared memory object
int
shm_file
;
// fd of the underlying shared memory file
int
sock
;
// unix socket fd for initial shm setup communication
...
...
@@ -210,10 +209,10 @@ private:
const
uintptr_t
start_addr
,
const
uintptr_t
end_addr
,
const
uintptr_t
offset
,
std
::
set
<
func_symbol
>
&
dest
,
Channel
*
chn
)
{
Elf
*
elf
;
Elf_Scn
*
scn
=
NULL
;
std
::
set
<
func_symbol
>
&
dest
,
Channel
*
chn
)
{
Elf
*
elf
;
Elf_Scn
*
scn
=
NULL
;
GElf_Ehdr
ehdr
;
GElf_Shdr
shdr
;
Elf_Data
*
data
;
...
...
@@ -277,7 +276,7 @@ private:
//retrieve symbol data
int
count
=
shdr
.
sh_size
/
shdr
.
sh_entsize
;
//debug
// printf("Section has %d symbols\n", count);
// printf("Section has %d symbols\n", count);
for
(
int
ii
=
0
;
ii
<
count
;
++
ii
)
{
GElf_Sym
sym
;
...
...
@@ -293,8 +292,8 @@ private:
}
//resolve symbol name
char
*
symstr
;
char
*
dsymstr
;
char
*
symstr
;
char
*
dsymstr
;
func_symbol
symdat
;
...
...
@@ -309,7 +308,7 @@ private:
if
(
status
==
0
)
{
symdat
.
name
=
std
::
string
(
dsymstr
);
free
((
void
*
)
dsymstr
);
free
((
void
*
)
dsymstr
);
}
else
{
symdat
.
name
=
std
::
string
(
symstr
);
}
...
...
@@ -325,29 +324,29 @@ private:
symdat
.
start_addr
<=
end_addr
)
{
//debug
// printf("Symbol %s in mem range (%llx-%llx, size %llx)\n", symdat.name,
// symdat.start_addr,
// symdat.end_addr,
// sym.st_size);
// printf("Symbol %s in mem range (%llx-%llx, size %llx)\n", symdat.name,
// symdat.start_addr,
// symdat.end_addr,
// sym.st_size);
if
(
!
dest
.
insert
(
symdat
).
second
)
{
//TODO check again here
//Log(1).stream() << chn->name() << ": DcdbPusher: Could not insert symbol!" << std::endl;
}
}
else
{
// printf("Symbol %s out of mem range (%llx-%llx, size %llx)\n", symdat.name,
// symdat.start_addr,
// symdat.end_addr,
// sym.st_size);
// printf("Symbol %s out of mem range (%llx-%llx, size %llx)\n", symdat.name,
// symdat.start_addr,
// symdat.end_addr,
// sym.st_size);
}
}
//debug
// printf("%s:\n", filename.c_str());
// if (shdr.sh_type == SHT_DYNSYM) {
// printf("Retrieved %d symbols of dynsym\n", dest.size());
// } else {
// printf("Retrieved %d symbols of symtab\n", dest.size());
// }
// printf("%s:\n", filename.c_str());
// if (shdr.sh_type == SHT_DYNSYM) {
// printf("Retrieved %d symbols of dynsym\n", dest.size());
// } else {
// printf("Retrieved %d symbols of symtab\n", dest.size());
// }
elf_end
(
elf
);
close
(
fd
);
...
...
@@ -364,8 +363,8 @@ private:
* Fortran -> mangling compiler dependent; no demangling implemented,
* other languages?)
*/
bool
read_addr_data
(
Channel
*
chn
)
{
FILE
*
file
;
bool
read_addr_data
(
Channel
*
chn
)
{
FILE
*
file
;
addr_range
addr
;
char
exec
;
uintptr_t
offset
;
...
...
@@ -381,7 +380,7 @@ private:
}
//read one line = one address range
while
(
fscanf
(
file
,
"%llx-%llx %*2c%1c%*s%llx%*s%*s%4096[^
\n
]"
,
while
(
fscanf
(
file
,
"%llx-%llx %*2c%1c%*s%llx%*s%*s%4096[^
\n
]"
,
&
(
addr
.
start_addr
),
&
(
addr
.
end_addr
),
&
exec
,
...
...
@@ -428,8 +427,8 @@ private:
}
}
fclose
(
file
);
// Log(1).stream() << chn->name() << ": DcdbPusher: Scan error: "
// << strerror(errno) << std::endl;
// Log(1).stream() << chn->name() << ": DcdbPusher: Scan error: "
// << strerror(errno) << std::endl;
return
true
;
}
...
...
@@ -451,7 +450,7 @@ private:
* be resolved it notifies us and this thread comes into
* play. Updates the symbol data in the shared memory file.
*/
void
startSUS
(
Channel
*
chn
)
{
void
startSUS
(
Channel
*
chn
)
{
stopSUS
();
run_sus
.
store
(
true
,
std
::
memory_order_release
);
sus
=
std
::
thread
([
=
]()
{
...
...
@@ -485,13 +484,13 @@ private:
void
print_debug_shm
()
{
size_t
sym_cnt
;
for
(
const
auto
&
a
:
addr_data
)
{
for
(
const
auto
&
a
:
addr_data
)
{
printf
(
"Mem range %s: %llx-%llx contains %d symbols:
\n
"
,
a
.
pathname
,
a
.
start_addr
,
a
.
end_addr
,
a
.
symbols
.
size
());
for
(
const
auto
&
f
:
a
.
symbols
)
{
for
(
const
auto
&
f
:
a
.
symbols
)
{
printf
(
"> (%llx-%llx) %s
\n
"
,
f
.
start_addr
,
f
.
end_addr
,
f
.
name
);
...
...
@@ -513,41 +512,40 @@ private:
size_t
r_index
;
sem_t
*
r_sem
;
sem_t
*
w_sem
;
sem_t
*
r_sem
;
sem_t
*
w_sem
;
char
*
msg_queue
;
char
*
msg_queue
;
r_sem
=
reinterpret_cast
<
sem_t
*>
(
static_cast
<
char
*>
(
shm
)
+
2
*
sizeof
(
size_t
));
r_sem
=
reinterpret_cast
<
sem_t
*>
(
static_cast
<
char
*>
(
shm
)
+
2
*
sizeof
(
size_t
));
w_sem
=
r_sem
+
1
;
msg_queue
=
reinterpret_cast
<
char
*>
(
w_sem
+
1
);
msg_queue
=
reinterpret_cast
<
char
*>
(
w_sem
+
1
);
//TODO atomic load/stores instead of semaphore locking?
if
(
sem_wait
(
r_sem
))
{
return
false
;
}
r_index
=
*
(
reinterpret_cast
<
size_t
*>
(
static_cast
<
char
*>
(
shm
)));
r_index
=
*
(
reinterpret_cast
<
size_t
*>
(
static_cast
<
char
*>
(
shm
)));
sem_post
(
r_sem
);
if
(
sem_trywait
(
w_sem
))
{
return
false
;
}
size_t
&
w_index
=
*
(
reinterpret_cast
<
size_t
*>
(
static_cast
<
char
*>
(
shm
)
+
sizeof
(
size_t
)));
size_t
&
w_index
=
*
(
reinterpret_cast
<
size_t
*>
(
static_cast
<
char
*>
(
shm
)
+
sizeof
(
size_t
)));
bool
ret
=
false
;
const
size_t
bytes_avail
=
w_index
<
r_index
?
(
r_index
-
w_index
-
1
)
:
(
MSGQ_SIZE
-
w_index
+
r_index
-
1
);
const
size_t
bytes_avail
=
w_index
<
r_index
?
(
r_index
-
w_index
-
1
)
:
(
MSGQ_SIZE
-
w_index
+
r_index
-
1
);
if
(
bytes_avail
>=
shm_buf_idx
)
{
if
((
w_index
+
shm_buf_idx
)
>=
MSGQ_SIZE
)
{
//wrap around end of queue
size_t
sep
=
MSGQ_SIZE
-
w_index
-
1
;
memcpy
(
&
msg_queue
[
w_index
+
1
],
shm_buf
,
sep
);
memcpy
(
msg_queue
,
&
shm_buf
[
sep
],
(
shm_buf_idx
-
sep
));
memcpy
(
&
msg_queue
[
w_index
+
1
],
shm_buf
,
sep
);
memcpy
(
msg_queue
,
&
shm_buf
[
sep
],
(
shm_buf_idx
-
sep
));
w_index
+=
shm_buf_idx
;
w_index
%=
MSGQ_SIZE
;
}
else
{
memcpy
(
&
msg_queue
[
w_index
+
1
],
shm_buf
,
shm_buf_idx
);
memcpy
(
&
msg_queue
[
w_index
+
1
],
shm_buf
,
shm_buf_idx
);
w_index
+=
shm_buf_idx
;
}
shm_buf_idx
=
0
;
...
...
@@ -558,7 +556,7 @@ private:
return
ret
;
}
void
post_init_cb
(
Caliper
*
c
,
Channel
*
chn
)
{
void
post_init_cb
(
Caliper
*
c
,
Channel
*
chn
)
{
bool
sampler_detected
=
false
;
bool
event_detected
=
false
;
...
...
@@ -592,7 +590,8 @@ private:
if
(
!
(
sampler_detected
||
event_detected
))
{
Log
(
1
).
stream
()
<<
chn
->
name
()
<<
": DcdbPusher: at least one of the following service combinations is required: "
">sampler,pthread,timestamp< or >event,timestamp<"
<<
std
::
endl
;
">sampler,pthread,timestamp< or >event,timestamp<"
<<
std
::
endl
;
return
;
}
...
...
@@ -608,7 +607,7 @@ private:
return
;
}
shm
=
mmap
(
NULL
,
SHM_SIZE
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
shm_file
,
0
);
if
(
shm
==
(
void
*
)
-
1
)
{
if
(
shm
==
(
void
*
)
-
1
)
{
Log
(
1
).
stream
()
<<
chn
->
name
()
<<
": DcdbPusher: Failed to mmap shm_file: "
<<
strerror
(
errno
)
<<
std
::
endl
;
shm
=
NULL
;
...
...
@@ -622,14 +621,14 @@ private:
}
//init r/w_index
*
(
reinterpret_cast
<
size_t
*>
(
static_cast
<
char
*>
(
shm
)))
=
0
;
*
(
reinterpret_cast
<
size_t
*>
(
static_cast
<
char
*>
(
shm
)
+
sizeof
(
size_t
)))
=
0
;
*
(
reinterpret_cast
<
size_t
*>
(
static_cast
<
char
*>
(
shm
)))
=
0
;
*
(
reinterpret_cast
<
size_t
*>
(
static_cast
<
char
*>
(
shm
)
+
sizeof
(
size_t
)))
=
0
;
//init semaphores
sem_t
*
r_sem
;
sem_t
*
w_sem
;
sem_t
*
r_sem
;
sem_t
*
w_sem
;
r_sem
=
reinterpret_cast
<
sem_t
*>
(
static_cast
<
char
*>
(
shm
)
+
2
*
sizeof
(
size_t
));
r_sem
=
reinterpret_cast
<
sem_t
*>
(
static_cast
<
char
*>
(
shm
)
+
2
*
sizeof
(
size_t
));
w_sem
=
r_sem
+
1
;
if
(
sem_init
(
r_sem
,
1
,
1
)
||
...
...
@@ -662,7 +661,7 @@ private:
addr
.
sun_family
=
AF_UNIX
;
snprintf
(
&
addr
.
sun_path
[
1
],
91
,
SOCK_NAME
);
if
(
connect
(
sock
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
)))
{
if
(
connect
(
sock
,
(
struct
sockaddr
*
)
&
addr
,
sizeof
(
addr
)))
{
Log
(
1
).
stream
()
<<
chn
->
name
()
<<
": DcdbPusher: Failed to connect socket: "
<<
strerror
(
errno
)
<<
std
::
endl
;
close
(
sock
);
...
...
@@ -685,7 +684,7 @@ private:
initialized
=
true
;
}
void
process_snapshot_cb
(
Caliper
*
c
,
Channel
*
chn
,
const
SnapshotRecord
*
,
const
SnapshotRecord
*
sbuf
)
{
void
process_snapshot_cb
(
Caliper
*
c
,
Channel
*
chn
,
const
SnapshotRecord
*
,
const
SnapshotRecord
*
sbuf
)
{
++
snapshots_processed
;
// NOTE sampler invoked snapshots are always signals, so better do nothing signal "un-safe" in the case of sampler invoked snapshots
//if (c->is_signal()) {
...
...
@@ -825,11 +824,11 @@ private:
memcpy
(
&
shm_buf
[
shm_buf_idx
],
&
ts
,
sizeof
(
ts
));
shm_buf_idx
+=
sizeof
(
ts
);
//must write a NUL terminated string
memcpy
(
&
shm_buf
[
shm_buf_idx
],
(
void
*
)
data
,
data_size
);
memcpy
(
&
shm_buf
[
shm_buf_idx
],
(
void
*
)
data
,
data_size
);
shm_buf_idx
+=
data_size
;
}
void
finish_cb
(
Caliper
*
c
,
Channel
*
chn
)
{
void
finish_cb
(
Caliper
*
c
,
Channel
*
chn
)
{
initialized
=
false
;
stopSUS
();
...
...
@@ -838,7 +837,7 @@ private:
shm
=
NULL
;
}
if
(
shm_file
!=
-
1
)
{
if
(
shm_file
!=
-
1
)
{
shm_unlink
((
STR_PREFIX
+
pid_str
).
c_str
());
close
(
shm_file
);
shm_file
=
-
1
;
...
...
@@ -856,18 +855,18 @@ private:
snapshots_event
=
0
;
}
void
create_thread_cb
(
Caliper
*
c
,
Channel
*
chn
)
{
void
create_thread_cb
(
Caliper
*
c
,
Channel
*
chn
)
{
shm_buf_idx
=
0
;
}
void
release_thread_cb
(
Caliper
*
c
,
Channel
*
chn
)
{
void
release_thread_cb
(
Caliper
*
c
,
Channel
*
chn
)
{
if
(
shm
!=
NULL
)
{
flush_buf
();
}
}
DcdbPusher
(
Caliper
*
c
,
Channel
*
chn
)
:
shm
(
NULL
),
DcdbPusher
(
Caliper
*
c
,
Channel
*
chn
)
:
shm
(
NULL
),
shm_file
(
-
1
),
sock
(
-
1
),
run_sus
(
false
),
...
...
@@ -881,31 +880,30 @@ private:
sus_cycle
=
cfg
.
get
(
"sus_cycle"
).
to_uint
();
}
public:
public:
~
DcdbPusher
()
{}
static
void
dcdbpusher_register
(
Caliper
*
c
,
Channel
*
chn
)
{
DcdbPusher
*
instance
=
new
DcdbPusher
(
c
,
chn
);
static
void
dcdbpusher_register
(
Caliper
*
c
,
Channel
*
chn
)
{
DcdbPusher
*
instance
=
new
DcdbPusher
(
c
,
chn
);
chn
->
events
().
create_thread_evt
.
connect
(
[
instance
](
Caliper
*
c
,
Channel
*
chn
){
[
instance
](
Caliper
*
c
,
Channel
*
chn
)
{
instance
->
create_thread_cb
(
c
,
chn
);
});
chn
->
events
().
release_thread_evt
.
connect
(
[
instance
](
Caliper
*
c
,
Channel
*
chn
){
[
instance
](
Caliper
*
c
,
Channel
*
chn
)
{
instance
->
release_thread_cb
(
c
,
chn
);
});
chn
->
events
().
post_init_evt
.
connect
(
[
instance
](
Caliper
*
c
,
Channel
*
chn
){
[
instance
](
Caliper
*
c
,
Channel
*
chn
)
{
instance
->
post_init_cb
(
c
,
chn
);
});
chn
->
events
().
process_snapshot
.
connect
(
[
instance
](
Caliper
*
c
,
Channel
*
chn
,
const
SnapshotRecord
*
trigger
,
const
SnapshotRecord
*
snapshot
){
[
instance
](
Caliper
*
c
,
Channel
*
chn
,
const
SnapshotRecord
*
trigger
,
const
SnapshotRecord
*
snapshot
)
{
instance
->
process_snapshot_cb
(
c
,
chn
,
trigger
,
snapshot
);
});
chn
->
events
().
finish_evt
.
connect
(
[
instance
](
Caliper
*
c
,
Channel
*
chn
){
[
instance
](
Caliper
*
c
,
Channel
*
chn
)
{
instance
->
finish_cb
(
c
,
chn
);
delete
instance
;
});
...
...
@@ -915,16 +913,14 @@ public:
};
// class DcdbPusher
const
ConfigSet
::
Entry
DcdbPusher
::
s_configdata
[]
=
{
{
"sus_cycle"
,
CALI_TYPE_UINT
,
"15"
,
{
"sus_cycle"
,
CALI_TYPE_UINT
,
"15"
,
"Symbol update service cycle in seconds (time between checks if update required"
,
"Symbol update service cycle in seconds (time between checks if update required"
},
"Symbol update service cycle in seconds (time between checks if update required"
},
ConfigSet
::
Terminator
};
ConfigSet
::
Terminator
};
}
// namespace
namespace
cali
{
CaliperService
dcdbpusher_service
{
"dcdbpusher"
,
::
DcdbPusher
::
dcdbpusher_register
};
CaliperService
dcdbpusher_service
{
"dcdbpusher"
,
::
DcdbPusher
::
dcdbpusher_register
};
}
dcdbpusher/Configuration.cpp
View file @
509656b2
...
...
@@ -35,10 +35,10 @@ bool Configuration::readAdditionalValues(boost::property_tree::iptree::value_typ
// ----- READING ADDITIONAL GLOBAL SETTINGS -----
if
(
boost
::
iequals
(
global
.
first
,
"mqttBroker"
))
{
brokerHost
=
parseNetworkHost
(
global
.
second
.
data
());
brokerPort
=
parseNetworkPort
(
global
.
second
.
data
())
==
""
?
BROKERPORT
:
stoi
(
parseNetworkPort
(
global
.
second
.
data
()));
brokerPort
=
parseNetworkPort
(
global
.
second
.
data
())
==
""
?
BROKERPORT
:
stoi
(
parseNetworkPort
(
global
.
second
.
data
()));
}
else
if
(
boost
::
iequals
(
global
.
first
,
"qosLevel"
))
{
qosLevel
=
stoi
(
global
.
second
.
data
());
if
(
qosLevel
>
2
||
qosLevel
<
0
)
if
(
qosLevel
>
2
||
qosLevel
<
0
)
qosLevel
=
1
;
}
else
if
(
boost
::
iequals
(
global
.
first
,
"maxInflightMsgNum"
))
{
maxInflightMsgNum
=
stoull
(
global
.
second
.
data
());
...
...
@@ -52,21 +52,21 @@ bool Configuration::readAdditionalValues(boost::property_tree::iptree::value_typ
return
true
;
}
bool
Configuration
::
readPlugins
(
PluginManager
&
pluginManager
)
{
bool
Configuration
::
readPlugins
(
PluginManager
&
pluginManager
)
{
std
::
string
globalConfig
=
_cfgFilePath
;
globalConfig
.
append
(
_cfgFileName
);
boost
::
property_tree
::
iptree
cfg
;
try
{
boost
::
property_tree
::
read_info
(
globalConfig
,
cfg
);
}
catch
(
boost
::
property_tree
::
info_parser_error
&
e
)
{
}
catch
(
boost
::
property_tree
::
info_parser_error
&
e
)
{
LOG
(
error
)
<<
"Error when reading plugins from "
<<
_cfgFileName
<<
": "
<<
e
.
what
();
return
false
;
}
pluginManager
.
setCfgFilePath
(
_cfgFilePath
);
//read plugins
BOOST_FOREACH
(
boost
::
property_tree
::
iptree
::
value_type
&
plugin
,
cfg
.
get_child
(
"plugins"
))
{
BOOST_FOREACH
(
boost
::
property_tree
::
iptree
::
value_type
&
plugin
,
cfg
.
get_child
(
"plugins"
))
{
if
(
boost
::
iequals
(
plugin
.
first
,
"plugin"
))
{
if
(
!
plugin
.
second
.
data
().
empty
())
{
std
::
string
pluginName
=
plugin
.
second
.
data
();
...
...
@@ -75,7 +75,7 @@ bool Configuration::readPlugins(PluginManager& pluginManager) {
LOG
(
info
)
<<
"Read plugin "
<<
pluginName
<<
"..."
;
BOOST_FOREACH
(
boost
::
property_tree
::
iptree
::
value_type
&
val
,
plugin
.
second
)
{
BOOST_FOREACH
(
boost
::
property_tree
::
iptree
::
value_type
&
val
,
plugin
.
second
)
{
if
(
boost
::
iequals
(
val
.
first
,
"path"
))
{
pluginPath
=
val
.
second
.
data
();
}
else
if
(
boost
::
iequals
(
val
.
first
,
"config"
))
{
...
...
@@ -85,7 +85,7 @@ bool Configuration::readPlugins(PluginManager& pluginManager) {
}
}
if
(
!
pluginManager
.
loadPlugin
(
pluginName
,
pluginPath
,
pluginConfig
))
{
if
(
!
pluginManager
.
loadPlugin
(
pluginName
,
pluginPath
,
pluginConfig
))
{
LOG
(
error
)
<<
"Could not load plugin "
<<
pluginName
;
pluginManager
.
unloadPlugin
();
return
false
;
...
...
dcdbpusher/Configuration.h
View file @
509656b2
...
...
@@ -44,15 +44,15 @@
*/
class
Configuration
:
public
GlobalConfiguration
{
public:
public:
/**
* Create new Configuration. Sets global config file to read from to cfgFile.
*
* @param cfgFilePath Path to where all config-files are located
* @param cfgFileName Name of the file containing the config
*/
Configuration
(
const
std
::
string
&
cfgFilePath
,
const
std
::
string
&
cfgFileName
)
:
GlobalConfiguration
(
cfgFilePath
,
cfgFileName
)
{}
Configuration
(
const
std
::
string
&
cfgFilePath
,
const
std
::
string
&
cfgFileName
)
:
GlobalConfiguration
(
cfgFilePath
,
cfgFileName
)
{}
virtual
~
Configuration
()
{}
...
...
@@ -64,7 +64,7 @@ public:
*
* @return true on success, false otherwise
*/
bool
readPlugins
(
PluginManager
&
pluginManager
);
bool
readPlugins
(
PluginManager
&
pluginManager
);
// Additional configuration parameters to be parsed and stored in the global block
int
qosLevel
=
1
;
...
...
@@ -74,8 +74,7 @@ public:
std
::
string
brokerHost
=
BROKERHOST
;
int
maxMsgNum
=
0
;
protected:
protected:
bool
readAdditionalValues
(
boost
::
property_tree
::
iptree
::
value_type
&
global
)
override
;
};
...
...
dcdbpusher/MQTTPusher.cpp
View file @
509656b2
...
...
@@ -26,14 +26,14 @@
//================================================================================
#include "MQTTPusher.h"
#include "timestamp.h"
#include <iostream>
#include <string>
#include <unistd.h>
#include "timestamp.h"
MQTTPusher
::
MQTTPusher
(
int
brokerPort
,
const
std
::
string
&
brokerHost
,
const
bool
autoPublish
,
int
qosLevel
,
pusherPluginStorage_t
&
plugins
,
op_pluginVector_t
&
oPlugins
,
int
maxNumberOfMessages
,
unsigned
int
maxInflightMsgNum
,
unsigned
int
maxQueuedMsgNum
)
:
_qosLevel
(
qosLevel
),
MQTTPusher
::
MQTTPusher
(
int
brokerPort
,
const
std
::
string
&
brokerHost
,
const
bool
autoPublish
,
int
qosLevel
,
pusherPluginStorage_t
&
plugins
,
op_pluginVector_t
&
oPlugins
,
int
maxNumberOfMessages
,
unsigned
int
maxInflightMsgNum
,
unsigned
int
maxQueuedMsgNum
)
:
_qosLevel
(
qosLevel
),
_brokerPort
(
brokerPort
),
_brokerHost
(
brokerHost
),
_autoPublish
(
autoPublish
),
...
...
@@ -75,7 +75,7 @@ MQTTPusher::MQTTPusher(int brokerPort, const std::string& brokerHost, const bool
}
MQTTPusher
::~
MQTTPusher
()
{
if
(
_connected
)
{
if
(
_connected
)
{
mosquitto_disconnect
(
_mosq
);
}
mosquitto_destroy
(
_mosq
);
...
...
@@ -101,7 +101,7 @@ void MQTTPusher::push() {
computeMsgRate
();
//collect sensor-data
reading_t
*
reads
=
new
reading_t
[
SensorBase
::
QUEUE_MAXLIMIT
];
reading_t
*
reads
=
new
reading_t
[
SensorBase
::
QUEUE_MAXLIMIT
];
std
::
size_t
totalCount
=
0
;
//number of messages
while
(
_keepRunning
||
totalCount
)
{
if
(
_doHalt
)
{
...
...
@@ -124,7 +124,7 @@ void MQTTPusher::push() {
}
if
(
_connected
)
{
if
(
getTimestamp
()
-
idleTime
>=
PUSHER_IDLETIME
)
{
if
(
getTimestamp
()
-
idleTime
>=
PUSHER_IDLETIME
)
{
idleTime
=
getTimestamp
();
totalCount
=
0
;
// Push sensor data
...
...
@@ -154,11 +154,11 @@ void MQTTPusher::push() {
break
;
}
for
(
const
auto
&
op
:
p
.
configurator
->
getOperators
())
{
if
(
op
->
getStreaming
())
{
if
(
op
->
getStreaming
())
{
for
(
const
auto
&
u
:
op
->
getUnits
())
{
for
(
const
auto
&
s
:
u
->
getBaseOutputs
())
{
if
(
s
->
getSizeOfReadingQueue
()
>=
op
->
getMinValues
())
{
if
(
_msgCap
==
DISABLED
||
totalCount
<
(
unsigned
)
_maxNumberOfMessages
)
{