Skip to content

Commit 5a56316

Browse files
author
Artyom Abakumov
committed
Load trace plugins directly via PluginManager and allow to set requeued plugins for trace session
1 parent 58d28af commit 5a56316

File tree

18 files changed

+136
-125
lines changed

18 files changed

+136
-125
lines changed

doc/README.services_extension

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ Start user trace session :
7070
isc_action_svc_trace_start
7171

7272
parameter(s)
73-
isc_spb_trc_name : trace session name, string, optional
74-
isc_spb_trc_cfg : trace session configuration, string, mandatory
73+
isc_spb_trc_name : trace session name, string, optional
74+
isc_spb_trc_cfg : trace session configuration, string, mandatory
75+
isc_spb_trc_plugins : plugins to use for session
7576

7677
output
7778
text message with status of operation :

doc/README.trace_services

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Action parameters switches :
8181
-N[AME] <string> Session name
8282
-I[D] <number> Session ID
8383
-C[ONFIG] <string> Trace configuration file name
84+
-P[LUGINS] <string list> Plugins list to use for trace session
8485

8586
Connection parameters switches :
8687
-SE[RVICE] <string> Service name

src/common/IntlParametersBlock.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ IntlParametersBlock::TagType IntlSpbStart::checkTag(UCHAR tag, const char** tagN
309309
{
310310
FB_IPB_TAG(isc_spb_trc_name);
311311
FB_IPB_TAG(isc_spb_trc_cfg);
312+
FB_IPB_TAG(isc_spb_trc_plugins);
312313
return TAG_STRING;
313314
}
314315
break;

src/common/classes/ClumpletReader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ ClumpletReader::ClumpletType ClumpletReader::getClumpletType(UCHAR tag) const
476476
{
477477
case isc_spb_trc_cfg:
478478
case isc_spb_trc_name:
479+
case isc_spb_trc_plugins:
479480
return StringSpb;
480481
case isc_spb_trc_id:
481482
return IntSpb;

src/include/firebird/impl/consts_pub.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@
657657
#define isc_spb_trc_id 1
658658
#define isc_spb_trc_name 2
659659
#define isc_spb_trc_cfg 3
660+
#define isc_spb_trc_plugins 4
660661

661662
/******************************************/
662663
/* Array slice description language (SDL) */

src/include/firebird/impl/msg/fbtracemgr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ FB_IMPL_MSG(FBTRACEMGR, 37, trace_switch_user_only, -901, "00", "000", "switch \
3838
FB_IMPL_MSG(FBTRACEMGR, 38, trace_switch_param_miss, -901, "00", "000", "mandatory parameter \"@1\" for switch \"@2\" is missing")
3939
FB_IMPL_MSG(FBTRACEMGR, 39, trace_param_act_notcompat, -901, "00", "000", "parameter \"@1\" is incompatible with action \"@2\"")
4040
FB_IMPL_MSG(FBTRACEMGR, 40, trace_mandatory_switch_miss, -901, "00", "000", "mandatory switch \"@1\" is missing")
41+
FB_IMPL_MSG_NO_SYMBOL(FBTRACEMGR, 41, " -P[LUGINS] <string list> Plugins list to use for trace session")
42+
FB_IMPL_MSG_NO_SYMBOL(FBTRACEMGR, 42, " fbtracemgr -SE service_mgr -START -NAME my_trace -CONFIG my_cfg.txt -PLUGINS fbtrace,custom_plugin")

src/include/gen/Firebird.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4418,6 +4418,7 @@ IProfilerStatsImpl = class(IProfilerStats)
44184418
isc_spb_trc_id = byte(1);
44194419
isc_spb_trc_name = byte(2);
44204420
isc_spb_trc_cfg = byte(3);
4421+
isc_spb_trc_plugins = byte(4);
44214422
isc_sdl_version1 = byte(1);
44224423
isc_sdl_eoc = byte(255);
44234424
isc_sdl_relation = byte(2);

src/jrd/svc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,6 +3134,7 @@ bool Service::process_switches(ClumpletReader& spb, string& switches)
31343134
{
31353135
case isc_spb_trc_cfg:
31363136
case isc_spb_trc_name:
3137+
case isc_spb_trc_plugins:
31373138
get_action_svc_string(spb, switches);
31383139
break;
31393140
case isc_spb_trc_id:

src/jrd/trace/TraceCmdLine.cpp

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,21 @@ namespace
6363
printMsg(number, dummy, newLine);
6464
}
6565

66+
struct MessageSet
67+
{
68+
const int range[2];
69+
const std::initializer_list<int> list;
70+
71+
void print() const
72+
{
73+
for (int i = range[0]; i <= range[1]; ++i)
74+
printMsg(i);
75+
76+
for (auto id = list.begin(); id != list.end(); ++id)
77+
printMsg(*id);
78+
}
79+
};
80+
6681
[[noreturn]] void usage(UtilSvc* uSvc, const ISC_STATUS code, const char* msg1 = NULL, const char* msg2 = NULL)
6782
{
6883
if (uSvc->isService())
@@ -94,16 +109,14 @@ namespace
94109

95110
// If the items aren't contiguous, a scheme like in nbackup.cpp will have to be used.
96111
// ASF: This is message codes!
97-
constexpr int MAIN_USAGE[] = {3, 21};
98-
constexpr int EXAMPLES[] = {22, 27};
112+
const MessageSet MAIN_USAGE{{3, 21}, {41}};
113+
const MessageSet EXAMPLES{{22, 27}, {42}};
99114
constexpr int NOTES[] = {28, 29};
100115

101-
for (int i = MAIN_USAGE[0]; i <= MAIN_USAGE[1]; ++i)
102-
printMsg(i);
116+
MAIN_USAGE.print();
103117

104118
printf("\n");
105-
for (int i = EXAMPLES[0]; i <= EXAMPLES[1]; ++i)
106-
printMsg(i);
119+
EXAMPLES.print();
107120

108121
printf("\n");
109122
for (int i = NOTES[0]; i <= NOTES[1]; ++i)
@@ -253,6 +266,27 @@ void fbtrace(UtilSvc* uSvc, TraceSvcIntf* traceSvc)
253266
usage(uSvc, isc_trace_param_val_miss, sw->in_sw_name);
254267
break;
255268

269+
case IN_SW_TRACE_PLUGINS:
270+
switch (action_sw->in_sw)
271+
{
272+
case IN_SW_TRACE_STOP:
273+
case IN_SW_TRACE_SUSPEND:
274+
case IN_SW_TRACE_RESUME:
275+
case IN_SW_TRACE_LIST:
276+
usage(uSvc, isc_trace_param_act_notcompat, sw->in_sw_name, action_sw->in_sw_name);
277+
break;
278+
}
279+
280+
if (!session.ses_plugins.empty())
281+
usage(uSvc, isc_trace_switch_once, sw->in_sw_name);
282+
283+
itr++;
284+
if (itr < argc && argv[itr])
285+
session.ses_plugins = argv[itr];
286+
else
287+
usage(uSvc, isc_trace_param_val_miss, sw->in_sw_name);
288+
break;
289+
256290
default:
257291
fb_assert(false);
258292
}

src/jrd/trace/TraceConfigStorage.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,9 @@ ULONG ConfigStorage::getSessionSize(const TraceSession& session) noexcept
676676
if ((len = session.ses_logfile.length()))
677677
ret += sz + len;
678678

679+
if ((len = session.ses_plugins.length()))
680+
ret += sz + len;
681+
679682
ret += sz + sizeof(session.ses_start);
680683

681684
return ret;
@@ -717,25 +720,16 @@ void ConfigStorage::addSession(TraceSession& session)
717720
char* p = reinterpret_cast<char*> (header) + slot->offset;
718721
Writer writer(p, slot->size);
719722

720-
if (!session.ses_name.empty()) {
721-
writer.write(tagName, session.ses_name.length(), session.ses_name.c_str());
722-
}
723-
if (session.ses_auth.hasData()) {
723+
writer.writeStringIfExists(tagName, session.ses_name);
724+
if (session.ses_auth.hasData())
724725
writer.write(tagAuthBlock, session.ses_auth.getCount(), session.ses_auth.begin());
725-
}
726-
if (!session.ses_user.empty()) {
727-
writer.write(tagUserName, session.ses_user.length(), session.ses_user.c_str());
728-
}
729-
if (session.ses_role.hasData()) {
730-
writer.write(tagRole, session.ses_role.length(), session.ses_role.c_str());
731-
}
732-
if (!session.ses_config.empty()) {
733-
writer.write(tagConfig, session.ses_config.length(), session.ses_config.c_str());
734-
}
726+
writer.writeStringIfExists(tagUserName, session.ses_user);
727+
writer.writeStringIfExists(tagRole, session.ses_role);
728+
writer.writeStringIfExists(tagConfig, session.ses_config);
735729
writer.write(tagStartTS, sizeof(session.ses_start), &session.ses_start);
736-
if (!session.ses_logfile.empty()) {
737-
writer.write(tagLogFile, session.ses_logfile.length(), session.ses_logfile.c_str());
738-
}
730+
writer.writeStringIfExists(tagLogFile, session.ses_logfile);
731+
writer.writeStringIfExists(tagPlugins, session.ses_plugins);
732+
739733
writer.write(tagEnd, 0, NULL);
740734
}
741735

@@ -841,6 +835,10 @@ bool ConfigStorage::readSession(const TraceCSHeader::Slot* slot, TraceSession& s
841835
p = session.ses_role.getBuffer(len);
842836
break;
843837

838+
case tagPlugins:
839+
p = session.ses_plugins.getBuffer(len);
840+
break;
841+
844842
default:
845843
fb_assert(false);
846844
return false;

0 commit comments

Comments
 (0)