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