I''d like to be able to dynamically read external configuration files within a dtrace script. I know dtrace allows inclusion of C header files but only at the preprocessing stage. What we need to do is dynamically enable/disable probes based on current application settings. I''d rather not have a bunch of independant scripts running and being started and killed whenever the settings change. I believe that if we can read a configuration file, we can use those settings within a predicate to enable/disable specific probes. Problem is, I don''t know how to directly read a file or otherwise affect a running dtrace script on the fly. Any help, insight or tricks would be greatly appreciated. Thanks, Stacy Maydew This message posted from opensolaris.org
Sean McGrath - Sun Microsystems Ireland
2006-May-24 15:34 UTC
[dtrace-discuss] Reading external files with dtrace
You could have something like:
BEGIN
{
int a_variable_this_is = 0;
}
/* turn on change watch */
syscall::open*:entry
/stringof(copyinstr(arg0)) == "/tmp/settings_have_changed_on"/
{
a_variable_this_is = 1;
}
/* turn off change watch */
syscall::open*:entry
/stringof(copyinstr(arg0)) == "/tmp/settings_have_changed_off"/
{
a_variable_this_is = 0;
}
<some provider>::<some probefunc>:<some point>
/a_variable_this_is == 1/
{
/* do this action if a_variable_this_is == 1 */
}
So by touching /tmp/settings_have_changed_on you''d turn on watching
extra probes and turn them off by touching /tmp/settings_have_changed_off
Mind you the
''<provider>::<probefunc>:<point>'' would
always be enabled but the
action wouldn''t be taken.
Usual disclaimer applies, I haven''t tried this out..
Sean.
.
Stacy Maydew stated:
< I''d like to be able to dynamically read external configuration
files within a dtrace script. I know dtrace allows inclusion of C header files
but only at the preprocessing stage.
<
< What we need to do is dynamically enable/disable probes based on current
application settings. I''d rather not have a bunch of independant
scripts running and being started and killed whenever the settings change. I
believe that if we can read a configuration file, we can use those settings
within a predicate to enable/disable specific probes. Problem is, I
don''t know how to directly read a file or otherwise affect a running
dtrace script on the fly.
<
< Any help, insight or tricks would be greatly appreciated.
<
< Thanks,
<
< Stacy Maydew
<
<
< This message posted from opensolaris.org
< _______________________________________________
< dtrace-discuss mailing list
< dtrace-discuss at opensolaris.org
--
Sean.
.
Sean McGrath - Sun Microsystems Ireland
2006-May-24 15:42 UTC
[dtrace-discuss] Reading external files with dtrace
Oops. slight change, take the declaration of int a_variable_this_is outside
the BEGIN clause.
Works if I ''echo >
/tmp/settings_have_changed_on|settings_have_changed_off''
Regards,
Sean.
.
Sean McGrath - Sun Microsystems Ireland stated:
<
< You could have something like:
<
< BEGIN
< {
< int a_variable_this_is = 0;
< }
<
< /* turn on change watch */
< syscall::open*:entry
< /stringof(copyinstr(arg0)) == "/tmp/settings_have_changed_on"/
< {
< a_variable_this_is = 1;
< }
<
< /* turn off change watch */
< syscall::open*:entry
< /stringof(copyinstr(arg0)) == "/tmp/settings_have_changed_off"/
< {
< a_variable_this_is = 0;
< }
<
< <some provider>::<some probefunc>:<some point>
< /a_variable_this_is == 1/
< {
< /* do this action if a_variable_this_is == 1 */
< }
<
< So by touching /tmp/settings_have_changed_on you''d turn on
watching
< extra probes and turn them off by touching /tmp/settings_have_changed_off
<
< Mind you the
''<provider>::<probefunc>:<point>'' would
always be enabled but the
< action wouldn''t be taken.
<
< Usual disclaimer applies, I haven''t tried this out..
<
< Sean.
< .
< Stacy Maydew stated:
< < I''d like to be able to dynamically read external
configuration files within a dtrace script. I know dtrace allows inclusion of C
header files but only at the preprocessing stage.
< <
< < What we need to do is dynamically enable/disable probes based on
current application settings. I''d rather not have a bunch of
independant scripts running and being started and killed whenever the settings
change. I believe that if we can read a configuration file, we can use those
settings within a predicate to enable/disable specific probes. Problem is, I
don''t know how to directly read a file or otherwise affect a running
dtrace script on the fly.
< <
< < Any help, insight or tricks would be greatly appreciated.
< <
< < Thanks,
< <
< < Stacy Maydew
< <
< <
< < This message posted from opensolaris.org
< < _______________________________________________
< < dtrace-discuss mailing list
< < dtrace-discuss at opensolaris.org
<
< --
< Sean.
< .
< _______________________________________________
< dtrace-discuss mailing list
< dtrace-discuss at opensolaris.org
--
Sean.
.
-------------- next part --------------
int a_variable_this_is;
BEGIN
{
a_variable_this_is = 0;
}
/* turn on change watch */
syscall::open*:entry
/stringof(copyinstr(arg0)) == "/tmp/settings_have_changed_on"/
{
a_variable_this_is = 1;
printf("Turning on change watch\n");
}
/* turn off change watch */
syscall::open*:entry
/stringof(copyinstr(arg0)) == "/tmp/settings_have_changed_off"/
{
a_variable_this_is = 0;
printf("Turning off change watch\n");
}
syscall::read*:entry
/a_variable_this_is == 1 && execname == "firefox-bin"/
{
printf(" got ya !\n");
}