OILS / metrics / cpython-defs.R View on Github | oilshell.org

72 lines, 49 significant
1#!/usr/bin/env Rscript
2#
3# bytecode.R -- Analyze output of opyc dis-tables.
4#
5# Usage:
6# bytecode.R ACTION IN_DIR OUT_DIR
7
8library(dplyr)
9library(tidyr) # spread()
10library(stringr)
11
12source('benchmarks/common.R')
13
14options(stringsAsFactors = F,
15 # Make the report wide. tibble.width doesn't appear to do this?
16 width=200,
17 tibble.print_max=40
18)
19
20Report = function(ctx) {
21 Banner('Summary of methods.tsv:')
22 ctx$methods %>% count(used) %>% arrange(desc(n)) -> f0
23 ShowFrame('Methods used:', f0)
24
25 ctx$methods %>% filter(used == T) %>% count(file) %>% arrange(desc(n)) -> f1
26 ShowFrame('Methods by file (after filtering):', f1)
27 ShowValue('Kept %d of %d methods in %d files', sum(ctx$methods$used),
28 nrow(ctx$methods), nrow(f1))
29
30 ctx$methods %>% count(flags) %>% arrange(desc(n)) -> f2
31 ShowFrame('Methods by flag', f2)
32
33 # libc.c and fastlex.c are mostly implemented. posixmodule are just
34 # bindings?
35 ctx$methods %>%
36 filter(used == T) %>%
37 mutate(basename=basename(file)) %>%
38 filter(basename != 'libc.c' & basename != 'fastlex.c' &
39 basename != 'setobject.c' & basename != 'zipimport.c') %>%
40 filter(py_method_name != '__length_hint__') %>%
41 select(c(basename, py_method_name)) %>%
42 arrange(basename, py_method_name) -> f3
43 ShowFrame('Methods to reimplement:', f3)
44 ShowValue('Total: %d methods', nrow(f3))
45}
46
47Load = function(in_dir) {
48 list(
49 methods = read.table(
50 file.path(in_dir, 'methods.tsv'), sep='\t', header=T)
51 )
52}
53
54main = function(argv) {
55 action = argv[[1]]
56
57 if (action == 'metrics') {
58 in_dir = argv[[2]]
59 ctx = Load(in_dir)
60 Report(ctx)
61
62 } else {
63 Log("Invalid action '%s'", action)
64 quit(status = 1)
65 }
66}
67
68if (length(sys.frames()) == 0) {
69 # increase ggplot font size globally
70 #theme_set(theme_grey(base_size = 20))
71 main(commandArgs(TRUE))
72}