h-stats-1.red 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %%% "SysLisp" part of the HEAP-STATS package.
  3. %%%
  4. %%% Author: Cris Perdue
  5. %%% December 1982
  6. %%% Documented January 1983
  7. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  8. on SysLisp;
  9. compiletime <<
  10. put('igetv,'assign!-op,'iputv);
  11. >>;
  12. %%% Magic constants defining the layout of a "heap-stats" object.
  13. compiletime <<
  14. Internal WConst TemplateX = 2,
  15. StringTabX = 3,
  16. StringSpaceX = 4,
  17. VectTabX = 5,
  18. VectSpaceX = 6,
  19. WordTabX = 7,
  20. WordSpaceX = 8,
  21. Pairs = 9,
  22. Strings = 10,
  23. HalfWords = 11,
  24. WordVecs = 12,
  25. Vectors = 13;
  26. >>;
  27. %%% This procedure sweeps the heap and collects statistics into
  28. %%% its argument, which is a heap-stats object. This routine may
  29. %%% be called as part of a garbage collection, so it may not do
  30. %%% any allocation whatsoever from the heap. Moderate size
  31. %%% integers are assumed to have in effect no tag.
  32. syslsp procedure HeapStats(Results);
  33. begin
  34. scalar CurrentItem,
  35. ObjLen,
  36. Last,
  37. HistoSize,
  38. StdTemplate,
  39. StringHTab,
  40. StringSpaceTab,
  41. VectHTab,
  42. VectSpaceTab,
  43. WordHTab,
  44. WordSpaceTab,
  45. Len;
  46. %% Check that the argument looks reasonable.
  47. if neq(isizev(Results), 13) then
  48. return nil;
  49. StdTemplate := igetv(Results,TemplateX);
  50. StringHTab := igetv(Results,StringTabX);
  51. StringSpaceTab := igetv(Results,StringSpaceX);
  52. VectHTab := igetv(Results,VectTabX);
  53. VectSpaceTab := igetv(Results,VectSpaceX);
  54. WordHTab := igetv(Results,WordTabX);
  55. WordSpaceTab := igetv(Results,WordSpaceX);
  56. %% Check the various subobjects of the argument to see that
  57. %% they look reasonable. The returns are all errors effectively.
  58. HistoSize := isizev(StdTemplate) + 1;
  59. if neq(isizev(StringHTab),HistoSize) then return 1;
  60. if neq(isizev(StringSpaceTab),HistoSize) then return 2;
  61. if neq(isizev(VectHTab),HistoSize) then return 3;
  62. if neq(isizev(VectSpaceTab),HistoSize) then return 4;
  63. if neq(isizev(WordHTab),HistoSize) then return 5;
  64. if neq(isizev(WordSpaceTab),HistoSize) then return 6;
  65. igetv(Results,Pairs) := 0;
  66. igetv(Results,Strings) := 0;
  67. igetv(Results,HalfWords) := 0;
  68. igetv(Results,WordVecs) := 0;
  69. igetv(Results,Vectors) := 0;
  70. FillVector(StringHTab,0);
  71. FillVector(StringSpaceTab,0);
  72. FillVector(VectHTab,0);
  73. FillVector(VectSpaceTab,0);
  74. FillVector(WordHTab,0);
  75. FillVector(WordSpaceTab,0);
  76. Last := HeapLast();
  77. CurrentItem := HeapLowerBound();
  78. while CurrentItem < Last do
  79. begin
  80. case Tag @CurrentItem of
  81. BTRTAG, CODE, NEGINT, POSINT, ID, UNBOUND,
  82. STR, BYTES, FIXN, FLTN, BIGN, WRDS, Halfwords, PAIR, VECT, EVECT:
  83. << ObjLen := 2; % must be first of pair
  84. igetv(Results,Pairs) := igetv(Results,Pairs) + 1;
  85. >>;
  86. HBYTES:
  87. << Len := StrLen CurrentItem;
  88. ObjLen := 1 + StrPack Len;
  89. igetv(Results,Strings) := igetv(Results,Strings) + 1;
  90. Histo(StdTemplate,StringHTab,Len+1,StringSpaceTab,ObjLen);
  91. >>;
  92. HHalfwords:
  93. << ObjLen := 1 + HalfWordPack HalfWordLen CurrentItem;
  94. igetv(Results,HalfWords) := igetv(Results,HalfWords) + 1;
  95. >>;
  96. HWRDS:
  97. << Len := WrdLen CurrentItem;
  98. ObjLen := 1 + WrdPack Len;
  99. igetv(Results,WordVecs) := igetv(Results,WordVecs) + 1;
  100. Histo(StdTemplate,WordHTab,Len+1,WordSpaceTab,ObjLen);
  101. >>;
  102. HVECT:
  103. << Len := VecLen CurrentItem;
  104. ObjLen := 1 + VectPack Len;
  105. igetv(Results,Vectors) := igetv(Results,Vectors) + 1;
  106. Histo(StdTemplate,VectHTab,Len+1,VectSpaceTab,ObjLen);
  107. >>;
  108. default:
  109. Error(0,"Illegal item in heap at %o", CurrentItem);
  110. end; % case
  111. CurrentItem := CurrentItem + ObjLen;
  112. end;
  113. Results;
  114. end;
  115. %%% Internal utility routine used by heapstats to accumulate
  116. %%% values into the statistics tables. The template is a
  117. %%% histogram template. The table is a histogram table. The
  118. %%% "value" is tallied into the appropriate bucket of the table
  119. %%% based on the template. Spacetab is similar to "table", but
  120. %%% the value of "space" will be added rather than tallied into
  121. %%% spacetab.
  122. Syslsp procedure Histo(Template,Table,Value,SpaceTab,Space);
  123. begin
  124. for i := 0 step 1 until isizev(Template) do
  125. if igetv(Template,i) >= Value then
  126. << igetv(Table,i) := igetv(Table,i) + 1;
  127. igetv(SpaceTab,i) := igetv(SpaceTab,i) + Space;
  128. return;
  129. >>;
  130. if Value > igetv(Template,isizev(Template)) then
  131. << igetv(Table,isizev(Template)+1)
  132. := igetv(Table,isizev(Template)+1) + 1;
  133. igetv(SpaceTab,isizev(Template)+1)
  134. := igetv(SpaceTab,isizev(Template)+1) + Space;
  135. >>;
  136. end;
  137. SysLsp procedure FillVector(v,k);
  138. for i := 0 step 1 until isizev(v) do
  139. igetv(v,i) := k;