7 #define DBDIR "tools/code_dbase"
9 #define COMPARE(A,B) ( ! strncmp ( A , B , strlen( B ) ) )
10 #define COMPARE2(A,B) ( ! strcmp ( A , B ) )
11 #define INLINELEN (4*8192)
13 #define MAXRECORDS 8192
16 char outbuf
[MAXRECORDS
][VARLEN
] ;
18 main( int argc
, char * argv
[] )
26 if (( dir
= opendir ( DBDIR
)) == NULL
) {
27 fprintf(stderr
, "Must be in top level WRF directory\n") ; exit(2) ;
30 fprintf(stderr
,"usage: callgraph root\n") ;
33 strcpy( root
, argv
[1] ) ;
35 cut
= atoi( argv
[2] ) ;
37 upper_case_str( root
) ;
38 lower_case_str( root
) ;
39 callgraph( root
, 0 , cut
) ;
40 sprintf(outbuf
[0],"var db = new makeArray(%d)\n",recno
-1 ) ;
41 for ( i
= 0 ; i
<= recno
; i
++ )
42 printf("%s",outbuf
[i
]) ;
45 callgraph ( char * root
, int indent
, int cut
)
49 char * p
, * q
, *q1
, prev
;
50 char inln
[INLINELEN
] ;
54 char tempbuf
[VARLEN
] ;
57 sprintf(fname
,"%s/calls", DBDIR
) ;
58 /* skip some routines */
60 COMPARE( root
, "add_msg" ) || COMPARE( root
, "reset_msgs" ) ||
61 COMPARE( t
[2] , "get_" ) || COMPARE( t
[2] , "set_" ) ||
62 COMPARE( t
[2] , "mpi_" ) || COMPARE( t
[2] , "ext_" ) ||
63 COMPARE( root
, "stencil" ) || COMPARE( root
, "wrf_debug" ) ||
64 COMPARE( root
, "wrf_message" ) || COMPARE( root
, "wrf_error" )
68 sprintf(tempbuf
,"db[%4d] = new dbRecord( %%s, \"%s\", \"../../WRFV2/tools/code_dbase/%s.html\", %d )\n",
69 thisrec
, root
, root
, indent
) ;
71 sprintf(tempbuf
,"db[%4d] = new dbRecord( %%s, \"%s\", \"%s.html\", %d )\n",
72 thisrec
, root
, root
, indent
) ;
75 if (( CALLEES
= fopen( fname
, "r" )) == NULL
) return ;
78 while ( fgets( inln
, INLINELEN
, CALLEES
) != NULL
) {
80 /* find first non space */
81 for ( p
= inln
; *p
; p
++ ) { if ( *p
!= ' ' ) break ; }
82 /* change multiple spaces to single space */
83 for ( q
= p
, q1
= q
, prev
= *p
; *q
; q
++ )
84 { if ( prev
== ' ' && *q
== ' ' ) { continue ; } else { prev
= *q
; *q1
++ = *q
; } }
86 for ( i
= 0 ; i
< 11 ; i
++ ) {
88 get_token_n( inln
, " ", i
, t
[i
] ) ; remove_nl(t
[i
]) ; lower_case_str( t
[i
] ) ;
90 if ( COMPARE2( t
[0] , root
) && COMPARE2( t
[1] , "calls" ) && ! COMPARE2( t
[0] , t
[2] ) &&
92 COMPARE( root
, "add_msg" ) || COMPARE( root
, "reset_msgs" ) ||
93 COMPARE( t
[2] , "get_" ) || COMPARE( t
[2] , "set_" ) ||
94 COMPARE( t
[2] , "mpi_" ) || COMPARE( t
[2] , "ext_" ) ||
95 COMPARE( root
, "stencil" ) || COMPARE( root
, "wrf_debug" ) ||
96 COMPARE( root
, "wrf_message" ) || COMPARE( root
, "wrf_error" )
98 if ( indent
<= cut
&& ( ! sym_get ( t
[2] ) ) ) {
101 callgraph ( t
[2] , indent
+ 1, cut
) ;
105 sprintf(outbuf
[thisrec
],tempbuf
,doescall
) ;
110 /*******************************************************************/
112 /* open the file of calls and count them */
113 count_entries ( char * root
, int * nentries
)
117 char inln
[INLINELEN
] ;
118 char * p
, *q
, *q1
, prev
;
122 sprintf(fname
,"%s/calls", DBDIR
) ;
123 if (( CALLEES
= fopen( fname
, "r" )) == NULL
) return ;
125 while ( fgets( inln
, INLINELEN
, CALLEES
) != NULL
) {
127 /* find first non space */
128 for ( p
= inln
; *p
; p
++ ) { if ( *p
!= ' ' ) break ; }
129 /* change multiple spaces to single space */
130 for ( q
= p
, q1
= q
, prev
= *p
; *q
; q
++ )
131 { if ( prev
== ' ' && *q
== ' ' ) { continue ; } else { prev
= *q
; *q1
++ = *q
; } }
133 for ( i
= 0 ; i
< 11 ; i
++ ) {
134 strcpy( t
[i
] , "" ) ;
135 get_token_n( inln
, " ", i
, t
[i
] ) ; remove_nl(t
[i
]) ; lower_case_str( t
[i
] ) ;
137 if ( COMPARE2( t
[0] , root
) && COMPARE2( t
[1] , "calls" ) && ! COMPARE2( t
[0] , t
[2] ) &&
139 COMPARE( root
, "add_msg" ) || COMPARE( root
, "reset_msgs" ) ||
140 COMPARE( t
[2] , "get_" ) || COMPARE( t
[2] , "set_" ) ||
141 COMPARE( t
[2] , "mpi_" ) || COMPARE( t
[2] , "ext_" ) ||
142 COMPARE( root
, "stencil" ) || COMPARE( root
, "wrf_debug" ) ||
143 COMPARE( root
, "wrf_message" ) || COMPARE( root
, "wrf_error" )
154 /* old version before adding javascript calltree */
155 main( int argc
, char * argv
[] )
161 if (( dir
= opendir ( DBDIR
)) == NULL
) {
162 fprintf(stderr
, "Must be in top level WRF directory\n") ; exit(2) ;
165 fprintf(stderr
,"usage: callgraph root\n") ;
168 strcpy( root
, argv
[1] ) ;
170 cut
= atoi( argv
[2] ) ;
172 upper_case_str( root
) ;
173 printf("<html>\n" ) ;
174 printf("<title> %s Call Tree </title>\n", root
) ;
175 printf("<body>\n" ) ;
176 printf("<h1> %s Call Tree </h1>\n", root
) ;
177 printf("<p><a href=index.html>[1] </a> " ) ;
178 printf("<a href=ct2.html>[2] </a> " ) ;
179 printf("<a href=ct3.html>[3] </a> " ) ;
180 printf("<a href=ct4.html>[4] </a> " ) ;
181 printf("<a href=ct5.html>[5] </a> " ) ;
182 printf("<a href=ctall.html>[all] </a><p>\n" ) ;
183 lower_case_str( root
) ;
184 callgraph( root
, 0 , cut
) ;
185 printf("</body>\n" ) ;
186 printf("</html>\n" ) ;
189 callgraph ( char * root
, int indent
, int cut
)
193 char * p
, * q
, *q1
, prev
;
194 char inln
[INLINELEN
] ;
199 sprintf(fname
,"%s/calls", DBDIR
) ;
200 if (( CALLEES
= fopen( fname
, "r" )) == NULL
) return ;
202 COMPARE( root
, "add_msg" ) || COMPARE( root
, "reset_msgs" ) ||
203 COMPARE( t
[2] , "get_" ) || COMPARE( t
[2] , "set_" ) ||
204 COMPARE( t
[2] , "mpi_" ) || COMPARE( t
[2] , "ext_" ) ||
205 COMPARE( root
, "stencil" ) || COMPARE( root
, "wrf_debug" ) ||
206 COMPARE( root
, "wrf_message" ) || COMPARE( root
, "wrf_error" )
208 for ( i
= 0 ; i
< indent
; i
++ ) printf(" !       ") ;
209 printf(" <a href=\"%s.html\"> %s </a><br>\n", root
, root
) ;
211 while ( fgets( inln
, INLINELEN
, CALLEES
) != NULL
) {
213 /* find first non space */
214 for ( p
= inln
; *p
; p
++ ) { if ( *p
!= ' ' ) break ; }
215 /* change multiple spaces to single space */
216 for ( q
= p
, q1
= q
, prev
= *p
; *q
; q
++ )
217 { if ( prev
== ' ' && *q
== ' ' ) { continue ; } else { prev
= *q
; *q1
++ = *q
; } }
219 for ( i
= 0 ; i
< 11 ; i
++ ) {
220 strcpy( t
[i
] , "" ) ;
221 get_token_n( inln
, " ", i
, t
[i
] ) ; remove_nl(t
[i
]) ; lower_case_str( t
[i
] ) ;
223 if ( COMPARE2( t
[0] , root
) && COMPARE2( t
[1] , "calls" ) && ! COMPARE2( t
[0] , t
[2] ) &&
225 COMPARE( root
, "add_msg" ) || COMPARE( root
, "reset_msgs" ) ||
226 COMPARE( t
[2] , "get_" ) || COMPARE( t
[2] , "set_" ) ||
227 COMPARE( t
[2] , "mpi_" ) || COMPARE( t
[2] , "ext_" ) ||
228 COMPARE( root
, "stencil" ) || COMPARE( root
, "wrf_debug" ) ||
229 COMPARE( root
, "wrf_message" ) || COMPARE( root
, "wrf_error" )
231 if ( indent
<= cut
&& ( ! sym_get ( t
[2] ) ) ) {
233 callgraph ( t
[2] , indent
+ 1, cut
) ;
240 #####################
241 # original old PERL code kept just for reference
243 $dbdir
= "tools/code_dbase" ;
245 if ( ! opendir( TOOLDIR
, "tools") ) {
246 print
"\nMust be in top level WRF directory\n" ;
251 if ( ( scalar @ARGV
< 1 ) ) {
252 print
"usage: callgraph root\n" ;
256 $rout1
= lc $ARGV
[0] ;
259 $routfile
= $dbdir
."/".$rout
;
261 if ( $indent
== 0 ) {
263 print
"<title> ",uc $rout
," Call Tree </title>\n" ;
265 print
"<h1> ",uc $rout
," Call Tree </h1>\n" ;
272 open CALLEES
, "< $dbdir/calls" or die
" cannot open $dbdir/calls " ;
273 while ( <CALLEES
> ) {
275 if ( $t
[0] eq lc $rout
&& $t
[1] eq
"calls" && ! ( $t
[2] eq $t
[0] ) && ! ($t
[2] =~ add_msg
) && !($t
[2] =~ reset_msgs
) && ! ($t
[2] =~ stencil
) && !($t
[2] =~ wrf_debug
) ) {
277 for ( $i
= 0 ; $i
< $indent
; $i
++ ) { print
"|   " ; }
278 print
"<a href=\"$rout\.html\"> $rout </a><br>\n" ;
282 if ( $i2
< 7 && (! $prune
{$t
[2]} ) ) {
283 $prune
{$t
[2]} = "y" ;
284 $opstr
= "tools/callgraph $t[2] $i2 |" ;
285 ####### RECURSE ##########
287 while ( <D
> ) { print
; }
292 if ( $indent
== 0 ) {