Skip to content

Commit

Permalink
Added support of pretty print of image process list
Browse files Browse the repository at this point in the history
- Introduced new PhLImageProcess to store data about image process
- fixes #616
  • Loading branch information
Bajger committed May 18, 2023
1 parent 4cbcd96 commit 7129e8a
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 14 deletions.
51 changes: 37 additions & 14 deletions src/PharoLauncher-CLI/PhLImageProcessListCliCommand.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ Class {
#category : #'PharoLauncher-CLI-Commands'
}

{ #category : #'command line - arguments' }
PhLImageProcessListCliCommand class >> addLauncherFlagsTo: aCommandSpec [

self addPrintFlagsTo: aCommandSpec.
]

{ #category : #'command line' }
PhLImageProcessListCliCommand class >> asCliCommand [
^ self newLauncherCommandSpec: #processList
Expand All @@ -20,29 +26,46 @@ PhLImageProcessListCliCommand class >> launcherCmdDescription [

{ #category : #'command execution' }
PhLImageProcessListCliCommand >> basicExecute [

"TODO rewrite this to more meaningful output with columns like PID, datetime started, vm name, image name"
|processList|
"TODO: Win Powershell version should be something like this: Get-Process | Where-Object { $_.Path -like '*Pharo*' -and $_.Path -like '*.image*' -and $_.Id -ne 2232 } | Select-Object Id, Path, StartTime, CommandLine"
self checkOS.
self outStream
nextPutAll: self executeOSShellCommand.
^ self context exitSuccess
processList := self imageProcesListFrom: self executeOSShellCommand.
self list: processList
]

{ #category : #'command execution' }
PhLImageProcessListCliCommand >> execute [
PhLImageProcessListCliCommand >> imageProcesListFrom: shellOutput [

"TODO rewrite this to more meaningful output with columns like PID, datetime started, vm name, image name"
"TODO: Win Powershell version should be something like this: Get-Process | Where-Object { $_.Path -like '*Pharo*' -and $_.Path -like '*.image*' -and $_.Id -ne 2232 } | Select-Object Id, Path, StartTime, CommandLine"
self checkOS.
self outStream
nextPutAll: self executeOSShellCommand.
^ self context exitSuccess
^ (shellOutput substrings: OSPlatform current lineEnding) collect: [:line |
PhLImageProcess newFrom: (line splitOn: '-|-')
]
]

{ #category : #private }
PhLImageProcessListCliCommand >> modelClass [

^ self class environment at: #PhLImageProcess
]

{ #category : #'command execution' }
PhLImageProcessListCliCommand >> osShellArgArray [
PhLImageProcessListCliCommand >> osShellArgArray [

^ Array with: 'echo' with: '-n' with: ('$(pgrep -a -f Pharo | grep ''.image'' | grep -v ''.bash''| grep -v {1})' format: {self currentVMPid asString})
^ Array with: self processListCmdArgs
]

{ #category : #'command execution' }
PhLImageProcessListCliCommand >> processListCmdArgs [

^ String streamContents: [:aStream |
aStream
nextPutAll: 'pgrep -a -f Pharo | grep ''.image'' | grep -v ''.bash'' | grep -v ';
nextPutAll: self currentVMPid asString;
nextPutAll: ' | while read -r line; do'; lf;
nextPutAll: ' pid=$(echo "$line" | awk ''{print $1}'')'; lf;
nextPutAll: ' vmPath=$(echo "$line" | awk ''{print $2}'')'; lf;
nextPutAll: ' imgPath=$(echo "$line" | awk ''{print $3}'')'; lf;
nextPutAll: ' start_time=$(ps -o lstart= -p "$pid")'; lf;
nextPutAll: ' echo "$pid-|-$vmPath-|-$imgPath-|-$start_time"'; lf;
nextPutAll: 'done'
]
]
100 changes: 100 additions & 0 deletions src/PharoLauncher-Core/PhLImageProcess.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"
I represent running Pharo image process. I have a known PID of running Pharo image process, image name, vm path, image Path start datetime of process. I am used mainly for pretty printing to user output.
"
Class {
#name : #PhLImageProcess,
#superclass : #PhLObject,
#instVars : [
'pid',
'vmPath',
'imagePath',
'startDateTime'
],
#category : #'PharoLauncher-Core-Model'
}

{ #category : #private }
PhLImageProcess class >> listPrintAttributeBlocks [

^ {[:imgProcess | imgProcess pid asString]. [:imgProcess | imgProcess imageName]. [:imgProcess | imgProcess vmPath]. [:imgProcess | imgProcess imagePath]. [:imgProcess | imgProcess startDateTime ].}

]

{ #category : #private }
PhLImageProcess class >> listPrintAttributeLabels [

^ #('PID' 'Image name' 'VM path' 'Image path' 'Date/Time started')
]

{ #category : #'instance creation' }
PhLImageProcess class >> newFrom: osOutputLine [

"initialize image process instance from line represented by OS command output line"
^ self new initializeFrom: osOutputLine; yourself

]

{ #category : #accessing }
PhLImageProcess >> imageName [


self imagePath ifEmpty: [ ^ '' ].
^ (self imagePath copyAfterLast: FileSystem disk delimiter) copyUpTo: $.
]

{ #category : #accessing }
PhLImageProcess >> imagePath [

^ imagePath
]

{ #category : #accessing }
PhLImageProcess >> imagePath: anObject [

imagePath := anObject
]

{ #category : #initialization }
PhLImageProcess >> initializeFrom: processLineArray [

self pid: processLineArray first.
self vmPath: processLineArray second.
self imagePath: processLineArray third.
self startDateTime: processLineArray fourth.
]

{ #category : #accessing }
PhLImageProcess >> pid [

^ pid
]

{ #category : #accessing }
PhLImageProcess >> pid: anObject [

pid := anObject
]

{ #category : #accessing }
PhLImageProcess >> startDateTime [

^ startDateTime
]

{ #category : #accessing }
PhLImageProcess >> startDateTime: anObject [

startDateTime := anObject
]

{ #category : #accessing }
PhLImageProcess >> vmPath [

^ vmPath
]

{ #category : #accessing }
PhLImageProcess >> vmPath: anObject [

vmPath := anObject
]

0 comments on commit 7129e8a

Please sign in to comment.