Giter VIP home page Giter VIP logo

cpp_etudes's Introduction

cpp_etudes

cpp_etudes is a cpp project integrated with google benchmark, google test for validating cpp features and refining vectorized builtin function of databases. It can be built by both clang and gcc. Some interesting perl scripts are also included.

Scripts

calltree.pl: A smart tool to surf C++ source code

run commands to get usage of calltree.pl as follows:

calltree.pl
calltree.pl help
calltree.pl -h
calltree.pl --help

image

csvtable.pl: create a ascii-border table from CSV format.

  1. create a csv file
cat >repeat.csv  <<'DONE'
t,vectorization,new-vectorization,non-vectorization,new speedup,vectorization speedup
repeat/const_times,3112ms, 9797ms, 13986ms(4X memory),3.14,4.49
repeat/const_s, 8107ms, 30231ms, 39501ms(32X memory), 3.72,4.87
repeat,9141ms, 32182ms,44315ms(32X memory), 3.52,4.84
DONE
  1. generate a ascii-border table
cat repeat.csv |./csvtable.pl

+====================+===============+===================+=====================+=============+=======================+
| test               | vectorization | new-vectorization | non-vectorization   | new speedup | vectorization speedup |
+====================+===============+===================+=====================+=============+=======================+
| repeat/const_times | 3112ms        | 9797ms            | 13986ms(4X memory)  | 3.14        | 4.49                  |
| repeat/const_s     | 8107ms        | 30231ms           | 39501ms(32X memory) | 3.72        | 4.87                  |
| repeat             | 9141ms        | 32182ms           | 44315ms(32X memory) | 3.52        | 4.84                  |
+--------------------+---------------+-------------------+---------------------+-------------+-----------------------+

cpptree.pl: show class hierarchy of cpp project in the style of Linux utility tree.

  1. usage, try with incubator-doris, other cpp projects are just ok.
# format

./cpptree.pl <keyword|regex> <filter> <verbose(0|1)> <depth(num)>
- keyword for exact match, regex for fuzzy match;
- subtrees whose leaf nodes does not match filter are pruned, default value is '' means match all;
- verbose=0, no file locations output; otherwise succinctly output;
- depth=num, print max derivation depth.

git clone https://github.com/satanson/incubator-doris.git
cd incubator-doris

# show all classes
./cpptree.pl '\w+'

# show all classes with file locations.
./cpptree.pl '\w+' '' 1

# show all classes exact-match ExecNode if ExecNode class exists
./cpptree.pl 'ExecNode' '' 1

# show all classes fuzzy-match regex '.*Node$' if the literal class name not exists.
./cpptree.pl '.*Node$' '' 1

# show all classes and depth of derivation relationship is less than 3
./cpptree.pl '\w+' '' 1 3

# show all classes whose ancestor class matches 'Node' and itself or its offsprings matches 'Scan'
/cpptree.pl 'Node' 'Scan'

  1. some outputs
cd incubator-doris
./cpptree.pl 'ExecNode'

image

cd ClickHouse
./cpptree.pl IProcessor

image

cd ClickHouse
./cpptree.pl IDataType '' 1

image

cd incubator-doris
./cpptree.pl 'Node' 'Scan'

image

cd ClickHouse
./cpptree.pl IProcessor Aggregat 1

image

color_palette.pl: show color palette for colorful terminal output.

  1. usage
./color_palette.pl

image

cpp_etudes's People

Contributors

bowenxiao1999 avatar cerdore avatar deardeng avatar prettykernel avatar qingzhongli avatar satanson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpp_etudes's Issues

Add go_calltree.pl

A lot of system written in golang, like kuberntes, docker and etc, implement go_calltree.pl to show calling and called relation between functions.

[feature request] Whether recursive functions can be highlighted

I use calltree.el in reading some open source software. It's an amazing art work, but I think there are some features can make it better, here are two suggestions.

  1. The caller function marked in another color(like blue) or use a special word to mark it in mode 1, just like mode 0.

image

  1. Provide an option argument to make recursive function call chain only appear once, in below picture, the call chain recur_func3 -> recur_func2 -> recur_func3 appera twice.

image

  1. After the source code change, auto regenerate the cpptree cache.

  2. Provide an option argument to set the .calltree.result.cached* files directory but not just save them in the same dir of calltree.pl.

test code for 1 and 2.

// rc.h
void recur_func1();

void recur_func2();

void recur_func3();
// rc.c
#include "rc.h"

void recur_func1() {
  recur_func2();
  recur_func1();
}

void recur_func2() {
  recur_func3();
}

void recur_func3() {
  recur_func1();
}

How to quickly execute a command like "[vim src/net/tls.cc +55]" in the output

There are command like [vim src/net/tls.cc +55] in calltree.pl output
How did you perform it and what tools/methods you used

Can I click to execute it?Or can I only copy-paste to execute it?
Windows Terminal (ssh to Ubuntu) does not recognize this command in the output and cannot be directly clicked to execute.

Output like src/net/tls.cc:55 can be recognized by the terminal in vscode, click to jump to the corresponding location.

执行./cpptree.pl 报错Dumper.c: loadable library and perl binaries are mismatched (got handshake key 0xc500080, needed 0xc400080)

oushu@zhenchuan-mac cpp_etudes % perl -v

This is perl 5, version 28, subversion 0 (v5.28.0) built for darwin-thread-multi-2level

Copyright 1987-2018, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

Cannot stop search when hit main function

  │           ├── perf_logrd    [vim orcasql-myfile/perf/perf_fshadow_logrd.c +30]
  │           │   └── main      [vim orcasql-myfile/perf/perf_fshadow_logrd.c +82]  <-- should stop to search here!
  │           │       ├── show_long_status      [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +143]
  │           │       │   ├── Ssl_mysql_main_status::show_ssl_ctx_sess_accept   [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +175]
  │           │       │   ├── Ssl_mysql_main_status::show_ssl_ctx_sess_accept_good      [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +181]
  │           │       │   ├── Ssl_mysql_main_status::show_ssl_ctx_sess_connect_good     [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +187]
  │           │       │   ├── Ssl_mysql_main_status::show_ssl_ctx_sess_accept_renegotiate       [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +193]
  │           │       │   ├── Ssl_mysql_main_status::show_ssl_ctx_sess_connect_renegotiate      [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +200]
  │           │       │   ├── Ssl_mysql_main_status::show_ssl_ctx_sess_cb_hits  [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +207]
  │           │       │   ├── Ssl_mysql_main_status::show_ssl_ctx_sess_hits     [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +213]
  │           │       │   ├── Ssl_mysql_main_status::show_ssl_ctx_sess_cache_full       [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +219]
  │           │       │   ├── Ssl_mysql_main_status::show_ssl_ctx_sess_misses   [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +225]
  │           │       │   ├── Ssl_mysql_main_status::show_ssl_ctx_sess_timeouts [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +231]
  │           │       │   ├── Ssl_mysql_main_status::show_ssl_ctx_sess_number   [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +237]
  │           │       │   ├── Ssl_mysql_main_status::show_ssl_ctx_sess_connect  [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +244]
  │           │       │   ├── Ssl_mysql_main_status::show_ssl_ctx_sess_get_cache_size   [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +250]
  │           │       │   ├── Ssl_mysql_main_status::show_ssl_ctx_get_verify_mode       [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +257]
  │           │       │   └── Ssl_mysql_main_status::show_ssl_ctx_get_verify_depth      [vim orcasql-mysql/sql/ssl_acceptor_context_operator.cc +263]

On ubuntu 20.4 calltree.pl failed but cpptree.pl Ok

I can not get what caused this

$ perl -v

This is perl 5, version 30, subversion 0 (v5.30.0) built for x86_64-linux-gnu-thread-multi
(with 50 registered patches, see perl -V for more detail)

$ cd workflow-master/src    # source code from https://github.com/sogou/workflow
$ cpptree.pl '\w+' '' 1     # OK

$ calltree.pl 'SubTask::subtask_done' '' 0 1 1  # fail

syntax error at /opt/cpp_etudes/calltree.pl line 1039, near "$_ <="
Type of arg 1 to main::any must be block or sub {} (not reference constructor) at /opt/cpp_etudes/calltree.pl line 1039, near "}}"
Global symbol "@lineno" requires explicit package name (did you forget to declare "my @lineno"?) at /opt/cpp_etudes/calltree.pl line 1039.
syntax error at /opt/cpp_etudes/calltree.pl line 1041, near "}"
Global symbol "@nodes" requires explicit package name (did you forget to declare "my @nodes"?) at /opt/cpp_etudes/calltree.pl line 1041.
Global symbol "$name_pattern" requires explicit package name (did you forget to declare "my $name_pattern"?) at /opt/cpp_etudes/calltree.pl line 1043.
Global symbol "$filter" requires explicit package name (did you forget to declare "my $filter"?) at /opt/cpp_etudes/calltree.pl line 1055.
Global symbol "$files_included" requires explicit package name (did you forget to declare "my $files_included"?) at /opt/cpp_etudes/calltree.pl line 1055.
Global symbol "$depth" requires explicit package name (did you forget to declare "my $depth"?) at /opt/cpp_etudes/calltree.pl line 1055.
Global symbol "@nodes" requires explicit package name (did you forget to declare "my @nodes"?) at /opt/cpp_etudes/calltree.pl line 1066.
syntax error at /opt/cpp_etudes/calltree.pl line 1068, near "}"
/opt/cpp_etudes/calltree.pl has too many errors.

请问这里的索引是否应该是 $i - 1 ?

push @result, [ $prev_file, $prev_lineno, $three_parts[$i][1], $prev_line ];

如果我没理解错的话, 这里的四元组中的第三个元素是函数定义的最后一行, 按这样理解这里的一行应该是:

 push @result, [ $prev_file, $prev_lineno, $three_parts[$i-1][1], $prev_line ]; 

否则将会产生下面这样的四元组:

jute/inc/EIndex.hh, 32, 24,        virtual ~EIndex() {} 

而修改后:

jute/inc/EIndex.hh, 32, 32,        virtual ~EIndex() {} 

Add a gotree.pl

A lot of system written in golang, like kuberntes, docker and etc, implement gotree.pl to show interface& struct hierarchy and speedup reading source code.

Add rusttree.pl

Write rusttree.pl to show type hierarchy of rust project.

Add rust_calltree.pl

Add rust_calltree.pl to show calling and called relation of funtions in Rust project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.