From ba98a81408cf01adee1ce919753fc8036de68ac2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Blizni=C4=8Denko?= Date: Mon, 11 Dec 2023 17:48:31 +0100 Subject: [PATCH] implemented Profile It command --- .../SpCodeDebugItCommand.class.st | 18 ----------- .../SpCodeProfileItCommand.class.st | 30 +++++++++++++++++-- .../SpCodeSelectionCommand.class.st | 18 +++++++++++ .../SpAbstractWidgetPresenter.class.st | 8 +++-- 4 files changed, 50 insertions(+), 24 deletions(-) diff --git a/src/Spec2-Code-Commands/SpCodeDebugItCommand.class.st b/src/Spec2-Code-Commands/SpCodeDebugItCommand.class.st index 3b27f095..f93d142f 100644 --- a/src/Spec2-Code-Commands/SpCodeDebugItCommand.class.st +++ b/src/Spec2-Code-Commands/SpCodeDebugItCommand.class.st @@ -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 [ diff --git a/src/Spec2-Code-Commands/SpCodeProfileItCommand.class.st b/src/Spec2-Code-Commands/SpCodeProfileItCommand.class.st index 9f12893b..67162b4f 100644 --- a/src/Spec2-Code-Commands/SpCodeProfileItCommand.class.st +++ b/src/Spec2-Code-Commands/SpCodeProfileItCommand.class.st @@ -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' } @@ -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 ] diff --git a/src/Spec2-Code-Commands/SpCodeSelectionCommand.class.st b/src/Spec2-Code-Commands/SpCodeSelectionCommand.class.st index e7e0b9c7..4df71c95 100644 --- a/src/Spec2-Code-Commands/SpCodeSelectionCommand.class.st +++ b/src/Spec2-Code-Commands/SpCodeSelectionCommand.class.st @@ -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 diff --git a/src/Spec2-Core/SpAbstractWidgetPresenter.class.st b/src/Spec2-Core/SpAbstractWidgetPresenter.class.st index 4d776bba..f41945e5 100644 --- a/src/Spec2-Core/SpAbstractWidgetPresenter.class.st +++ b/src/Spec2-Core/SpAbstractWidgetPresenter.class.st @@ -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 ]