1*bb86c7edSAndroid Build Coastguard Worker#!/bin/bash 2*bb86c7edSAndroid Build Coastguard Worker 3*bb86c7edSAndroid Build Coastguard Worker# Generates a graphviz dependency graph for :ruy, with details trimmed. 4*bb86c7edSAndroid Build Coastguard Worker# Suggested rendering: pipe to `neato` (part of graphviz standard distribution) 5*bb86c7edSAndroid Build Coastguard Worker# doc/depgraph.sh | dot -Tsvg > depgraph.svg 6*bb86c7edSAndroid Build Coastguard Worker 7*bb86c7edSAndroid Build Coastguard Workerdrop=( 8*bb86c7edSAndroid Build Coastguard Worker ':platform' 9*bb86c7edSAndroid Build Coastguard Worker ':check_macros' 10*bb86c7edSAndroid Build Coastguard Worker ':asm_helpers' 11*bb86c7edSAndroid Build Coastguard Worker ':size_util' 12*bb86c7edSAndroid Build Coastguard Worker ':system_aligned_alloc' 13*bb86c7edSAndroid Build Coastguard Worker ':side_pair' 14*bb86c7edSAndroid Build Coastguard Worker ':opt_set' 15*bb86c7edSAndroid Build Coastguard Worker ':blocking_counter' 16*bb86c7edSAndroid Build Coastguard Worker ':wait' 17*bb86c7edSAndroid Build Coastguard Worker ':time' 18*bb86c7edSAndroid Build Coastguard Worker ':path' 19*bb86c7edSAndroid Build Coastguard Worker ':performance_advisory' 20*bb86c7edSAndroid Build Coastguard Worker ':tune' 21*bb86c7edSAndroid Build Coastguard Worker ':matrix' 22*bb86c7edSAndroid Build Coastguard Worker ':mat' 23*bb86c7edSAndroid Build Coastguard Worker ':mul_params' 24*bb86c7edSAndroid Build Coastguard Worker ':context_get_ctx' 25*bb86c7edSAndroid Build Coastguard Worker ':have_built_path_for' 26*bb86c7edSAndroid Build Coastguard Worker ':pack_common' 27*bb86c7edSAndroid Build Coastguard Worker ':kernel_common' 28*bb86c7edSAndroid Build Coastguard Worker ':trace' 29*bb86c7edSAndroid Build Coastguard Worker ':validate' 30*bb86c7edSAndroid Build Coastguard Worker 'profiler:instrumentation' 31*bb86c7edSAndroid Build Coastguard Worker '\bclog\b' 32*bb86c7edSAndroid Build Coastguard Worker '\bcpuinfo\b' 33*bb86c7edSAndroid Build Coastguard Worker ':apply_multiplier' 34*bb86c7edSAndroid Build Coastguard Worker '\blabel=' 35*bb86c7edSAndroid Build Coastguard Worker) 36*bb86c7edSAndroid Build Coastguard Worker 37*bb86c7edSAndroid Build Coastguard Workergraph="$(bazel query 'kind("cc_library", deps(//ruy))' --output graph --noimplicit_deps 2>/dev/null)" 38*bb86c7edSAndroid Build Coastguard Worker 39*bb86c7edSAndroid Build Coastguard Workergraph="$(echo "${graph}" | sed 's|//ruy/\?||g')" 40*bb86c7edSAndroid Build Coastguard Worker 41*bb86c7edSAndroid Build Coastguard Workerfor t in "${drop[@]}"; do 42*bb86c7edSAndroid Build Coastguard Worker graph="$(echo "${graph}" | grep -v "${t}")" 43*bb86c7edSAndroid Build Coastguard Workerdone 44*bb86c7edSAndroid Build Coastguard Worker 45*bb86c7edSAndroid Build Coastguard Workergraph="$(echo "${graph}" | sed 's|//:cpuinfo_with_unstripped_include_path||g')" 46*bb86c7edSAndroid Build Coastguard Workergraph="$(echo "${graph}" | sed 's|//third_party/cpuinfo:[a-z0-9_]*|@cpuinfo|g')" 47*bb86c7edSAndroid Build Coastguard Worker 48*bb86c7edSAndroid Build Coastguard Workerfrontend=( 49*bb86c7edSAndroid Build Coastguard Worker ':ruy' 50*bb86c7edSAndroid Build Coastguard Worker ':context' 51*bb86c7edSAndroid Build Coastguard Worker ':frontend' 52*bb86c7edSAndroid Build Coastguard Worker ':prepare_packed_matrices' 53*bb86c7edSAndroid Build Coastguard Worker ':create_trmul_params' 54*bb86c7edSAndroid Build Coastguard Worker) 55*bb86c7edSAndroid Build Coastguard Worker 56*bb86c7edSAndroid Build Coastguard Workermiddleend=( 57*bb86c7edSAndroid Build Coastguard Worker ':ctx' 58*bb86c7edSAndroid Build Coastguard Worker ':trmul_params' 59*bb86c7edSAndroid Build Coastguard Worker ':trmul' 60*bb86c7edSAndroid Build Coastguard Worker ':block_map' 61*bb86c7edSAndroid Build Coastguard Worker ':cpuinfo' 62*bb86c7edSAndroid Build Coastguard Worker ':cpu_cache_params' 63*bb86c7edSAndroid Build Coastguard Worker ':allocator' 64*bb86c7edSAndroid Build Coastguard Worker ':prepacked_cache' 65*bb86c7edSAndroid Build Coastguard Worker) 66*bb86c7edSAndroid Build Coastguard Worker 67*bb86c7edSAndroid Build Coastguard Workerbackend=( 68*bb86c7edSAndroid Build Coastguard Worker ':kernel.*' 69*bb86c7edSAndroid Build Coastguard Worker ':pack.*' 70*bb86c7edSAndroid Build Coastguard Worker) 71*bb86c7edSAndroid Build Coastguard Worker 72*bb86c7edSAndroid Build Coastguard Workerthreadpool=( 73*bb86c7edSAndroid Build Coastguard Worker ':thread_pool' 74*bb86c7edSAndroid Build Coastguard Worker) 75*bb86c7edSAndroid Build Coastguard Worker 76*bb86c7edSAndroid Build Coastguard Workerfrontend_lines=() 77*bb86c7edSAndroid Build Coastguard Workermiddleend_lines=() 78*bb86c7edSAndroid Build Coastguard Workerbackend_lines=() 79*bb86c7edSAndroid Build Coastguard Workerthreadpool_lines=() 80*bb86c7edSAndroid Build Coastguard Workermisc_lines=() 81*bb86c7edSAndroid Build Coastguard Workerarrow_lines=() 82*bb86c7edSAndroid Build Coastguard Worker 83*bb86c7edSAndroid Build Coastguard Workerwhile IFS= read -r line; do 84*bb86c7edSAndroid Build Coastguard Worker if [[ "${line}" =~ '->' ]]; then 85*bb86c7edSAndroid Build Coastguard Worker arrow_lines+=("${line}") 86*bb86c7edSAndroid Build Coastguard Worker else 87*bb86c7edSAndroid Build Coastguard Worker handled=false 88*bb86c7edSAndroid Build Coastguard Worker if [ $handled = false ]; then 89*bb86c7edSAndroid Build Coastguard Worker for f in "${frontend[@]}"; do 90*bb86c7edSAndroid Build Coastguard Worker if [[ "${line}" =~ ${f} ]]; then 91*bb86c7edSAndroid Build Coastguard Worker frontend_lines+=("${line}") 92*bb86c7edSAndroid Build Coastguard Worker handled=true 93*bb86c7edSAndroid Build Coastguard Worker break 94*bb86c7edSAndroid Build Coastguard Worker fi 95*bb86c7edSAndroid Build Coastguard Worker done 96*bb86c7edSAndroid Build Coastguard Worker fi 97*bb86c7edSAndroid Build Coastguard Worker if [ $handled = false ]; then 98*bb86c7edSAndroid Build Coastguard Worker for f in "${middleend[@]}"; do 99*bb86c7edSAndroid Build Coastguard Worker if [[ "${line}" =~ ${f} ]]; then 100*bb86c7edSAndroid Build Coastguard Worker middleend_lines+=("${line}") 101*bb86c7edSAndroid Build Coastguard Worker handled=true 102*bb86c7edSAndroid Build Coastguard Worker break 103*bb86c7edSAndroid Build Coastguard Worker fi 104*bb86c7edSAndroid Build Coastguard Worker done 105*bb86c7edSAndroid Build Coastguard Worker fi 106*bb86c7edSAndroid Build Coastguard Worker if [ $handled = false ]; then 107*bb86c7edSAndroid Build Coastguard Worker for f in "${backend[@]}"; do 108*bb86c7edSAndroid Build Coastguard Worker if [[ "${line}" =~ ${f} ]]; then 109*bb86c7edSAndroid Build Coastguard Worker backend_lines+=("${line}") 110*bb86c7edSAndroid Build Coastguard Worker handled=true 111*bb86c7edSAndroid Build Coastguard Worker break 112*bb86c7edSAndroid Build Coastguard Worker fi 113*bb86c7edSAndroid Build Coastguard Worker done 114*bb86c7edSAndroid Build Coastguard Worker fi 115*bb86c7edSAndroid Build Coastguard Worker if [ $handled = false ]; then 116*bb86c7edSAndroid Build Coastguard Worker for f in "${threadpool[@]}"; do 117*bb86c7edSAndroid Build Coastguard Worker if [[ "${line}" =~ ${f} ]]; then 118*bb86c7edSAndroid Build Coastguard Worker threadpool_lines+=("${line}") 119*bb86c7edSAndroid Build Coastguard Worker handled=true 120*bb86c7edSAndroid Build Coastguard Worker break 121*bb86c7edSAndroid Build Coastguard Worker fi 122*bb86c7edSAndroid Build Coastguard Worker done 123*bb86c7edSAndroid Build Coastguard Worker fi 124*bb86c7edSAndroid Build Coastguard Worker if [ $handled = false ]; then 125*bb86c7edSAndroid Build Coastguard Worker if [[ "${line}" =~ ^[[:space:]]+\" ]]; then 126*bb86c7edSAndroid Build Coastguard Worker misc_lines+=("${line}") 127*bb86c7edSAndroid Build Coastguard Worker fi 128*bb86c7edSAndroid Build Coastguard Worker fi 129*bb86c7edSAndroid Build Coastguard Worker fi 130*bb86c7edSAndroid Build Coastguard Workerdone <<< "${graph}" 131*bb86c7edSAndroid Build Coastguard Worker 132*bb86c7edSAndroid Build Coastguard Workerecho "digraph ruy {" 133*bb86c7edSAndroid Build Coastguard Workerecho " splines = true" 134*bb86c7edSAndroid Build Coastguard Workerecho " node [shape=box]" 135*bb86c7edSAndroid Build Coastguard Workerfor f in "${frontend_lines[@]}"; do 136*bb86c7edSAndroid Build Coastguard Worker echo " $f [style=filled, color=\"#B2EBF2\"];" 137*bb86c7edSAndroid Build Coastguard Workerdone 138*bb86c7edSAndroid Build Coastguard Workerfor m in "${middleend_lines[@]}"; do 139*bb86c7edSAndroid Build Coastguard Worker echo " $m [style=filled, color=\"#C8E6C9\"];" 140*bb86c7edSAndroid Build Coastguard Workerdone 141*bb86c7edSAndroid Build Coastguard Workerfor b in "${backend_lines[@]}"; do 142*bb86c7edSAndroid Build Coastguard Worker echo " $b [style=filled, color=\"#FFCDD2\"];" 143*bb86c7edSAndroid Build Coastguard Workerdone 144*bb86c7edSAndroid Build Coastguard Workerfor b in "${threadpool_lines[@]}"; do 145*bb86c7edSAndroid Build Coastguard Worker echo " $b [style=filled, color=\"#FFF9C4\"];" 146*bb86c7edSAndroid Build Coastguard Workerdone 147*bb86c7edSAndroid Build Coastguard Workerfor m in "${misc_lines[@]}"; do 148*bb86c7edSAndroid Build Coastguard Worker echo "$m" 149*bb86c7edSAndroid Build Coastguard Workerdone 150*bb86c7edSAndroid Build Coastguard Workerfor a in "${arrow_lines[@]}"; do 151*bb86c7edSAndroid Build Coastguard Worker echo "$a" 152*bb86c7edSAndroid Build Coastguard Workerdone 153*bb86c7edSAndroid Build Coastguard Workerecho "}" 154