Skip to content

Commit adc9411

Browse files
Add test that checks ALS initial memory footprint
For eng/ide/ada_language_server#1596
1 parent c5cbc80 commit adc9411

File tree

7 files changed

+159
-0
lines changed

7 files changed

+159
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
with Ada.Text_IO;
2+
3+
procedure main is
4+
begin
5+
Ada.Text_IO.Put_Line ("Hello Ada World!");
6+
end main;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project p is
2+
end p;
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""
2+
Test that ALS initial memory footprint does not exceed a
3+
given amount of memory when runtime indexing is
4+
disabled.
5+
"""
6+
7+
from drivers.pylsp import (
8+
ALSLanguageClient,
9+
ALSClientServerConfig,
10+
test,
11+
get_ALS_memory_footprint,
12+
)
13+
import os
14+
15+
16+
async def check_memory_footprint(
17+
lsp: ALSLanguageClient,
18+
footprint_lower_bound,
19+
footprint_upper_bound,
20+
):
21+
"""
22+
This checks that the ALS memory footprint is within the given bounds.
23+
The bounds should be expresed in MB.
24+
"""
25+
# Send a didOpen for main.adb
26+
lsp.didOpenFile("main.adb")
27+
28+
# Wait for indexing
29+
await lsp.awaitIndexingEnd()
30+
31+
# Check the memory footprint in MB (psutil returns memory info in Bytes): verify
32+
# that the initial footprint is within expected bounds
33+
mem_footprint = get_ALS_memory_footprint()
34+
35+
assert footprint_lower_bound < mem_footprint < footprint_upper_bound, (
36+
f"Initial memory footprint should be between {footprint_lower_bound}MB "
37+
+ f"and {footprint_upper_bound}MB. Actual memory is: {mem_footprint}MB"
38+
)
39+
40+
41+
@test(
42+
config=ALSClientServerConfig(
43+
[
44+
os.environ.get("ALS", "ada_language_server"),
45+
"--tracefile",
46+
"./traces_with_runtime_indexing.cfg",
47+
]
48+
)
49+
)
50+
async def test_with_indexing(lsp: ALSLanguageClient) -> None:
51+
await check_memory_footprint(
52+
lsp, footprint_lower_bound=600, footprint_upper_bound=650
53+
)
54+
55+
56+
@test(
57+
config=ALSClientServerConfig(
58+
[
59+
os.environ.get("ALS", "ada_language_server"),
60+
"--tracefile",
61+
"./traces_without_runtime_indexing.cfg",
62+
]
63+
)
64+
)
65+
async def test_without_indexing(lsp: ALSLanguageClient) -> None:
66+
await check_memory_footprint(
67+
lsp, footprint_lower_bound=70, footprint_upper_bound=150
68+
)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# If the title is the same as the directory name, it can be ommited.
2+
driver: pylsp
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Custom traces file that enables runtime indexing
2+
# to check initial memory footprint.
3+
4+
>ada_ls_log.$T.$$.log:buffer_size=0:buffer_size=0
5+
6+
# Main trace
7+
ALS.MAIN=yes
8+
9+
# Full logs, helpful for debugging
10+
ALS.IN=yes
11+
ALS.OUT=yes
12+
13+
# Enable runtime indexing for this test
14+
ALS.RUNTIME_INDEXING=yes
15+
16+
# Testing should include incremental text changes
17+
#ALS.ALLOW_INCREMENTAL_TEXT_CHANGES=yes > inout.txt:buffer_size=0
18+
ALS.ALLOW_INCREMENTAL_TEXT_CHANGES=yes
19+
20+
# Activate navigation warnings in test mode
21+
ALS.NOTIFICATIONS_FOR_IMPRECISE_NAVIGATION=yes
22+
23+
# Disable advanced PP formatting of snippet for most tests
24+
ALS.COMPLETION.FORMATTING=no
25+
26+
# Disable logging in LSP formatting module
27+
ALS.FORMATTING=no
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Custom traces file that disables runtime indexing
2+
# to check initial memory footprint.
3+
4+
>ada_ls_log.$T.$$.log:buffer_size=0:buffer_size=0
5+
6+
# Main trace
7+
ALS.MAIN=yes
8+
9+
# Full logs, helpful for debugging
10+
ALS.IN=yes
11+
ALS.OUT=yes
12+
13+
# Disable runtime indexing for this test
14+
ALS.RUNTIME_INDEXING=no
15+
16+
# Testing should include incremental text changes
17+
#ALS.ALLOW_INCREMENTAL_TEXT_CHANGES=yes > inout.txt:buffer_size=0
18+
ALS.ALLOW_INCREMENTAL_TEXT_CHANGES=yes
19+
20+
# Activate navigation warnings in test mode
21+
ALS.NOTIFICATIONS_FOR_IMPRECISE_NAVIGATION=yes
22+
# Disable advanced PP formatting of snippet for most tests
23+
ALS.COMPLETION.FORMATTING=no
24+
25+
# Disable logging in LSP formatting module
26+
ALS.FORMATTING=no

testsuite/drivers/pylsp.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import logging
88
import os
9+
import psutil
910
import shlex
1011
import sys
1112
import urllib
@@ -845,6 +846,19 @@ def URI(src_path: Path | str) -> str:
845846
return src_uri
846847

847848

849+
def find_ALS_process():
850+
"""
851+
Return the ALS process launched by the pyslsp test driver.
852+
"""
853+
for x in psutil.pids():
854+
try:
855+
p = psutil.Process(x)
856+
if p.ppid() == os.getpid() and p.name().startswith("ada_language_server"):
857+
return p
858+
except psutil.NoSuchProcess:
859+
pass
860+
861+
848862
def assertEqual(actual: Any, expected: Any) -> None:
849863
"""Raise an AssertionError if actual != expected."""
850864
if actual != expected:
@@ -878,6 +892,20 @@ def to_str(item: tuple[str, int]):
878892
)
879893

880894

895+
def get_ALS_memory_footprint():
896+
"""
897+
Return the memory footprint in MB of the ALS process launched
898+
by the pyslsp test driver.
899+
"""
900+
for x in psutil.pids():
901+
try:
902+
p = psutil.Process(x)
903+
if p.ppid() == os.getpid() and p.name().startswith("ada_language_server"):
904+
return p.memory_full_info().rss / (1024**2)
905+
except psutil.NoSuchProcess:
906+
pass
907+
908+
881909
class TestInfraError(Exception):
882910

883911
def __init__(

0 commit comments

Comments
 (0)