/
VMProfilerSymbolsManager.class.st
205 lines (174 loc) · 7.04 KB
/
VMProfilerSymbolsManager.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
Class {
#name : #VMProfilerSymbolsManager,
#superclass : #Object,
#instVars : [
'modules',
'symbolsByModule',
'modulesByName',
'vmModule',
'cogModule'
],
#classVars : [
'CompatibilityClass'
],
#category : #'CogTools-VMProfiler'
}
{ #category : #LICENSE }
VMProfilerSymbolsManager class >> LICENSE [
^'Project Squeak
Copyright (c) 2005-2013, 3D Immersive Collaboration Consulting, LLC., All Rights Reserved
Redistributions in source code form must reproduce the above copyright and this condition.
Licensed under MIT License (MIT)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.'
]
{ #category : #'as yet unclassified' }
VMProfilerSymbolsManager class >> initialize [
"Add to the shut down list to delete the temp directory and contents."
Smalltalk addToShutDownList: self
]
{ #category : #'as yet unclassified' }
VMProfilerSymbolsManager class >> tempDirectory [
^ CompatibilityClass ifNotNil: [CompatibilityClass nameFordirPath:'/tmp/vmsyms' plus:OSProcess thisOSProcess pid printString]
]
{ #category : #'as yet unclassified' }
VMProfilerSymbolsManager class >> using: aCompatibilityClass [
CompatibilityClass := aCompatibilityClass.
^ self new
]
{ #category : #'Cog compiled code' }
VMProfilerSymbolsManager >> addCogModuleSymbols: symbols [
self initialized ifFalse:
[Cursor wait showWhile:
[[self initialized] whileFalse:
[(Delay forMilliseconds: 100) wait]]].
modules
removeAllSuchThat: [:existingModule| cogModule name = existingModule name];
add: cogModule.
modulesByName at: cogModule name put: cogModule.
symbolsByModule at: cogModule put: symbols
]
{ #category : #'Constituents naming' }
VMProfilerSymbolsManager >> analyzeClosedPIC: aClosedPIC [
^ Dictionary new
at: 'selector' put: aClosedPIC first;
at: 'nbOfCases' put: aClosedPIC size -1;
at: 'listOfCases' put: ((2 to: aClosedPIC size by: 2) collect:
[ :i |
(aClosedPIC at: i) -> ((aClosedPIC at: i+1) isCompiledCode "MNU PIC Case"
ifTrue: [(aClosedPIC at: i+1) methodClass name]
ifFalse: [aClosedPIC at: i+1])]);
yourself
]
{ #category : #accessing }
VMProfilerSymbolsManager >> cogModule [
^cogModule
]
{ #category : #'Cog compiled code' }
VMProfilerSymbolsManager >> computeCogCodeModule: cogCodeConstituents [
| symbols |
(cogModule := VMPExecutableModuleSymbol new)
name: vmModule shortName, '.', cogCodeConstituents first;
shortName: cogCodeConstituents first;
vmshift: 0;
address: cogCodeConstituents second;
size: cogCodeConstituents last - cogCodeConstituents second.
symbols := (3 to: cogCodeConstituents size - 2 by: 2) collect:
[:i| "Declare methods as public; PICs and entries as private"
| thing |
((thing := cogCodeConstituents at: i) isCompiledMethod
ifTrue: [VMPPublicFunctionSymbol]
ifFalse: [VMPPrivateFunctionSymbol]) new
name: (self nameOf: thing cogCodeModule: cogCodeConstituents);
address: (self extractAddress: (cogCodeConstituents at: i + 1));
cm: thing ;
mcpcbcpcmap: (cogCodeConstituents at: i + 1);
limit: (self extractAddress: (cogCodeConstituents at: i + 3 ifAbsent: [cogCodeConstituents last]))].
self addCogModuleSymbols: symbols
]
{ #category : #'Cog compiled code' }
VMProfilerSymbolsManager >> extractAddress: thing [
^ thing isArray ifTrue: [ thing first ] ifFalse: [ thing ]
]
{ #category : #'Constituents naming' }
VMProfilerSymbolsManager >> getClosedPICLabel: aThing [
"return a label for the considered closed PIC, listing its selector, its total number of cases, and the concrete classes present in the PIC. The duplicates (if any) among these classes have been deleted in #analyzeClosedPIC: "
|list|
list := String streamContents: [ :s |(aThing at: 'listOfCases') asStringOn: s delimiter: ', '].
^ String streamContents: [ :s | s nextPutAll: 'cPIC ', (aThing at: 'selector'), ' - ', (aThing at: 'nbOfCases') asString, ' (', list, ')' ]
]
{ #category : #'initialize-release' }
VMProfilerSymbolsManager >> initialize [
"Initialize the receiver, parsing the symbols in the background for faster startup."
self initializeMost.
self parseAsynchronously
]
{ #category : #accessing }
VMProfilerSymbolsManager >> moduleFor: aSymbol [
^modules
detect: [:module|
module address <= aSymbol address
and: [module limit >= aSymbol limit]]
ifNone: []
]
{ #category : #accessing }
VMProfilerSymbolsManager >> moduleForAddress: address [
^modules
detect: [:module|
module address <= address
and: [module limit >= address]]
ifNone: []
]
{ #category : #accessing }
VMProfilerSymbolsManager >> modules [
^modules
]
{ #category : #'Constituents naming' }
VMProfilerSymbolsManager >> nameOf: thing cogCodeModule: cogCodeConstituents [
thing isCompiledMethod ifTrue: [ ^ thing methodClass name , '>>' , thing selector ].
thing class == cogCodeConstituents first class ifTrue: [ ^thing ].
^ thing isArray
ifTrue: [self getClosedPICLabel: (self analyzeClosedPIC: thing)]
ifFalse: ['OpenPIC ',(thing isString
ifTrue: [ thing ]
ifFalse: [ thing printString ])]
]
{ #category : #accessing }
VMProfilerSymbolsManager >> symbolsInModule: aModule [
^symbolsByModule at: aModule ifAbsent: [#()]
]
{ #category : #accessing }
VMProfilerSymbolsManager >> symbolsSelect: aBlock [
| size stream |
size := symbolsByModule inject: 0 into: [:sum :symbols| sum + symbols size].
stream := (Array new: size) writeStream.
modules do:
[:module|
(aBlock value: module) ifTrue:
[stream nextPut: module].
(symbolsByModule at: module ifAbsent: [#()]) do:
[:sym|
(aBlock value: sym) ifTrue:
[stream nextPut: sym]]].
^stream contents
]
{ #category : #accessing }
VMProfilerSymbolsManager >> symbolsWithTypes: aSet [
| size stream |
(aSet size = 1 and: [aSet anyOne == #module]) ifTrue:
[^modules].
size := symbolsByModule inject: 0 into: [:sum :symbols| sum + symbols size].
stream := (Array new: size) writeStream.
modules do:
[:module|
(symbolsByModule at: module ifAbsent: [#()]) do:
[:sym|
(aSet includes: sym type) ifTrue:
[stream nextPut: sym]]].
^stream contents
]
{ #category : #accessing }
VMProfilerSymbolsManager >> vmModule [
^vmModule
]