etp-commands

来自「OTP是开放电信平台的简称」· 代码 · 共 1,993 行 · 第 1/4 页

TXT
1,993
字号
  set $etp_flat = 1  etp-1 ($arg0) 0  set $etp_flat = 0  printf ":...\n"  set $etp_search_alloc_n = sizeof(erts_allctrs) / sizeof(*erts_allctrs)  set $etp_search_alloc_i = 0  while $etp_search_alloc_i < $etp_search_alloc_n    if erts_allctrs[$etp_search_alloc_i].alloc      set $etp_search_alloc_f = (erts_allctrs+$etp_search_alloc_i)      while ($etp_search_alloc_f->alloc == debug_alloc) || \            ($etp_search_alloc_f->alloc == stat_alloc) || \            ($etp_search_alloc_f->alloc == map_stat_alloc)        set $etp_search_alloc_f = \          (ErtsAllocatorFunctions_t*)$etp_search_alloc_f->extra      end      if ($etp_search_alloc_f->alloc != erts_sys_alloc) && \         ($etp_search_alloc_f->alloc != erts_fix_alloc)        if ($etp_search_alloc_f->alloc == erts_alcu_alloc) || \           ($etp_search_alloc_f->alloc == erts_alcu_alloc_ts)          # alcu alloc          set $etp_search_alloc_e = (Allctr_t*)$etp_search_alloc_f->extra          # mbc_list          set $etp_search_alloc_p = $etp_search_alloc_e->mbc_list.first          set $etp_search_alloc_cnt = 0          while $etp_search_alloc_p && \                ($etp_search_alloc_cnt < $etp_max_depth)            set $etp_search_alloc_cnt++            if $etp_search_alloc_p <= ($arg0) && \               ($arg0) < (char*)$etp_search_alloc_p + \                         ($etp_search_alloc_p->chdr & (Uint)~7)              printf "erts_allctrs[%d] %% %salloc: mbc_list: %d\n", \                     $etp_search_alloc_i, $etp_search_alloc_e->name_prefix, \                     $etp_search_alloc_cnt            end            if $etp_search_alloc_p == $etp_search_alloc_e->mbc_list.last              if $etp_search_alloc_p->next                printf \                  "erts_allctrs[%d] %% %salloc: mbc_list.last error %p\n",\                  $etp_search_alloc_i, $etp_search_alloc_e->name_prefix,\                  $etp_search_alloc_p              end              set $etp_search_alloc_p = 0            else              set $etp_search_alloc_p = $etp_search_alloc_p->next            end          end          if $etp_search_alloc_p            printf "erts_allctrs[%d] %% %salloc: too large mbc_list %p\n", \                   $ept_search_alloc_i, $etp_search_alloc_e->name_prefix,                   $ept_search_alloc_p          end          # sbc_list          set $etp_search_alloc_p = $etp_search_alloc_e->sbc_list.first          set $etp_search_alloc_cnt = 0          while $etp_search_alloc_p && \                ($etp_search_alloc_cnt < $etp_max_depth)            set $etp_search_alloc_cnt++            if $etp_search_alloc_p <= ($arg0) && \               ($arg0) < (char*)$etp_search_alloc_p + \                         ($etp_search_alloc_p->chdr & (Uint)~7)              printf "erts_allctrs[%d] %% %salloc: sbc_list: %d\n", \                     $etp_search_alloc_i, $etp_search_alloc_e->name_prefix, \                     $etp_search_alloc_cnt            end            if $etp_search_alloc_p == $etp_search_alloc_e->sbc_list.last              if $etp_search_alloc_p->next                printf \                  "erts_allctrs[%d] %% %salloc: sbc_list.last error %p",\                  $etp_search_alloc_i, $etp_search_alloc_e->name_prefix,\                  $etp_search_alloc_p              end              set $etp_search_alloc_p = 0            else              set $etp_search_alloc_p = $etp_search_alloc_p->next            end          end          if $etp_search_alloc_p            printf "erts_allctrs[%d] %% %salloc: too large sbc_list %p\n", \                   $ept_search_alloc_i, $etp_search_alloc_e->name_prefix,                   $ept_search_alloc_p          end        else          printf "erts_allctrs[%d] %% %s: unknown allocator\n", \                 $etp_search_alloc_i, erts_alc_a2ad[$etp_search_alloc_i]        end      end    end    set $etp_search_alloc_i++  endenddocument etp-search-alloc%---------------------------------------------------------------------------% etp-search-heaps Eterm% % Search all internal allocator memory blocks for for the specified Eterm.%---------------------------------------------------------------------------enddefine etp-overlapped-heaps# Args: ## Non-reentrant#  printf "%% Dumping heap addresses to \"etp-commands.bin\"\n"  set $etp_overlapped_heaps_q = erts_max_processes / 10  set $etp_overlapped_heaps_r = erts_max_processes % 10  set $etp_overlapped_heaps_t = 10  set $etp_overlapped_heaps_m = $etp_overlapped_heaps_q  if $etp_overlapped_heaps_r > 0    set $etp_overlapped_heaps_m++    set $etp_overlapped_heaps_r--  end  set $etp_overlapped_heaps_i = 0  set $etp_overlapped_heaps_found = 0  dump binary value etp-commands.bin 'o'  append binary value etp-commands.bin 'v'  append binary value etp-commands.bin 'e'  append binary value etp-commands.bin 'r'  append binary value etp-commands.bin 'l'  append binary value etp-commands.bin 'a'  append binary value etp-commands.bin 'p'  append binary value etp-commands.bin 'p'  append binary value etp-commands.bin 'e'  append binary value etp-commands.bin 'd'  append binary value etp-commands.bin '-'  append binary value etp-commands.bin 'h'  append binary value etp-commands.bin 'e'  append binary value etp-commands.bin 'a'  append binary value etp-commands.bin 'p'  append binary value etp-commands.bin 's'  append binary value etp-commands.bin '\0'  while $etp_overlapped_heaps_i < erts_max_processes    if process_tab[$etp_overlapped_heaps_i]      append binary value etp-commands.bin \        (Eterm)$etp_overlapped_heaps_i      append binary value etp-commands.bin \        (Eterm)process_tab[$etp_overlapped_heaps_i]->heap      append binary value etp-commands.bin \        (Eterm)process_tab[$etp_overlapped_heaps_i]->hend      append binary value etp-commands.bin \        (Eterm)process_tab[$etp_overlapped_heaps_i]->old_heap      append binary value etp-commands.bin \        (Eterm)process_tab[$etp_overlapped_heaps_i]->old_hend      set $etp_overlapped_heaps_p = process_tab[$etp_overlapped_heaps_i]->mbuf      set $etp_overlapped_heaps_cnt = 0      while $etp_overlapped_heaps_p && \            ($etp_overlapped_heaps_cnt < $etp_max_depth)        set $etp_overlapped_heaps_cnt++        append binary value etp-commands.bin \          (Eterm)$etp_overlapped_heaps_p        append binary value etp-commands.bin \(Eterm)(&($etp_overlapped_heaps_p->mem)+$etp_overlapped_heaps_p->size)        set $etp_overlapped_heaps_p = $etp_overlapped_heaps_p->next      end      if $etp_overlapped_heaps_p        printf "process_tab[%d] %% Too many HeapFragments\n", \               $etp_overlapped_heaps_i      end      append binary value etp-commands.bin (Eterm)0x0      append binary value etp-commands.bin (Eterm)0x0    end    set $etp_overlapped_heaps_i++    if $etp_overlapped_heaps_i > $etp_overlapped_heaps_m      printf "%% %d%%...\n", $etp_overlapped_heaps_t      set $etp_overlapped_heaps_t += 10      set $etp_overlapped_heaps_m += $etp_overlapped_heaps_q      if $etp_overlapped_heaps_r > 0        set $etp_overlapped_heaps_m++        set $etp_overlapped_heaps_r--      end    end  end  etp-runenddocument etp-overlapped-heaps%---------------------------------------------------------------------------% etp-overlapped-heaps% % Dump all process heap addresses in process_tab[], including % the heap fragments in binary format on the file etp-commands.bin.% Then call etp_commands:file/1 to analyze if any heaps overlap.%% Requires 'erl' in the path and 'etp_commands.beam' in 'erl's search path.%---------------------------------------------------------------------------enddefine etp-chart# Args: Process*## Non-reentrant  etp-chart-start ($arg0)  set ($arg0) = ($arg0)  etp-msgq (($arg0)->msg)  etp-stackdump ($arg0)  etp-dictdump (($arg0)->dictionary)  etp-dictdump (($arg0)->debug_dictionary)  printf "%% Dumping other process data...\n"  etp ($arg0)->seq_trace_token  etp ($arg0)->fvalue  printf "%% Dumping done.\n"  etp-chart-printenddocument etp-chart%---------------------------------------------------------------------------% etp-chart Process*% % Dump all process data to the file "etp-commands.bin" and then use% the Erlang support module to print a memory chart of all terms.%---------------------------------------------------------------------------enddefine etp-chart-start# Args: Process*## Non-reentrant  set $etp_chart = 1  set $etp_chart_id = 0  set $etp_chart_start_p = ($arg0)  dump binary value etp-commands.bin 'c'  append binary value etp-commands.bin 'h'  append binary value etp-commands.bin 'a'  append binary value etp-commands.bin 'r'  append binary value etp-commands.bin 't'  append binary value etp-commands.bin '\0'  append binary value etp-commands.bin (Eterm)($etp_chart_start_p->heap)  append binary value etp-commands.bin (Eterm)($etp_chart_start_p->high_water)  append binary value etp-commands.bin (Eterm)($etp_chart_start_p->hend)  append binary value etp-commands.bin (Eterm)($etp_chart_start_p->old_heap)  append binary value etp-commands.bin (Eterm)($etp_chart_start_p->old_hend)  set $etp_chart_start_cnt = 0  set $etp_chart_start_p = $etp_chart_start_p->mbuf  while $etp_chart_start_p && ($etp_chart_start_cnt < $etp_max_depth)    set $etp_chart_start_cnt++    append binary value etp-commands.bin (Eterm)($etp_chart_start_p->mem)    append binary value etp-commands.bin (Eterm)($etp_chart_start_p->size)    set $etp_chart_start_p = $etp_chart_start_p->next  end  append binary value etp-commands.bin (Eterm)(0)  append binary value etp-commands.bin (Eterm)(0)  if $etp_chart_start_p    printf "%% Too many HeapFragments\n"  endenddocument etp-chart-start%---------------------------------------------------------------------------% etp-chart-start Process*% % Dump a chart head to the file "etp-commands.bin".%---------------------------------------------------------------------------enddefine etp-chart-entry-1# Args: Eterm, int depth, int words## Reentrant capable  if ($arg1) == 0    set $etp_chart_id++    printf "#%d:", $etp_chart_id  end  append binary value etp-commands.bin ($arg0)&~0x3  append binary value etp-commands.bin (Eterm)(($arg2)*sizeof(Eterm))  append binary value etp-commands.bin (Eterm)$etp_chart_id  append binary value etp-commands.bin (Eterm)($arg1)#   printf "<dumped %#x %lu %lu %lu>", ($arg0)&~0x3, \#     (Eterm)(($arg2)*sizeof(Eterm)), (Eterm)$etp_chart_id, (Eterm)($arg1)enddefine etp-chart-print  set $etp_chart = 0  etp-runenddocument etp-chart-print%---------------------------------------------------------------------------% etp-chart-print Process*% % Print a memory chart of the dumped data in "etp-commands.bin", and stop% chart recording.%---------------------------------------------------------------------------end############################################################################# ETS table debug#define etp-ets-tables# Args:## Non-reentrant  printf "%% Dumping < %lu ETS tables\n", (unsigned long)db_max_tabs  while $etp_ets_tables_i < db_max_tabs    if (db_tables[$etp_ets_tables_i].id != 0x18) && \       (db_tables[$etp_ets_tables_i].id != 0xd8)      printf "%% %d:", $etp_ets_tables_i      etp-1 ((Eterm)(db_tables[$etp_ets_tables_i].id)) 0      printf " "      etp-1 ((Eterm)(db_tables[$etp_ets_tables_i].t->common.owner)) 0      printf "\n"    end    set $etp_ets_tables_i++  end  set $etp_ets_table_i = 0enddocument etp-ets-tables%---------------------------------------------------------------------------% etp-ets-tables%% Dump all ETS table names and their indexies.%---------------------------------------------------------------------------enddefine etp-ets-tabledump# Args: int tableindex## Non-reentrant  printf "%% Dumping ETS table %d:", ($arg0)  set $etp_ets_tabledump_n = 0  set $etp_ets_tabledump_t = db_tables[($arg0)].t  set $etp_ets_tabledump_i = 0  etp-1 ($etp_ets_tabledump_t->common.the_name) 0  printf " status=%#x\n", $etp_ets_tabledump_t->common.status  if $etp_ets_tabledump_t->common.status & 0x130    # Hash table    set $etp_ets_tabledump_h = $etp_ets_tabledump_t->hash    printf "%% nitems=%d\n", $etp_ets_tabledump_h->nitems    while $etp_ets_tabledump_i < $etp_ets_tabledump_h->nactive      set $etp_ets_tabledump_l = $etp_ets_tabledump_h->seg \            [$etp_ets_tabledump_i>>8][$etp_ets_tabledump_i&0xFF]      if $etp_ets_tabledump_l        printf "%% Slot %d:\n", $etp_ets_tabledump_i        while $etp_ets_tabledump_l          if $etp_ets_tabledump_n            printf ","          else            printf "["          end          set $etp_ets_tabledump_n++          etp-1 ((Eterm)($etp_ets_tabledump_l->dbterm.tpl)|0x2) 0          if $etp_ets_tabledump_l->hvalue == ((unsigned long)-1)            printf "% *\n"          else            printf "\n"          end          set $etp_ets_tabledump_l = $etp_ets_tabledump_l->next          if $etp_ets_tabledump_n >= $etp_max_depth            set $etp_ets_tabledump_l = 0          end        end      end      set $etp_ets_tabledump_i++    end    if $etp_ets_tabledump_n      printf "].\n"    end  else    printf "%% Not a hash table\n"  endenddocument etp-ets-tabledump%---------------------------------------------------------------------------% etp-ets-tabledump Slot%% Dump an ETS table with a specified slot index.%---------------------------------------------------------------------------end############################################################################# Erlang support module handling#define etp-run  shell make -f "${ROOTDIR:?}/erts/etc/unix/etp_commands.mk" \    ROOTDIR="${ROOTDIR:?}" ETP_DATA="etp-commands.bin"enddocument etp-run%---------------------------------------------------------------------------% etp-run% % Make and run the Erlang support module on the input file % "erl-commands.bin". The environment variable ROOTDIR must% be set to find $ROOTDIR/erts/etc/unix/etp_commands.mk.%% Also, erl and erlc must be in the path.%---------------------------------------------------------------------------end############################################################################# Toolbox parameter handling#define etp-set-max-depth  if ($arg0) > 0    set $etp_max_depth = ($arg0)  else    echo %%%Error: max-depth <= 0 %%%\n  endenddocument etp-set-max-depth%---------------------------------------------------------------------------% etp-set-max-depth Depth% % Set the max term depth to use for etp. The term dept limit% works in both depth and width, so if you set the max depth to 10,% an 11 element flat tuple will be truncated.%---------------------------------------------------------------------------enddefine etp-set-max-string-length  if ($arg0) > 0    set $etp_max_string_length = ($arg0)  else    echo %%%Error: max-string-length <= 0 %%%\n  endenddocument etp-set-max-string-length%---------------------------------------------------------------------------% etp-set-max-strint-length Length% % Set the max string length to use for ept when printing lists% that can be shown as printable strings. Printable strings% that are longer will be truncated, and not even checked if% they really are printable all the way to the end.%---------------------------------------------------------------------------enddefine etp-show  printf "etp-set-max-depth %d\n", $etp_max_depth  printf "etp-set-max-string-length %d\n", $etp_max_string_lengthenddocument etp-show%---------------------------------------------------------------------------% etp-show% % Show the commands needed to set all etp parameters % to their current value.%---------------------------------------------------------------------------end############################################################################# Init#define etp-init  set $etp_arch64 = (sizeof(void *) == 8)  if $etp_arch64    set $etp_nil = 0xfffffffffffffffb  else    set $etp_nil = 0xfffffffb  end  set $etp_flat = 0  set $etp_chart_id = 0  set $etp_chart = 0  set $etp_max_depth = 20  set $etp_max_string_length = 100  set $etp_ets_tables_i = 0enddocument etp-init%---------------------------------------------------------------------------% Use etp-help for a command overview and general help.% % To use the Erlang support module, the environment variable ROOTDIR% must be set to the toplevel installation directory of Erlang/OTP,% so the etp-commands file becomes:%     $ROOTDIR/erts/etc/unix/etp-commands% Also, erl and erlc must be in the path.%---------------------------------------------------------------------------endetp-inithelp etp-initetp-show

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?