-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGtPyImportTimePackage.class.st
More file actions
149 lines (133 loc) · 3.62 KB
/
GtPyImportTimePackage.class.st
File metadata and controls
149 lines (133 loc) · 3.62 KB
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
"
This is a class that's useful for handling outputs of instructions like
```shell
python -X importtime -m xyz
```
"
Class {
#name : #GtPyImportTimePackage,
#superclass : #Object,
#instVars : [
'localTime',
'cumulativeTime',
'nesting',
'name',
'children'
],
#category : #GToolkit4Python
}
{ #category : #'as yet unclassified' }
GtPyImportTimePackage class >> fromString: aString [
"aString looks like
import time: self [us] | cumulative | imported package
import time: 77 | 77 | _io
import time: 19 | 19 | marshal
import time: 131 | 131 | posix
import time: 363 | 590 | _frozen_importlib_external
import time: 450 | 450 | time
..."
| root stack lines |
lines := aString lines allButFirst reversed
select: [ :each | each beginsWith: 'import time' ].
root := GtPyImportTimePackage new
localTime: 0;
cumulativeTime: -1;
nesting: -1;
name: 'Root'.
stack := Stack new.
stack push: root.
lines
do: [ :each |
| newPackage |
newPackage := self lineParser parse: each.
[ newPackage nesting <= stack top nesting ] whileTrue: [ stack pop ].
stack top addChild: newPackage.
stack push: newPackage ].
^ root
]
{ #category : #'as yet unclassified' }
GtPyImportTimePackage class >> lineParser [
^ ('import time:' asPParser trim , #digit asPParser plus flatten trim
, '|' asPParser trim , #digit asPParser plus flatten trim , '|' asPParser
, #space asPParser , #space asPParser star
, #endOfInput asPParser negate plus flatten)
==> [ :t |
GtPyImportTimePackage new
localTime: (t at: 2) asNumber;
cumulativeTime: (t at: 4) asNumber;
nesting: (t at: 7) size / 2;
name: (t at: 8) ]
]
{ #category : #'as yet unclassified' }
GtPyImportTimePackage >> addChild: aPyImportTimePackage [
children add: aPyImportTimePackage
]
{ #category : #'as yet unclassified' }
GtPyImportTimePackage >> children [
^ children
]
{ #category : #'as yet unclassified' }
GtPyImportTimePackage >> cumulativeTime [
cumulativeTime < 0 ifTrue: [ cumulativeTime := self children sumNumbers: #cumulativeTime ].
^ cumulativeTime
]
{ #category : #accessing }
GtPyImportTimePackage >> cumulativeTime: aTime [
cumulativeTime := aTime
]
{ #category : #'as yet unclassified' }
GtPyImportTimePackage >> gtChildrenFor: aView [
<gtView>
| normalizer |
children ifNil: [ ^ aView empty ].
normalizer := BrColorLinearNormalizer
inContext: (self withDeepCollect: #children)
withCommand: #cumulativeTime
lowColor: Color veryVeryLightGray
highColor: (Color
r: 216
g: 55
b: 62
range: 255).
^ aView columnedTree
title: 'Children';
items: [ {self} ];
expandOneLevel;
children: [ :each | each children ];
column: 'Value' text: [ :each | each name ];
column: 'Local time' text: [ :each | each localTime ];
column: 'Cumulative time'
textDo: [ :aColumn |
aColumn
format: [ :each | each cumulativeTime ];
background: [ :each | normalizer value: each ] ]
]
{ #category : #'as yet unclassified' }
GtPyImportTimePackage >> initialize [
super initialize.
children := OrderedCollection new.
]
{ #category : #'as yet unclassified' }
GtPyImportTimePackage >> localTime [
^ localTime
]
{ #category : #accessing }
GtPyImportTimePackage >> localTime: aTime [
localTime := aTime
]
{ #category : #'as yet unclassified' }
GtPyImportTimePackage >> name [
^ name
]
{ #category : #accessing }
GtPyImportTimePackage >> name: aString [
name := aString
]
{ #category : #'as yet unclassified' }
GtPyImportTimePackage >> nesting [
^ nesting
]
{ #category : #accessing }
GtPyImportTimePackage >> nesting: anInteger [
nesting := anInteger
]