Skip to content

Commit

Permalink
implemented Profile It command
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBliznicenko committed Dec 11, 2023
1 parent 08b7e8d commit ba98a81
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
18 changes: 0 additions & 18 deletions src/Spec2-Code-Commands/SpCodeDebugItCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,6 @@ SpCodeDebugItCommand class >> defaultShortcutKey [
| $d shift control unix
]

{ #category : 'private' }
SpCodeDebugItCommand >> compile: aStream for: anObject in: evalContext [

| methodClass |
methodClass := evalContext
ifNil: [ anObject class ]
ifNotNil: [ evalContext methodClass ].

^ context class compiler
source: aStream;
class: methodClass;
context: evalContext;
requestor: context; "it should enable a visibility of current tool variables in new debugger"
isScripting: true;
failBlock: [ ^ nil ];
compile
]

{ #category : 'private' }
SpCodeDebugItCommand >> debug: aStream [

Expand Down
30 changes: 27 additions & 3 deletions src/Spec2-Code-Commands/SpCodeProfileItCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ I will evalute the selection (or line) of the playground using a profiler.
Class {
#name : 'SpCodeProfileItCommand',
#superclass : 'SpCodeSelectionCommand',
#category : 'Spec2-Code-Commands-TODO',
#category : 'Spec2-Code-Commands-Base',
#package : 'Spec2-Code-Commands',
#tag : 'TODO'
#tag : 'Base'
}

{ #category : 'defaults' }
Expand All @@ -25,5 +25,29 @@ SpCodeProfileItCommand class >> defaultName [
{ #category : 'execution' }
SpCodeProfileItCommand >> execute [

self flag: 'TODO'
| selection receiver evaluationContext stream compiledMethod |
selection := self selectedTextOrLine.
selection trimBoth ifEmpty: [ ^ self ].

receiver := self context doItReceiver.
evaluationContext := self context doItContext.

stream := selection readStream.
compiledMethod := self
compile: stream
for: receiver
in: evaluationContext.
compiledMethod ifNil: [ ^ self ].

ProfilerPresenter new
open;
spyOn: [
compiledMethod valueWithReceiver: receiver arguments: #( ) ]
asCode: selection
]

{ #category : 'constants' }
SpCodeProfileItCommand >> profilerPresenterClass [

^ ProfilerPresenter
]
18 changes: 18 additions & 0 deletions src/Spec2-Code-Commands/SpCodeSelectionCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ SpCodeSelectionCommand >> asSpecCommand [
^ SpToolCurrentApplicationCommand decorate: super asSpecCommand
]

{ #category : 'private' }
SpCodeSelectionCommand >> compile: aStream for: anObject in: evalContext [

| methodClass |
methodClass := evalContext
ifNil: [ anObject class ]
ifNotNil: [ evalContext methodClass ].

^ context class compiler
source: aStream;
class: methodClass;
context: evalContext;
requestor: context; "it should enable a visibility of current tool variables in new debugger"
isScripting: true;
failBlock: [ ^ nil ];
compile
]

{ #category : 'private' }
SpCodeSelectionCommand >> evaluate: aString andDo: aBlock [
"Treat the current selection as an expression; evaluate it and invoke
Expand Down
8 changes: 5 additions & 3 deletions src/Spec2-Core/SpAbstractWidgetPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ SpAbstractWidgetPresenter class >> addDocumentSectionFactoryMethod: aBuilder [

{ #category : 'documentation' }
SpAbstractWidgetPresenter class >> addDocumentSectionHierarchy: aBuilder [

aBuilder newLine.
aBuilder header: [ :builder | builder text: 'Hierarchy' ] withLevel: 2.
aBuilder
header: [ :builder | builder text: 'Hierarchy' ]
withLevel: 2.
SpDocumentHierarchyBuilder new
builder: aBuilder;
filter: [ :eachClass | eachClass package packageName beginsWith: 'Spec2-' ];
filter: [ :eachClass | eachClass package name beginsWith: 'Spec2-' ];
buildFor: self
]

Expand Down

0 comments on commit ba98a81

Please sign in to comment.