@@ -3,6 +3,7 @@ package rti
33import (
44 "os"
55 "os/exec"
6+ "path"
67 "runtime"
78 "strconv"
89 "strings"
@@ -27,6 +28,13 @@ func getProcessMemory() (int64, error) {
2728 return rssKB * 1024 , nil // Convert KB to bytes
2829}
2930
31+ // newMemoryTestConnector creates a connector using ShapeType (like README example)
32+ func newMemoryTestConnector () (* Connector , error ) {
33+ _ , curPath , _ , _ := runtime .Caller (0 )
34+ xmlPath := path .Join (path .Dir (curPath ), "./test/xml/MemoryTestShape.xml" )
35+ return NewConnector ("MyParticipantLibrary::Zero" , xmlPath )
36+ }
37+
3038// TestMemoryUsage tests RTI Connector with comprehensive memory profiling
3139func TestMemoryUsage (t * testing.T ) {
3240 iterations := 1
@@ -105,23 +113,25 @@ func max(a, b int) int {
105113}
106114
107115func runConnectorExample (t * testing.T , iteration int ) {
108- // Use existing test configuration for reliability
109- connector , err := newTestConnector ()
116+ // Use ShapeType configuration like in the main README example
117+ // This provides realistic memory usage measurements for the documented API
118+ connector , err := newMemoryTestConnector ()
110119 if err != nil {
111120 t .Fatalf ("Iteration %d: Failed to create connector: %v" , iteration , err )
112121 }
113122 defer connector .Delete ()
114123
115- // Get output (writer) and publish test data
116- output , err := newTestOutput ( connector )
124+ // Get output (writer) and publish shape data
125+ output , err := connector . GetOutput ( "MyPublisher::MySquareWriter" )
117126 if err != nil {
118127 t .Fatalf ("Iteration %d: Failed to get output: %v" , iteration , err )
119128 }
120129
121- // Publish test data using existing TestType
122- output .Instance .SetString ("st" , "MemoryTest" )
123- output .Instance .SetInt32 ("l" , int32 (iteration * 10 ))
124- output .Instance .SetFloat32 ("f" , float32 (iteration )+ 0.5 )
130+ // Publish shape data (same as README example)
131+ output .Instance .SetString ("color" , "BLUE" )
132+ output .Instance .SetInt ("x" , iteration * 10 )
133+ output .Instance .SetInt ("y" , iteration * 20 )
134+ output .Instance .SetInt ("shapesize" , 30 )
125135 err = output .Write ()
126136 if err != nil {
127137 t .Fatalf ("Iteration %d: Failed to write: %v" , iteration , err )
@@ -132,24 +142,25 @@ func runConnectorExample(t *testing.T, iteration int) {
132142 }
133143}
134144
135- // BenchmarkConnectorMemory provides benchmark-based memory analysis
145+ // BenchmarkConnectorMemory provides benchmark-based memory analysis using ShapeType
136146func BenchmarkConnectorMemory (b * testing.B ) {
137147 b .ResetTimer ()
138148 for i := 0 ; i < b .N ; i ++ {
139- connector , err := newTestConnector ()
149+ connector , err := newMemoryTestConnector ()
140150 if err != nil {
141151 b .Fatalf ("Failed to create connector: %v" , err )
142152 }
143153
144- output , err := newTestOutput ( connector )
154+ output , err := connector . GetOutput ( "MyPublisher::MySquareWriter" )
145155 if err != nil {
146156 connector .Delete ()
147157 b .Fatalf ("Failed to get output: %v" , err )
148158 }
149159
150- output .Instance .SetString ("st" , "BenchmarkTest" )
151- output .Instance .SetInt32 ("l" , int32 (i * 10 ))
152- output .Instance .SetFloat32 ("f" , float32 (i )+ 0.5 )
160+ output .Instance .SetString ("color" , "BLUE" )
161+ output .Instance .SetInt ("x" , i * 10 )
162+ output .Instance .SetInt ("y" , i * 20 )
163+ output .Instance .SetInt ("shapesize" , 30 )
153164 output .Write ()
154165
155166 connector .Delete ()
0 commit comments