Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Commit

Permalink
add tracing api (to trace executed callouts)
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanlm committed Oct 10, 2019
1 parent f7f0b0c commit 5678e96
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
37 changes: 37 additions & 0 deletions src/ThreadedFFI-UFFI/TFCalloutAPI.class.st
@@ -1,9 +1,31 @@
Class {
#name : #TFCalloutAPI,
#superclass : #FFICalloutAPI,
#classVars : [
'TraceBlock'
],
#category : #'ThreadedFFI-UFFI'
}

{ #category : #tracing }
TFCalloutAPI class >> activateTrace [

self activateTraceWith: [ :sender | sender crTrace ]
]

{ #category : #tracing }
TFCalloutAPI class >> activateTraceWith: aBlock [

TraceBlock := aBlock.
FFIMethodRegistry resetAll
]

{ #category : #tracing }
TFCalloutAPI class >> isTracing [

^ TraceBlock notNil
]

{ #category : #'instance creation' }
TFCalloutAPI class >> newCallbackBackendFor: aCallback [

Expand All @@ -14,6 +36,21 @@ TFCalloutAPI class >> newCallbackBackendFor: aCallback [
runner: aCallback ffiLibrary runner
]

{ #category : #tracing }
TFCalloutAPI class >> resetTrace [

TraceBlock := nil.
FFIMethodRegistry resetAll
]

{ #category : #tracing }
TFCalloutAPI class >> trace: sender [
"This method is not to be used directly, it is called by TFFI when #activateTrace was called."

TraceBlock ifNil: [ ^ self ].
TraceBlock value: sender
]

{ #category : #action }
TFCalloutAPI >> newBuilder [

Expand Down
19 changes: 13 additions & 6 deletions src/ThreadedFFI-UFFI/TFCalloutMethodBuilder.class.st
Expand Up @@ -20,17 +20,24 @@ TFCalloutMethodBuilder >> createFFICalloutLiteralFromSpec: functionSpec [
{ #category : #private }
TFCalloutMethodBuilder >> generateFFICallout: builder spec: functionSpec [
| properties |

"Copy the properties of the old method"
sender methodProperties
ifNotNil: [ properties := sender methodProperties copy.
properties method: nil.
builder properties: properties ].
sender methodProperties ifNotNil: [
properties := sender methodProperties copy.
properties method: nil.
builder properties: properties ].

builder
numArgs: self method argumentNames size;
addTemps: (self method argumentNames copyWith: #result).

"Builds a method call"

TFCalloutAPI isTracing ifTrue: [
TFCalloutAPI trace: sender.
builder
pushLiteral: TFCalloutAPI;
pushLiteral: sender;
send: #trace: ].

"Obtain the library to use"
builder
pushReceiver;
Expand Down

0 comments on commit 5678e96

Please sign in to comment.