Skip to content

Commit 78f66aa

Browse files
committed
Enhance memory usage tests with ShapeType configuration and add MemoryTestShape.xml
1 parent a355de8 commit 78f66aa

File tree

3 files changed

+67
-15
lines changed

3 files changed

+67
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ $env:PATH = "$(pwd)\rticonnextdds-connector\lib\win-x64;$env:PATH"
9292

9393
<types>
9494
<struct name="ShapeType">
95-
<member name="color" type="string" key="true"/>
95+
<member name="color" type="string" key="true" stringMaxLength="128"/>
9696
<member name="x" type="long"/>
9797
<member name="y" type="long"/>
9898
<member name="shapesize" type="long"/>

memory_usage_test.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package rti
33
import (
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
3139
func TestMemoryUsage(t *testing.T) {
3240
iterations := 1
@@ -105,23 +113,25 @@ func max(a, b int) int {
105113
}
106114

107115
func 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
136146
func 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()

test/xml/MemoryTestShape.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0"?>
2+
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="http://community.rti.com/schema/5.1.0/rti_dds_profiles.xsd" version="5.1.0">
4+
5+
<qos_library name="QosLibrary">
6+
<qos_profile name="DefaultProfile" base_name="BuiltinQosLibExp::Generic.StrictReliable" is_default_qos="true">
7+
<participant_qos>
8+
<discovery>
9+
<initial_peers>
10+
<element>shmem://</element>
11+
</initial_peers>
12+
<multicast_receive_addresses/>
13+
</discovery>
14+
</participant_qos>
15+
</qos_profile>
16+
</qos_library>
17+
18+
<types>
19+
<struct name="ShapeType">
20+
<member name="color" type="string" key="true" stringMaxLength="128"/>
21+
<member name="x" type="long"/>
22+
<member name="y" type="long"/>
23+
<member name="shapesize" type="long"/>
24+
</struct>
25+
</types>
26+
27+
<domain_library name="MyDomainLibrary">
28+
<domain name="MyDomain" domain_id="0">
29+
<register_type name="ShapeType" type_ref="ShapeType" kind="dynamicData"/>
30+
<topic name="Square" register_type_ref="ShapeType"/>
31+
</domain>
32+
</domain_library>
33+
34+
<participant_library name="MyParticipantLibrary">
35+
<domain_participant name="Zero" domain_ref="MyDomainLibrary::MyDomain">
36+
<publisher name="MyPublisher">
37+
<data_writer name="MySquareWriter" topic_ref="Square"/>
38+
</publisher>
39+
</domain_participant>
40+
</participant_library>
41+
</dds>

0 commit comments

Comments
 (0)