1 /*---------------------------------------------------------------------------*
2 * srec_stats.c *
3 * *
4 * Copyright 2007, 2008 Nuance Communciations, Inc. *
5 * *
6 * Licensed under the Apache License, Version 2.0 (the 'License'); *
7 * you may not use this file except in compliance with the License. *
8 * *
9 * You may obtain a copy of the License at *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
11 * *
12 * Unless required by applicable law or agreed to in writing, software *
13 * distributed under the License is distributed on an 'AS IS' BASIS, *
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15 * See the License for the specific language governing permissions and *
16 * limitations under the License. *
17 * *
18 *---------------------------------------------------------------------------*/
19
20 #include"srec_stats.h"
21 #include "passert.h"
22 #include "portable.h"
23
24
25 #ifdef SREC_STATS_ACTIVE
26
27 typedef struct
28 {
29 int num_fsmarc_tokens;
30 int num_fsmnode_tokens;
31 int num_word_tokens;
32 int num_altword_tokens, num_altword_token_batches;
33
34 int num_astar_active_parps;
35 int num_astar_complete_parps;
36 int num_astar_parps_in_use;
37
38 int num_fsmarc_token_reprunes;
39 int num_fsmnode_token_reprunes;
40 int num_word_token_reprunes;
41 int num_altword_token_reprunes;
42 int num_bad_backtraces;
43 int num_forced_updates;
44
45 }
46 srec_stats;
47
48 srec_stats my_srec_stats;
49
50 #define MAX_IN_SAMPLE(MaX,SamPle) \
51 if((MaX)<(SamPle)) MaX = (SamPle);
52
srec_stats_clear()53 void srec_stats_clear()
54 {
55 memset(&my_srec_stats, 0, sizeof(my_srec_stats));
56 }
57
srec_stats_show()58 void srec_stats_show()
59 {
60 #ifdef SREC_ENGINE_VERBOSE_LOGGING
61 PLogMessage(
62 L("SREC STATS: FWD tokens s %d f %d w %d aw %d // ASTAR parps a %d c %d t %d // REPRUNES s %d f %d w %d aw %d bbt %d fcu %d\n"),
63 my_srec_stats.num_fsmarc_tokens,
64 my_srec_stats.num_fsmnode_tokens,
65 my_srec_stats.num_word_tokens,
66 my_srec_stats.num_altword_tokens,
67 my_srec_stats.num_astar_active_parps,
68 my_srec_stats.num_astar_complete_parps,
69 my_srec_stats.num_astar_parps_in_use,
70 my_srec_stats.num_fsmarc_token_reprunes,
71 my_srec_stats.num_fsmnode_token_reprunes,
72 my_srec_stats.num_word_token_reprunes,
73 my_srec_stats.num_altword_token_reprunes,
74 my_srec_stats.num_bad_backtraces,
75 my_srec_stats.num_forced_updates
76 );
77 #endif
78 }
79
srec_stats_update(srec * rec,char * msg)80 void srec_stats_update(srec* rec, char* msg)
81 {
82 int i;
83 asr_int16_t num;
84 fsmnode_token* ftoken;
85 fsmarc_token* stoken;
86 word_token* wtoken;
87 altword_token* awtoken;
88 asr_int16_t numb;
89 stokenID st_index;
90 ftokenID ft_index;
91 wtokenID wt_index;
92
93 if (msg) PLogMessage ( msg );
94 /* state tokens */
95 st_index = rec->active_fsmarc_tokens;
96 for (num = 0; st_index != MAXstokenID; st_index = stoken->next_token_index)
97 {
98 stoken = &rec->fsmarc_token_array[st_index];
99 num++;
100 }
101 if (msg) PLogMessage ( " stokens %d", num );
102 MAX_IN_SAMPLE(my_srec_stats.num_fsmarc_tokens, num);
103
104 /* fsmnode tokens */
105 ft_index = rec->active_fsmnode_tokens;
106 for (num = 0 ; ft_index != MAXftokenID; ft_index = ftoken->next_token_index)
107 {
108 ftoken = &rec->fsmnode_token_array[ft_index];
109 num++;
110 }
111 if (msg) PLogMessage ( " ftokens %d", num );
112 MAX_IN_SAMPLE(my_srec_stats.num_fsmnode_tokens, num);
113
114 /* word tokens */
115 for (i = 0, num = 0; i < rec->current_search_frame; i++)
116 {
117 wt_index = rec->word_lattice->words_for_frame[i];
118 for (; wt_index != MAXwtokenID; wt_index = wtoken->next_token_index)
119 {
120 wtoken = &rec->word_token_array[wt_index];
121 num++;
122 }
123 }
124 if (msg) PLogMessage ( " wtokens %d", num );
125 MAX_IN_SAMPLE(my_srec_stats.num_word_tokens, num);
126
127 /* altword tokens */
128 for (num = 0, awtoken = rec->altword_token_freelist; awtoken; awtoken = awtoken->next_token)
129 num++;
130 num = rec->altword_token_array_size - num;
131 for (numb = 0, i = 0; i < rec->altword_token_array_size; i++)
132 if (rec->altword_token_array[i].next_token == AWTNULL)
133 numb++;
134 numb--; /* foreach tail, there is a head, remove the freelist head pointer */
135 if (msg) PLogMessage ( " awtokens %d/%d", num, numb );
136 MAX_IN_SAMPLE(my_srec_stats.num_altword_tokens, num);
137 MAX_IN_SAMPLE(my_srec_stats.num_altword_token_batches, numb);
138 if (msg) PLogMessage ( "\n" );
139 }
140
srec_stats_update_astar(AstarStack * stack)141 void srec_stats_update_astar(AstarStack* stack)
142 {
143 int num_parps_in_use;
144 partial_path *parp;
145 /* active parps are the leaves of the tree, still being extended */
146 MAX_IN_SAMPLE(my_srec_stats.num_astar_active_parps,
147 stack->num_active_paths);
148 /* complete parps are the leaves, for completed paths */
149 MAX_IN_SAMPLE(my_srec_stats.num_astar_complete_parps,
150 stack->num_complete_paths);
151
152 num_parps_in_use = stack->partial_path_array_size;
153 for (parp = stack->free_parp_list; parp; parp = parp->next)
154 num_parps_in_use--;
155
156 MAX_IN_SAMPLE(my_srec_stats.num_astar_parps_in_use, num_parps_in_use);
157 }
158
srec_stats_inc_stoken_reprunes(int n)159 void srec_stats_inc_stoken_reprunes(int n)
160 {
161 my_srec_stats.num_fsmarc_token_reprunes += n;
162 }
srec_stats_inc_ftoken_reprunes(int n)163 void srec_stats_inc_ftoken_reprunes(int n)
164 {
165 my_srec_stats.num_fsmnode_token_reprunes += n;
166 }
srec_stats_inc_wtoken_reprunes(int n)167 void srec_stats_inc_wtoken_reprunes(int n)
168 {
169 my_srec_stats.num_word_token_reprunes += n;
170 }
srec_stats_inc_awtoken_reprunes(int n)171 void srec_stats_inc_awtoken_reprunes(int n)
172 {
173 my_srec_stats.num_altword_token_reprunes += n;
174 }
srec_stats_inc_bad_backtraces()175 void srec_stats_inc_bad_backtraces()
176 {
177 my_srec_stats.num_bad_backtraces++;
178 }
srec_stats_inc_forced_updates()179 void srec_stats_inc_forced_updates()
180 {
181 my_srec_stats.num_forced_updates++;
182 }
183 #endif
184
185
186