perf hist: Introduce hists class and move lots of methods to it
[linux-flexiantxendom0.git] / tools / perf / util / hist.c
1 #include "hist.h"
2 #include "session.h"
3 #include "sort.h"
4 #include <math.h>
5
6 struct callchain_param  callchain_param = {
7         .mode   = CHAIN_GRAPH_REL,
8         .min_percent = 0.5
9 };
10
11 static void hist_entry__add_cpumode_count(struct hist_entry *self,
12                                           unsigned int cpumode, u64 count)
13 {
14         switch (cpumode) {
15         case PERF_RECORD_MISC_KERNEL:
16                 self->count_sys += count;
17                 break;
18         case PERF_RECORD_MISC_USER:
19                 self->count_us += count;
20                 break;
21         case PERF_RECORD_MISC_GUEST_KERNEL:
22                 self->count_guest_sys += count;
23                 break;
24         case PERF_RECORD_MISC_GUEST_USER:
25                 self->count_guest_us += count;
26                 break;
27         default:
28                 break;
29         }
30 }
31
32 /*
33  * histogram, sorted on item, collects counts
34  */
35
36 static struct hist_entry *hist_entry__new(struct hist_entry *template)
37 {
38         size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_node) : 0;
39         struct hist_entry *self = malloc(sizeof(*self) + callchain_size);
40
41         if (self != NULL) {
42                 *self = *template;
43                 if (symbol_conf.use_callchain)
44                         callchain_init(self->callchain);
45         }
46
47         return self;
48 }
49
50 struct hist_entry *__hists__add_entry(struct hists *self,
51                                       struct addr_location *al,
52                                       struct symbol *sym_parent, u64 count)
53 {
54         struct rb_node **p = &self->entries.rb_node;
55         struct rb_node *parent = NULL;
56         struct hist_entry *he;
57         struct hist_entry entry = {
58                 .thread = al->thread,
59                 .ms = {
60                         .map    = al->map,
61                         .sym    = al->sym,
62                 },
63                 .ip     = al->addr,
64                 .level  = al->level,
65                 .count  = count,
66                 .parent = sym_parent,
67         };
68         int cmp;
69
70         while (*p != NULL) {
71                 parent = *p;
72                 he = rb_entry(parent, struct hist_entry, rb_node);
73
74                 cmp = hist_entry__cmp(&entry, he);
75
76                 if (!cmp) {
77                         he->count += count;
78                         goto out;
79                 }
80
81                 if (cmp < 0)
82                         p = &(*p)->rb_left;
83                 else
84                         p = &(*p)->rb_right;
85         }
86
87         he = hist_entry__new(&entry);
88         if (!he)
89                 return NULL;
90         rb_link_node(&he->rb_node, parent, p);
91         rb_insert_color(&he->rb_node, &self->entries);
92 out:
93         hist_entry__add_cpumode_count(he, al->cpumode, count);
94         return he;
95 }
96
97 int64_t
98 hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
99 {
100         struct sort_entry *se;
101         int64_t cmp = 0;
102
103         list_for_each_entry(se, &hist_entry__sort_list, list) {
104                 cmp = se->se_cmp(left, right);
105                 if (cmp)
106                         break;
107         }
108
109         return cmp;
110 }
111
112 int64_t
113 hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
114 {
115         struct sort_entry *se;
116         int64_t cmp = 0;
117
118         list_for_each_entry(se, &hist_entry__sort_list, list) {
119                 int64_t (*f)(struct hist_entry *, struct hist_entry *);
120
121                 f = se->se_collapse ?: se->se_cmp;
122
123                 cmp = f(left, right);
124                 if (cmp)
125                         break;
126         }
127
128         return cmp;
129 }
130
131 void hist_entry__free(struct hist_entry *he)
132 {
133         free(he);
134 }
135
136 /*
137  * collapse the histogram
138  */
139
140 static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he)
141 {
142         struct rb_node **p = &root->rb_node;
143         struct rb_node *parent = NULL;
144         struct hist_entry *iter;
145         int64_t cmp;
146
147         while (*p != NULL) {
148                 parent = *p;
149                 iter = rb_entry(parent, struct hist_entry, rb_node);
150
151                 cmp = hist_entry__collapse(iter, he);
152
153                 if (!cmp) {
154                         iter->count += he->count;
155                         hist_entry__free(he);
156                         return;
157                 }
158
159                 if (cmp < 0)
160                         p = &(*p)->rb_left;
161                 else
162                         p = &(*p)->rb_right;
163         }
164
165         rb_link_node(&he->rb_node, parent, p);
166         rb_insert_color(&he->rb_node, root);
167 }
168
169 void hists__collapse_resort(struct hists *self)
170 {
171         struct rb_root tmp;
172         struct rb_node *next;
173         struct hist_entry *n;
174
175         if (!sort__need_collapse)
176                 return;
177
178         tmp = RB_ROOT;
179         next = rb_first(&self->entries);
180
181         while (next) {
182                 n = rb_entry(next, struct hist_entry, rb_node);
183                 next = rb_next(&n->rb_node);
184
185                 rb_erase(&n->rb_node, &self->entries);
186                 collapse__insert_entry(&tmp, n);
187         }
188
189         self->entries = tmp;
190 }
191
192 /*
193  * reverse the map, sort on count.
194  */
195
196 static void __hists__insert_output_entry(struct rb_root *entries,
197                                          struct hist_entry *he,
198                                          u64 min_callchain_hits)
199 {
200         struct rb_node **p = &entries->rb_node;
201         struct rb_node *parent = NULL;
202         struct hist_entry *iter;
203
204         if (symbol_conf.use_callchain)
205                 callchain_param.sort(&he->sorted_chain, he->callchain,
206                                       min_callchain_hits, &callchain_param);
207
208         while (*p != NULL) {
209                 parent = *p;
210                 iter = rb_entry(parent, struct hist_entry, rb_node);
211
212                 if (he->count > iter->count)
213                         p = &(*p)->rb_left;
214                 else
215                         p = &(*p)->rb_right;
216         }
217
218         rb_link_node(&he->rb_node, parent, p);
219         rb_insert_color(&he->rb_node, entries);
220 }
221
222 u64 hists__output_resort(struct hists *self)
223 {
224         struct rb_root tmp;
225         struct rb_node *next;
226         struct hist_entry *n;
227         u64 min_callchain_hits;
228         u64 nr_hists = 0;
229
230         min_callchain_hits = self->stats.total * (callchain_param.min_percent / 100);
231
232         tmp = RB_ROOT;
233         next = rb_first(&self->entries);
234
235         while (next) {
236                 n = rb_entry(next, struct hist_entry, rb_node);
237                 next = rb_next(&n->rb_node);
238
239                 rb_erase(&n->rb_node, &self->entries);
240                 __hists__insert_output_entry(&tmp, n, min_callchain_hits);
241                 ++nr_hists;
242         }
243
244         self->entries = tmp;
245         return nr_hists;
246 }
247
248 static size_t callchain__fprintf_left_margin(FILE *fp, int left_margin)
249 {
250         int i;
251         int ret = fprintf(fp, "            ");
252
253         for (i = 0; i < left_margin; i++)
254                 ret += fprintf(fp, " ");
255
256         return ret;
257 }
258
259 static size_t ipchain__fprintf_graph_line(FILE *fp, int depth, int depth_mask,
260                                           int left_margin)
261 {
262         int i;
263         size_t ret = callchain__fprintf_left_margin(fp, left_margin);
264
265         for (i = 0; i < depth; i++)
266                 if (depth_mask & (1 << i))
267                         ret += fprintf(fp, "|          ");
268                 else
269                         ret += fprintf(fp, "           ");
270
271         ret += fprintf(fp, "\n");
272
273         return ret;
274 }
275
276 static size_t ipchain__fprintf_graph(FILE *fp, struct callchain_list *chain,
277                                      int depth, int depth_mask, int count,
278                                      u64 total_samples, int hits,
279                                      int left_margin)
280 {
281         int i;
282         size_t ret = 0;
283
284         ret += callchain__fprintf_left_margin(fp, left_margin);
285         for (i = 0; i < depth; i++) {
286                 if (depth_mask & (1 << i))
287                         ret += fprintf(fp, "|");
288                 else
289                         ret += fprintf(fp, " ");
290                 if (!count && i == depth - 1) {
291                         double percent;
292
293                         percent = hits * 100.0 / total_samples;
294                         ret += percent_color_fprintf(fp, "--%2.2f%%-- ", percent);
295                 } else
296                         ret += fprintf(fp, "%s", "          ");
297         }
298         if (chain->ms.sym)
299                 ret += fprintf(fp, "%s\n", chain->ms.sym->name);
300         else
301                 ret += fprintf(fp, "%p\n", (void *)(long)chain->ip);
302
303         return ret;
304 }
305
306 static struct symbol *rem_sq_bracket;
307 static struct callchain_list rem_hits;
308
309 static void init_rem_hits(void)
310 {
311         rem_sq_bracket = malloc(sizeof(*rem_sq_bracket) + 6);
312         if (!rem_sq_bracket) {
313                 fprintf(stderr, "Not enough memory to display remaining hits\n");
314                 return;
315         }
316
317         strcpy(rem_sq_bracket->name, "[...]");
318         rem_hits.ms.sym = rem_sq_bracket;
319 }
320
321 static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
322                                          u64 total_samples, int depth,
323                                          int depth_mask, int left_margin)
324 {
325         struct rb_node *node, *next;
326         struct callchain_node *child;
327         struct callchain_list *chain;
328         int new_depth_mask = depth_mask;
329         u64 new_total;
330         u64 remaining;
331         size_t ret = 0;
332         int i;
333         uint entries_printed = 0;
334
335         if (callchain_param.mode == CHAIN_GRAPH_REL)
336                 new_total = self->children_hit;
337         else
338                 new_total = total_samples;
339
340         remaining = new_total;
341
342         node = rb_first(&self->rb_root);
343         while (node) {
344                 u64 cumul;
345
346                 child = rb_entry(node, struct callchain_node, rb_node);
347                 cumul = cumul_hits(child);
348                 remaining -= cumul;
349
350                 /*
351                  * The depth mask manages the output of pipes that show
352                  * the depth. We don't want to keep the pipes of the current
353                  * level for the last child of this depth.
354                  * Except if we have remaining filtered hits. They will
355                  * supersede the last child
356                  */
357                 next = rb_next(node);
358                 if (!next && (callchain_param.mode != CHAIN_GRAPH_REL || !remaining))
359                         new_depth_mask &= ~(1 << (depth - 1));
360
361                 /*
362                  * But we keep the older depth mask for the line separator
363                  * to keep the level link until we reach the last child
364                  */
365                 ret += ipchain__fprintf_graph_line(fp, depth, depth_mask,
366                                                    left_margin);
367                 i = 0;
368                 list_for_each_entry(chain, &child->val, list) {
369                         ret += ipchain__fprintf_graph(fp, chain, depth,
370                                                       new_depth_mask, i++,
371                                                       new_total,
372                                                       cumul,
373                                                       left_margin);
374                 }
375                 ret += __callchain__fprintf_graph(fp, child, new_total,
376                                                   depth + 1,
377                                                   new_depth_mask | (1 << depth),
378                                                   left_margin);
379                 node = next;
380                 if (++entries_printed == callchain_param.print_limit)
381                         break;
382         }
383
384         if (callchain_param.mode == CHAIN_GRAPH_REL &&
385                 remaining && remaining != new_total) {
386
387                 if (!rem_sq_bracket)
388                         return ret;
389
390                 new_depth_mask &= ~(1 << (depth - 1));
391
392                 ret += ipchain__fprintf_graph(fp, &rem_hits, depth,
393                                               new_depth_mask, 0, new_total,
394                                               remaining, left_margin);
395         }
396
397         return ret;
398 }
399
400 static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
401                                        u64 total_samples, int left_margin)
402 {
403         struct callchain_list *chain;
404         bool printed = false;
405         int i = 0;
406         int ret = 0;
407         u32 entries_printed = 0;
408
409         list_for_each_entry(chain, &self->val, list) {
410                 if (!i++ && sort__first_dimension == SORT_SYM)
411                         continue;
412
413                 if (!printed) {
414                         ret += callchain__fprintf_left_margin(fp, left_margin);
415                         ret += fprintf(fp, "|\n");
416                         ret += callchain__fprintf_left_margin(fp, left_margin);
417                         ret += fprintf(fp, "---");
418
419                         left_margin += 3;
420                         printed = true;
421                 } else
422                         ret += callchain__fprintf_left_margin(fp, left_margin);
423
424                 if (chain->ms.sym)
425                         ret += fprintf(fp, " %s\n", chain->ms.sym->name);
426                 else
427                         ret += fprintf(fp, " %p\n", (void *)(long)chain->ip);
428
429                 if (++entries_printed == callchain_param.print_limit)
430                         break;
431         }
432
433         ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin);
434
435         return ret;
436 }
437
438 static size_t callchain__fprintf_flat(FILE *fp, struct callchain_node *self,
439                                       u64 total_samples)
440 {
441         struct callchain_list *chain;
442         size_t ret = 0;
443
444         if (!self)
445                 return 0;
446
447         ret += callchain__fprintf_flat(fp, self->parent, total_samples);
448
449
450         list_for_each_entry(chain, &self->val, list) {
451                 if (chain->ip >= PERF_CONTEXT_MAX)
452                         continue;
453                 if (chain->ms.sym)
454                         ret += fprintf(fp, "                %s\n", chain->ms.sym->name);
455                 else
456                         ret += fprintf(fp, "                %p\n",
457                                         (void *)(long)chain->ip);
458         }
459
460         return ret;
461 }
462
463 static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
464                                             u64 total_samples, int left_margin)
465 {
466         struct rb_node *rb_node;
467         struct callchain_node *chain;
468         size_t ret = 0;
469         u32 entries_printed = 0;
470
471         rb_node = rb_first(&self->sorted_chain);
472         while (rb_node) {
473                 double percent;
474
475                 chain = rb_entry(rb_node, struct callchain_node, rb_node);
476                 percent = chain->hit * 100.0 / total_samples;
477                 switch (callchain_param.mode) {
478                 case CHAIN_FLAT:
479                         ret += percent_color_fprintf(fp, "           %6.2f%%\n",
480                                                      percent);
481                         ret += callchain__fprintf_flat(fp, chain, total_samples);
482                         break;
483                 case CHAIN_GRAPH_ABS: /* Falldown */
484                 case CHAIN_GRAPH_REL:
485                         ret += callchain__fprintf_graph(fp, chain, total_samples,
486                                                         left_margin);
487                 case CHAIN_NONE:
488                 default:
489                         break;
490                 }
491                 ret += fprintf(fp, "\n");
492                 if (++entries_printed == callchain_param.print_limit)
493                         break;
494                 rb_node = rb_next(rb_node);
495         }
496
497         return ret;
498 }
499
500 int hist_entry__snprintf(struct hist_entry *self, char *s, size_t size,
501                          struct hists *pair_hists, bool show_displacement,
502                          long displacement, bool color, u64 session_total)
503 {
504         struct sort_entry *se;
505         u64 count, total, count_sys, count_us, count_guest_sys, count_guest_us;
506         const char *sep = symbol_conf.field_sep;
507         int ret;
508
509         if (symbol_conf.exclude_other && !self->parent)
510                 return 0;
511
512         if (pair_hists) {
513                 count = self->pair ? self->pair->count : 0;
514                 total = pair_hists->stats.total;
515                 count_sys = self->pair ? self->pair->count_sys : 0;
516                 count_us = self->pair ? self->pair->count_us : 0;
517                 count_guest_sys = self->pair ? self->pair->count_guest_sys : 0;
518                 count_guest_us = self->pair ? self->pair->count_guest_us : 0;
519         } else {
520                 count = self->count;
521                 total = session_total;
522                 count_sys = self->count_sys;
523                 count_us = self->count_us;
524                 count_guest_sys = self->count_guest_sys;
525                 count_guest_us = self->count_guest_us;
526         }
527
528         if (total) {
529                 if (color)
530                         ret = percent_color_snprintf(s, size,
531                                                      sep ? "%.2f" : "   %6.2f%%",
532                                                      (count * 100.0) / total);
533                 else
534                         ret = snprintf(s, size, sep ? "%.2f" : "   %6.2f%%",
535                                        (count * 100.0) / total);
536                 if (symbol_conf.show_cpu_utilization) {
537                         ret += percent_color_snprintf(s + ret, size - ret,
538                                         sep ? "%.2f" : "   %6.2f%%",
539                                         (count_sys * 100.0) / total);
540                         ret += percent_color_snprintf(s + ret, size - ret,
541                                         sep ? "%.2f" : "   %6.2f%%",
542                                         (count_us * 100.0) / total);
543                         if (perf_guest) {
544                                 ret += percent_color_snprintf(s + ret,
545                                                 size - ret,
546                                                 sep ? "%.2f" : "   %6.2f%%",
547                                                 (count_guest_sys * 100.0) /
548                                                                 total);
549                                 ret += percent_color_snprintf(s + ret,
550                                                 size - ret,
551                                                 sep ? "%.2f" : "   %6.2f%%",
552                                                 (count_guest_us * 100.0) /
553                                                                 total);
554                         }
555                 }
556         } else
557                 ret = snprintf(s, size, sep ? "%lld" : "%12lld ", count);
558
559         if (symbol_conf.show_nr_samples) {
560                 if (sep)
561                         ret += snprintf(s + ret, size - ret, "%c%lld", *sep, count);
562                 else
563                         ret += snprintf(s + ret, size - ret, "%11lld", count);
564         }
565
566         if (pair_hists) {
567                 char bf[32];
568                 double old_percent = 0, new_percent = 0, diff;
569
570                 if (total > 0)
571                         old_percent = (count * 100.0) / total;
572                 if (session_total > 0)
573                         new_percent = (self->count * 100.0) / session_total;
574
575                 diff = new_percent - old_percent;
576
577                 if (fabs(diff) >= 0.01)
578                         snprintf(bf, sizeof(bf), "%+4.2F%%", diff);
579                 else
580                         snprintf(bf, sizeof(bf), " ");
581
582                 if (sep)
583                         ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
584                 else
585                         ret += snprintf(s + ret, size - ret, "%11.11s", bf);
586
587                 if (show_displacement) {
588                         if (displacement)
589                                 snprintf(bf, sizeof(bf), "%+4ld", displacement);
590                         else
591                                 snprintf(bf, sizeof(bf), " ");
592
593                         if (sep)
594                                 ret += snprintf(s + ret, size - ret, "%c%s", *sep, bf);
595                         else
596                                 ret += snprintf(s + ret, size - ret, "%6.6s", bf);
597                 }
598         }
599
600         list_for_each_entry(se, &hist_entry__sort_list, list) {
601                 if (se->elide)
602                         continue;
603
604                 ret += snprintf(s + ret, size - ret, "%s", sep ?: "  ");
605                 ret += se->se_snprintf(self, s + ret, size - ret,
606                                        se->se_width ? *se->se_width : 0);
607         }
608
609         return ret;
610 }
611
612 int hist_entry__fprintf(struct hist_entry *self, struct hists *pair_hists,
613                         bool show_displacement, long displacement, FILE *fp,
614                         u64 session_total)
615 {
616         char bf[512];
617         hist_entry__snprintf(self, bf, sizeof(bf), pair_hists,
618                              show_displacement, displacement,
619                              true, session_total);
620         return fprintf(fp, "%s\n", bf);
621 }
622
623 static size_t hist_entry__fprintf_callchain(struct hist_entry *self, FILE *fp,
624                                             u64 session_total)
625 {
626         int left_margin = 0;
627
628         if (sort__first_dimension == SORT_COMM) {
629                 struct sort_entry *se = list_first_entry(&hist_entry__sort_list,
630                                                          typeof(*se), list);
631                 left_margin = se->se_width ? *se->se_width : 0;
632                 left_margin -= thread__comm_len(self->thread);
633         }
634
635         return hist_entry_callchain__fprintf(fp, self, session_total,
636                                              left_margin);
637 }
638
639 size_t hists__fprintf(struct hists *self, struct hists *pair,
640                       bool show_displacement, FILE *fp)
641 {
642         struct sort_entry *se;
643         struct rb_node *nd;
644         size_t ret = 0;
645         unsigned long position = 1;
646         long displacement = 0;
647         unsigned int width;
648         const char *sep = symbol_conf.field_sep;
649         char *col_width = symbol_conf.col_width_list_str;
650
651         init_rem_hits();
652
653         fprintf(fp, "# %s", pair ? "Baseline" : "Overhead");
654
655         if (symbol_conf.show_nr_samples) {
656                 if (sep)
657                         fprintf(fp, "%cSamples", *sep);
658                 else
659                         fputs("  Samples  ", fp);
660         }
661
662         if (symbol_conf.show_cpu_utilization) {
663                 if (sep) {
664                         ret += fprintf(fp, "%csys", *sep);
665                         ret += fprintf(fp, "%cus", *sep);
666                         if (perf_guest) {
667                                 ret += fprintf(fp, "%cguest sys", *sep);
668                                 ret += fprintf(fp, "%cguest us", *sep);
669                         }
670                 } else {
671                         ret += fprintf(fp, "  sys  ");
672                         ret += fprintf(fp, "  us  ");
673                         if (perf_guest) {
674                                 ret += fprintf(fp, "  guest sys  ");
675                                 ret += fprintf(fp, "  guest us  ");
676                         }
677                 }
678         }
679
680         if (pair) {
681                 if (sep)
682                         ret += fprintf(fp, "%cDelta", *sep);
683                 else
684                         ret += fprintf(fp, "  Delta    ");
685
686                 if (show_displacement) {
687                         if (sep)
688                                 ret += fprintf(fp, "%cDisplacement", *sep);
689                         else
690                                 ret += fprintf(fp, " Displ");
691                 }
692         }
693
694         list_for_each_entry(se, &hist_entry__sort_list, list) {
695                 if (se->elide)
696                         continue;
697                 if (sep) {
698                         fprintf(fp, "%c%s", *sep, se->se_header);
699                         continue;
700                 }
701                 width = strlen(se->se_header);
702                 if (se->se_width) {
703                         if (symbol_conf.col_width_list_str) {
704                                 if (col_width) {
705                                         *se->se_width = atoi(col_width);
706                                         col_width = strchr(col_width, ',');
707                                         if (col_width)
708                                                 ++col_width;
709                                 }
710                         }
711                         width = *se->se_width = max(*se->se_width, width);
712                 }
713                 fprintf(fp, "  %*s", width, se->se_header);
714         }
715         fprintf(fp, "\n");
716
717         if (sep)
718                 goto print_entries;
719
720         fprintf(fp, "# ........");
721         if (symbol_conf.show_nr_samples)
722                 fprintf(fp, " ..........");
723         if (pair) {
724                 fprintf(fp, " ..........");
725                 if (show_displacement)
726                         fprintf(fp, " .....");
727         }
728         list_for_each_entry(se, &hist_entry__sort_list, list) {
729                 unsigned int i;
730
731                 if (se->elide)
732                         continue;
733
734                 fprintf(fp, "  ");
735                 if (se->se_width)
736                         width = *se->se_width;
737                 else
738                         width = strlen(se->se_header);
739                 for (i = 0; i < width; i++)
740                         fprintf(fp, ".");
741         }
742
743         fprintf(fp, "\n#\n");
744
745 print_entries:
746         for (nd = rb_first(&self->entries); nd; nd = rb_next(nd)) {
747                 struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
748
749                 if (show_displacement) {
750                         if (h->pair != NULL)
751                                 displacement = ((long)h->pair->position -
752                                                 (long)position);
753                         else
754                                 displacement = 0;
755                         ++position;
756                 }
757                 ret += hist_entry__fprintf(h, pair, show_displacement,
758                                            displacement, fp, self->stats.total);
759
760                 if (symbol_conf.use_callchain)
761                         ret += hist_entry__fprintf_callchain(h, fp, self->stats.total);
762
763                 if (h->ms.map == NULL && verbose > 1) {
764                         __map_groups__fprintf_maps(&h->thread->mg,
765                                                    MAP__FUNCTION, verbose, fp);
766                         fprintf(fp, "%.10s end\n", graph_dotted_line);
767                 }
768         }
769
770         free(rem_sq_bracket);
771
772         return ret;
773 }