jorge gmail
2007-Nov-14 21:10 UTC
[dtrace-discuss] automate DtraceToolkit scripts with ktime
Hi all, i write a little program that could be useful if you have DtraceToolkit. Almost all scripts wait until you press ctrl+c key, but If want to automate this task this is not possible because you need to stay in front of your terminal. Ktime launch the program passed as parameter and wait <time> ( in seconds) until send a ctr+c signal ( SIGINT) to the child process. http://kbradero.neuroaio.biz/gnu/ktime/ktime.c ( source code online ) http://kbradero.neuroaio.biz/gnu/ktime/solaris/ binary Examples : ./ktime shortlived.d 20 Syntaxis: ./ktime <program> <time> #crontab -l * * * * * /tmp/test/DTraceToolkit-0.99/Bin/mon.sh You could integrate in other scripts: /tmp/test/DTraceToolkit-0.99/Bin/>#cat mon.sh #!/bin/bash cd /tmp/test/DTraceToolkit-0.99/Bin/ /tmp/test/DTraceToolkit-0.99/Bin/ktime errinfo 20 > state.txt echo `date` >> state.txt The code: cat ktime.c #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <signal.h> /* Author: Jorge Alberto Garcia Gonzalez email: jorge.garcia.gonzalez(en)gmail.com Usage: ./ktime shortlived.d 10 ktime <program > <program parameters> <seconds until send ctrl+c > way to compile: gcc ktime.c -o ktime */ int main( int argc, char *argv[]){ pid_t child_pid=0; char *arguments=NULL; int narguments= argc-2; /* chid arguments*/ int i=argc-1 ; int element=1; int lenarg=0; for( element=1; element <=argc-2 ;element++){ lenarg+= strlen(argv[ element ]) +1 ; printf("%d \n",lenarg); } lenarg+=1; element=1; arguments=(char *) malloc( lenarg * sizeof(char) ); for( element=1; element <=argc-2 ; element++ ){ strcat( arguments, argv[ element ] ); strcat( arguments, " "); /* printf("argumento: %s \n", argv[ element ] ); */ } /* printf("child arguments: %s \n", arguments ); */ if( ( child_pid=fork() )==0 ){ //execl("/tmp/test/DTraceToolkit-0.99/Bin/errinfo","errinfo",(char *)0); execv(argv[1],&arguments ); }else { sleep( atoi(argv[argc-1]) ) ; kill(child_pid,SIGINT) ; //printf("child: %d is dead, leaving...\n",(int)child_pid); } return 0; } -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.opensolaris.org/pipermail/dtrace-discuss/attachments/20071114/a27e5eda/attachment.html>
Adam Leventhal
2007-Nov-14 21:37 UTC
[dtrace-discuss] automate DtraceToolkit scripts with ktime
Alternatively, you could modify the scripts so they exit after a specified interval: tick-1s /i++ >= $1/ { exit(0); } Adam On Wed, Nov 14, 2007 at 03:10:05PM -0600, jorge gmail wrote:> > > Hi all, i write a little program that could be useful if you have > DtraceToolkit. Almost all scripts wait until you press ctrl+c key, but > > If want to automate this task this is not possible because you need to stay > in front of your terminal. > > > > Ktime launch the program passed as parameter and wait <time> ( in seconds) > until send a ctr+c signal ( SIGINT) to the child process. > > > > > > http://kbradero.neuroaio.biz/gnu/ktime/ktime.c ( source code online ) > > http://kbradero.neuroaio.biz/gnu/ktime/solaris/ binary > > Examples : > > ./ktime shortlived.d 20 > > > > Syntaxis: > > ./ktime <program> <time> > > > > #crontab -l > > * * * * * /tmp/test/DTraceToolkit-0.99/Bin/mon.sh > > > > You could integrate in other scripts: > > > > /tmp/test/DTraceToolkit-0.99/Bin/>#cat mon.sh > > #!/bin/bash > > cd /tmp/test/DTraceToolkit-0.99/Bin/ > > /tmp/test/DTraceToolkit-0.99/Bin/ktime errinfo 20 > state.txt > > echo `date` >> state.txt > > > > > > > > > > The code: > > > > cat ktime.c > > #include <stdio.h> > > #include <string.h> > > #include <stdlib.h> > > #include <unistd.h> > > #include <signal.h> > > > > > > /* > > Author: Jorge Alberto Garcia Gonzalez > > email: jorge.garcia.gonzalez(en)gmail.com > > Usage: ./ktime shortlived.d 10 > > ktime <program > <program parameters> <seconds until send ctrl+c > > > > way to compile: gcc ktime.c -o ktime > > */ > > int main( int argc, char *argv[]){ > > pid_t child_pid=0; > > char *arguments=NULL; > > int narguments= argc-2; /* chid arguments*/ > > int i=argc-1 ; > > int element=1; > > int lenarg=0; > > > > > > for( element=1; element <=argc-2 ;element++){ > > lenarg+= strlen(argv[ element ]) +1 ; > > printf("%d \n",lenarg); > > } > > lenarg+=1; > > element=1; > > > > arguments=(char *) malloc( lenarg * sizeof(char) ); > > > > for( element=1; element <=argc-2 ; element++ ){ > > strcat( arguments, argv[ element ] ); > > strcat( arguments, " "); > > /* > > printf("argumento: %s \n", argv[ element ] ); > > */ > > } > > > > /* > > printf("child arguments: %s \n", arguments ); > > */ > > > > if( ( child_pid=fork() )==0 ){ > > > //execl("/tmp/test/DTraceToolkit-0.99/Bin/errinfo","errinfo",(char *)0); > > execv(argv[1],&arguments ); > > > > }else > > { > > sleep( atoi(argv[argc-1]) ) ; > > kill(child_pid,SIGINT) ; > > //printf("child: %d is dead, leaving...\n",(int)child_pid); > > } > > return 0; > > } > > > > >> _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org-- Adam Leventhal, FishWorks http://blogs.sun.com/ahl
Brendan Gregg - Sun Microsystems
2007-Nov-14 21:47 UTC
[dtrace-discuss] automate DtraceToolkit scripts with ktime
G''Fay Folks, On Wed, Nov 14, 2007 at 03:10:05PM -0600, jorge gmail wrote:> > > Hi all, i write a little program that could be useful if you have > DtraceToolkit. Almost all scripts wait until you press ctrl+c key, but > > If want to automate this task this is not possible because you need to stay > in front of your terminal.Sorry, I haven''t documented this in the DTraceToolkit yet (it should be under Notes/ALLautomation.txt), and I apologize, but there is an easy way to automate most of them. For example: # ./mmapfiles.d Tracing... Hit Ctrl-C to end. ^C Lets say I wanted that to run for 10 seconds only; since it is a .d script, expressions can be added to the command line: # ./mmapfiles.d -n ''tick-10sec { exit(0); }'' Tracing... Hit Ctrl-C to end. MMAPS CMD PATHNAME 1 date /var/ld/ld.config 1 ls /var/ld/ld.config 3 date /lib/libc.so.1 3 ls /lib/libavl.so.1 3 ls /lib/libc.so.1 3 ls /lib/libsec.so.1 Now it runs for 10 seconds. Usually. The profile:::tick-10sec probe can hook onto a pre-existing enabling of profile:::tick-10sec, if someone else was running it on the same system, meaning that it could exit much sooner than 10 seconds. This could be improved using: # ./mmapfiles.d -n ''tick-1sec /++i == 10/ { exit(0); }'' Tracing... Hit Ctrl-C to end. MMAPS CMD PATHNAME 1 date /var/ld/ld.config 3 date /lib/libc.so.1 Now it will be much closer to 10 seconds (between 9 and 10). It could user tick-10hz to get within 9.9 and 10.0, if needed. Some scripts in the DTraceToolkit are wrapped in Perl or shell, and don''t have the .d extension, and can''t use this trick. Some of those have an interval and count as options, which can be used instead. That leaves several scripts with no way of automating the time; which shouldn''t take me too long to fix for the next version of the toolkit (it''s already on my todo list). In the meantime, if you have a script that isn''t *.d, that doesn''t provide interval and count, then you can either edit the script to add that functionality, or use Ktime.> Ktime launch the program passed as parameter and wait <time> ( in seconds) > until send a ctr+c signal ( SIGINT) to the child process. > > http://kbradero.neuroaio.biz/gnu/ktime/ktime.c ( source code online ) > > http://kbradero.neuroaio.biz/gnu/ktime/solaris/ binary > > Examples : > > ./ktime shortlived.d 20 > > > Syntaxis: > > ./ktime <program> <time> >[...] Cool; there have certainly been times in the past where Ktime would have been handy, and it can still serve a purpose for some of the toolkit scripts. thanks, Brendan -- Brendan [CA, USA]
jorge gmail
2007-Nov-14 21:59 UTC
[dtrace-discuss] automate DtraceToolkit scripts with ktime
To me, it seems that probably this doesn''t work with DtraceToolkit scripts, because some scripts takes actions before it receives the SIGINT signals. However this could work with scripts that only need a delay. Thanks Adam. I write ktime because is not very easy to change scripts from dtrace. Here is my little history" At work we need to put monitoring scripts with errinfo, but it don?t have a -t flag ( time )so I made a change in order that you could call it Like this: ./errinfo http://kbradero.neuroaio.biz/gnu/errinfo-scripteable #cat > errinfo <paste the file> ^d #chmod +x errinfo ./errinfo -t "time in seconds" -c -u $user > output If you made a diff between this version and the original from DtraceToolkit-0.99 you could seed that the change are not so simple that You could do It (fast) with all. Saludos! -----Original Message----- From: Adam Leventhal [mailto:ahl at eng.sun.com] Sent: Mi?rcoles, 14 de Noviembre de 2007 03:38 p.m. To: jorge gmail Cc: dtrace-discuss at opensolaris.org Subject: Re: [dtrace-discuss] automate DtraceToolkit scripts with ktime Alternatively, you could modify the scripts so they exit after a specified interval: tick-1s /i++ >= $1/ { exit(0); } Adam On Wed, Nov 14, 2007 at 03:10:05PM -0600, jorge gmail wrote:> > > Hi all, i write a little program that could be useful if you have > DtraceToolkit. Almost all scripts wait until you press ctrl+c key, but > > If want to automate this task this is not possible because you need tostay> in front of your terminal. > > > > Ktime launch the program passed as parameter and wait <time> ( inseconds)> until send a ctr+c signal ( SIGINT) to the child process. > > > > > > http://kbradero.neuroaio.biz/gnu/ktime/ktime.c ( source code online ) > > http://kbradero.neuroaio.biz/gnu/ktime/solaris/ binary > > Examples : > > ./ktime shortlived.d 20 > > > > Syntaxis: > > ./ktime <program> <time> > > > > #crontab -l > > * * * * * /tmp/test/DTraceToolkit-0.99/Bin/mon.sh > > > > You could integrate in other scripts: > > > > /tmp/test/DTraceToolkit-0.99/Bin/>#cat mon.sh > > #!/bin/bash > > cd /tmp/test/DTraceToolkit-0.99/Bin/ > > /tmp/test/DTraceToolkit-0.99/Bin/ktime errinfo 20 > state.txt > > echo `date` >> state.txt > > > > > > > > > > The code: > > > > cat ktime.c > > #include <stdio.h> > > #include <string.h> > > #include <stdlib.h> > > #include <unistd.h> > > #include <signal.h> > > > > > > /* > > Author: Jorge Alberto Garcia Gonzalez > > email: jorge.garcia.gonzalez(en)gmail.com > > Usage: ./ktime shortlived.d 10 > > ktime <program > <program parameters> <seconds until send ctrl+c > > > > way to compile: gcc ktime.c -o ktime > > */ > > int main( int argc, char *argv[]){ > > pid_t child_pid=0; > > char *arguments=NULL; > > int narguments= argc-2; /* chid arguments*/ > > int i=argc-1 ; > > int element=1; > > int lenarg=0; > > > > > > for( element=1; element <=argc-2 ;element++){ > > lenarg+= strlen(argv[ element ]) +1 ; > > printf("%d \n",lenarg); > > } > > lenarg+=1; > > element=1; > > > > arguments=(char *) malloc( lenarg * sizeof(char) ); > > > > for( element=1; element <=argc-2 ; element++ ){ > > strcat( arguments, argv[ element ] ); > > strcat( arguments, " "); > > /* > > printf("argumento: %s \n", argv[ element ] ); > > */ > > } > > > > /* > > printf("child arguments: %s \n", arguments ); > > */ > > > > if( ( child_pid=fork() )==0 ){ > > > //execl("/tmp/test/DTraceToolkit-0.99/Bin/errinfo","errinfo",(char *)0); > > execv(argv[1],&arguments ); > > > > }else > > { > > sleep( atoi(argv[argc-1]) ) ; > > kill(child_pid,SIGINT) ; > > //printf("child: %d is dead,leaving...\n",(int)child_pid);> > } > > return 0; > > } > > > > >> _______________________________________________ > dtrace-discuss mailing list > dtrace-discuss at opensolaris.org-- Adam Leventhal, FishWorks http://blogs.sun.com/ahl
jorge gmail
2007-Nov-14 23:06 UTC
[dtrace-discuss] automate DtraceToolkit scripts with ktime
Thanks Brendan! -----Original Message----- From: Brendan Gregg - Sun Microsystems [mailto:brendan at sun.com] Sent: Mi?rcoles, 14 de Noviembre de 2007 03:48 p.m. To: jorge gmail Cc: dtrace-discuss at opensolaris.org Subject: Re: [dtrace-discuss] automate DtraceToolkit scripts with ktime G''Fay Folks, On Wed, Nov 14, 2007 at 03:10:05PM -0600, jorge gmail wrote:> > > Hi all, i write a little program that could be useful if you have > DtraceToolkit. Almost all scripts wait until you press ctrl+c key, but > > If want to automate this task this is not possible because you need tostay> in front of your terminal.Sorry, I haven''t documented this in the DTraceToolkit yet (it should be under Notes/ALLautomation.txt), and I apologize, but there is an easy way to automate most of them. For example: # ./mmapfiles.d Tracing... Hit Ctrl-C to end. ^C Lets say I wanted that to run for 10 seconds only; since it is a .d script, expressions can be added to the command line: # ./mmapfiles.d -n ''tick-10sec { exit(0); }'' Tracing... Hit Ctrl-C to end. MMAPS CMD PATHNAME 1 date /var/ld/ld.config 1 ls /var/ld/ld.config 3 date /lib/libc.so.1 3 ls /lib/libavl.so.1 3 ls /lib/libc.so.1 3 ls /lib/libsec.so.1 Now it runs for 10 seconds. Usually. The profile:::tick-10sec probe can hook onto a pre-existing enabling of profile:::tick-10sec, if someone else was running it on the same system, meaning that it could exit much sooner than 10 seconds. This could be improved using: # ./mmapfiles.d -n ''tick-1sec /++i == 10/ { exit(0); }'' Tracing... Hit Ctrl-C to end. MMAPS CMD PATHNAME 1 date /var/ld/ld.config 3 date /lib/libc.so.1 Now it will be much closer to 10 seconds (between 9 and 10). It could user tick-10hz to get within 9.9 and 10.0, if needed. Some scripts in the DTraceToolkit are wrapped in Perl or shell, and don''t have the .d extension, and can''t use this trick. Some of those have an interval and count as options, which can be used instead. That leaves several scripts with no way of automating the time; which shouldn''t take me too long to fix for the next version of the toolkit (it''s already on my todo list). In the meantime, if you have a script that isn''t *.d, that doesn''t provide interval and count, then you can either edit the script to add that functionality, or use Ktime.> Ktime launch the program passed as parameter and wait <time> ( inseconds)> until send a ctr+c signal ( SIGINT) to the child process. > > http://kbradero.neuroaio.biz/gnu/ktime/ktime.c ( source code online ) > > http://kbradero.neuroaio.biz/gnu/ktime/solaris/ binary > > Examples : > > ./ktime shortlived.d 20 > > > Syntaxis: > > ./ktime <program> <time> >[...] Cool; there have certainly been times in the past where Ktime would have been handy, and it can still serve a purpose for some of the toolkit scripts. thanks, Brendan -- Brendan [CA, USA]
Hi, yestarday a send a little program that launch ( fork) a process anf before send a SINGINT signal( ctrl+c). I found that if the child has other child, it doesn''t die, because only the first child process receives the signal. I don?t know if there is a fast way to kill a process with all his Childs, or if i need to check the process tree first and then send the signal to the list. I know there is a signal that kill all the group, but if you have this program running within a crontab may be all the cron task would die and not only the process that ktime start. I update the files in my website if someone wants to check it: http://kbradero.neuroaio.biz/gnu/ktime/ktime.c (source code online) http://kbradero.neuroaio.biz/gnu/ktime/solaris/ binary (Sorry for my English I know is poor) -----Original Message----- From: Brendan Gregg - Sun Microsystems [mailto:brendan at sun.com] Sent: Mi?rcoles, 14 de Noviembre de 2007 03:48 p.m. To: jorge gmail Cc: dtrace-discuss at opensolaris.org Subject: Re: [dtrace-discuss] automate DtraceToolkit scripts with ktime G''Fay Folks, On Wed, Nov 14, 2007 at 03:10:05PM -0600, jorge gmail wrote:> > > Hi all, i write a little program that could be useful if you have > DtraceToolkit. Almost all scripts wait until you press ctrl+c key, but > > If want to automate this task this is not possible because you need tostay> in front of your terminal.Sorry, I haven''t documented this in the DTraceToolkit yet (it should be under Notes/ALLautomation.txt), and I apologize, but there is an easy way to automate most of them. For example: # ./mmapfiles.d Tracing... Hit Ctrl-C to end. ^C Lets say I wanted that to run for 10 seconds only; since it is a .d script, expressions can be added to the command line: # ./mmapfiles.d -n ''tick-10sec { exit(0); }'' Tracing... Hit Ctrl-C to end. MMAPS CMD PATHNAME 1 date /var/ld/ld.config 1 ls /var/ld/ld.config 3 date /lib/libc.so.1 3 ls /lib/libavl.so.1 3 ls /lib/libc.so.1 3 ls /lib/libsec.so.1 Now it runs for 10 seconds. Usually. The profile:::tick-10sec probe can hook onto a pre-existing enabling of profile:::tick-10sec, if someone else was running it on the same system, meaning that it could exit much sooner than 10 seconds. This could be improved using: # ./mmapfiles.d -n ''tick-1sec /++i == 10/ { exit(0); }'' Tracing... Hit Ctrl-C to end. MMAPS CMD PATHNAME 1 date /var/ld/ld.config 3 date /lib/libc.so.1 Now it will be much closer to 10 seconds (between 9 and 10). It could user tick-10hz to get within 9.9 and 10.0, if needed. Some scripts in the DTraceToolkit are wrapped in Perl or shell, and don''t have the .d extension, and can''t use this trick. Some of those have an interval and count as options, which can be used instead. That leaves several scripts with no way of automating the time; which shouldn''t take me too long to fix for the next version of the toolkit (it''s already on my todo list). In the meantime, if you have a script that isn''t *.d, that doesn''t provide interval and count, then you can either edit the script to add that functionality, or use Ktime.> Ktime launch the program passed as parameter and wait <time> ( inseconds)> until send a ctr+c signal ( SIGINT) to the child process. > > http://kbradero.neuroaio.biz/gnu/ktime/ktime.c ( source code online ) > > http://kbradero.neuroaio.biz/gnu/ktime/solaris/ binary > > Examples : > > ./ktime shortlived.d 20 > > > Syntaxis: > > ./ktime <program> <time> >[...] Cool; there have certainly been times in the past where Ktime would have been handy, and it can still serve a purpose for some of the toolkit scripts. thanks, Brendan -- Brendan [CA, USA]