Skip to content

Conversation

mikeprosserni
Copy link
Contributor

@mikeprosserni mikeprosserni commented Oct 16, 2025

What does this Pull Request accomplish?

  • Added ReadAnalogWaveforms method to the NiDAQmxService.
  • Updated code generation with support for CustomCodeNoLibrary. This is needed for ReadAnalogWaveforms because it doesn't have a matching library function. (Instead, it calls library_->InternalReadAnalogWaveformPerChan(), which has very different parameters)
  • Introduced new waveform attributes and functions in metadata.
  • Updated CMake build process to include new waveform protobuf files.
  • Added Ninja build instructions to CONTRIBUTING.md.

Why should this Pull Request be merged?

AB#3424627

What testing has been done?

PS C:\dev\fireserp\grpc-device> .\build\Debug\SystemTestsRunner.exe --gtest_filter="*ReadAnalogWaveforms*"                                                             
Note: Google Test filter = *ReadAnalogWaveforms*
[==========] Running 4 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 4 tests from NiDAQmxDriverApiTests
[ RUN      ] NiDAQmxDriverApiTests.ReadAnalogWaveforms_WithNoAttributeMode_ReturnsWaveformData
[       OK ] NiDAQmxDriverApiTests.ReadAnalogWaveforms_WithNoAttributeMode_ReturnsWaveformData (4493 ms)
[ RUN      ] NiDAQmxDriverApiTests.ReadAnalogWaveforms_WithTimingMode_ReturnsWaveformDataWithTimingInfo
[       OK ] NiDAQmxDriverApiTests.ReadAnalogWaveforms_WithTimingMode_ReturnsWaveformDataWithTimingInfo (128 ms)
[ RUN      ] NiDAQmxDriverApiTests.ReadAnalogWaveforms_WithExtendedPropertiesMode_ReturnsWaveformDataWithAttributes
[       OK ] NiDAQmxDriverApiTests.ReadAnalogWaveforms_WithExtendedPropertiesMode_ReturnsWaveformDataWithAttributes (15 ms)
[ RUN      ] NiDAQmxDriverApiTests.ReadAnalogWaveforms_WithTimingAndExtendedPropertiesMode_ReturnsWaveformDataWithTimingAndAttributes
[       OK ] NiDAQmxDriverApiTests.ReadAnalogWaveforms_WithTimingAndExtendedPropertiesMode_ReturnsWaveformDataWithTimingAndAttributes (81 ms)
[----------] 4 tests from NiDAQmxDriverApiTests (4746 ms total)

[----------] Global test environment tear-down
[==========] 4 tests from 1 test suite ran. (4754 ms total)
[  PASSED  ] 4 tests.

Mike Prosser added 5 commits October 16, 2025 13:32
- Added ReadAnalogWaveforms method stub to NiDAQmxService for reading analog waveforms.
- Updated metadata validation to include CustomCodeNoLibrary.
- Introduced new waveform attributes and functions in metadata.
- Enhanced CMake configuration for new protobuf files.
- Improved CONTRIBUTING.md with Ninja build instructions.
@mikeprosserni mikeprosserni changed the title [Under Construction] Add ReadAnalogWaveforms to NiDAQmxService Add ReadAnalogWaveforms to NiDAQmxService Oct 16, 2025
@mikeprosserni mikeprosserni marked this pull request as ready for review October 20, 2025 17:07
glibc_version: "2_31",
cmake_generator: '-G "Ninja"',
build_type: RelWithDebInfo
build_type: RelWithDebInfo,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made these build config changes in order to get nidaqmx_library.cpp to successfully compile on Ubuntu. As far as I can tell, the problem is that after I added the new library functions in functions.py, the nidaqmx_library.cpp became too large to compile with the original settings. It was either timing out or running out of memory or something.

I'm not sure this is the best way to fix the issue, however. Changing the optimization from O2 to O1 means the grpc device server will be less optimized for everyone on linux, right? Another approach that might work is splitting nidaqmx_library.cpp into multiple smaller .cpp files somehow. What do the reviewers think of that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you build it locally, does it print any more output, such as

note: variable tracking size limit exceeded with -fvar-tracking-assignments, retrying without

In the past I've sometimes had to use -fno-var-tracking-assignments to compile large code-generated files. I don't know if this option is still relevant or there is a different option nowadays.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, how long does it take to build locally with -O2? Does it eventually succeed?

Copy link
Contributor Author

@mikeprosserni mikeprosserni Oct 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a linux machine to build locally on, I've been relying on the CI build for this. All I can see is this, after 33 minutes:

[2601/3669] Building CXX object CMakeFiles/IntegrationTestsRunner.dir/generated/nidaqmx/nidaqmx_library.cpp.o
ninja: build stopped: interrupted by user.
Error: Process completed with exit code 143.

https://github.com/ni/grpc-device/actions/runs/18659129011/job/53195445860

or, when I added --verbose:

[2601/3669] /usr/bin/g++-9 -DCARES_STATICLIB -DTEST_API_BUILDING -DTestApi -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS -Iproto -I.././generated -I.././imports/include -I.././source -I.././third_party/grpc-sideband/src -I.././third_party/grpc-sideband/moniker_src -I../third_party/grpc/include -I../third_party/grpc/third_party/abseil-cpp -I../third_party/grpc/third_party/re2 -Igrpc/third_party/cares/cares -I../third_party/grpc/third_party/cares/cares -I../third_party/grpc/third_party/cares/cares/include -I../third_party/grpc/third_party/boringssl-with-bazel/src/include -I../third_party/grpc/third_party/protobuf/src -I../third_party/utfcpp/source -I../third_party/grpc-sideband/src -I../third_party/grpc-sideband/moniker_src -I../third_party/json/include -isystem ../third_party/googletest/googlemock/include -isystem ../third_party/googletest/googlemock -isystem ../third_party/googletest/googletest/include -isystem ../third_party/googletest/googletest -O2 -g -DNDEBUG -std=c++17 -MD -MT CMakeFiles/IntegrationTestsRunner.dir/generated/nidaqmx/nidaqmx_library.cpp.o -MF CMakeFiles/IntegrationTestsRunner.dir/generated/nidaqmx/nidaqmx_library.cpp.o.d -o CMakeFiles/IntegrationTestsRunner.dir/generated/nidaqmx/nidaqmx_library.cpp.o -c ../generated/nidaqmx/nidaqmx_library.cpp
ninja: build stopped: interrupted by user.
Error: Process completed with exit code 143.

https://github.com/ni/grpc-device/actions/runs/18663525332/job/53209586512

I did some googling and some guessing, and figured resource exhaustion was the most likely explanation for exit code 143. So I changed the build parameters to see if that would get the CI to build successfully, and it did. That's all I know at this point.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VTA is a potential cause of resource exhaustion. This feature tracks variable locations for each line of code in order to produce debug info that accurately shows the variable values when you step through the function, even if it's inlined. However, when your code has hundreds of variable assignments in the same function, this feature can take a lot of CPU and memory. I don't know exactly why.

VTA only affects the debugging experience, not execution speed, so if turning it off solves your problem, then it's a better solution than using -O1 and turning off a bunch of optimizations.

Please try updating https://github.com/ni/grpc-device/blob/main/source/codegen/templates/service.cpp.mako to use #pragma GCC optimize to scope the -fno-var-tracking-assignments or -O1 to *_library.cpp. You will need to guard this pragma with #ifdef __GNUC__ or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this PR, I've reverted the changes to build_cmake and implemented your suggested changes to service.cpp.mako, and nidaqmx_library.cpp is still compiling without crashing.

As another data point, I tried a different strategy in a different PR, where I reverted the other changes in build_cmake, and just used -j ${{ runner.os == 'Linux' && '2' || steps.cpu-cores.outputs.count }}, which also allwed nidaqmx_library.cpp to compile without crashing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked out your branch on my laptop, commented out the -fno-var-tracking-assignments, and ran time cmake --build . -j 16 --config RelWithDebInfo on WSL:

real    21m28.891s
user    298m4.721s
sys     30m30.097s

Running .ninja_log through https://github.com/nico/ninjatracing shows

image

It seems like all of the DAQmx files are problem files, taking >3 minutes to compile.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, which file is causing the problem? service.cpp or library.cpp? I thought you said it was library.cpp.

Copy link
Contributor Author

@mikeprosserni mikeprosserni Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nidaqmx_library.cpp was the problem. Although the changes made in service.cpp.mako seems to have fixed it: https://github.com/ni/grpc-device/actions/runs/18724889717/job/53406944072?pr=1203

[2600/3669] Building CXX object CMakeFiles/IntegrationTestsRunner.dir/proto/data_moniker.grpc.pb.cc.o
[2601/3669] Building CXX object CMakeFiles/IntegrationTestsRunner.dir/generated/nidaqmx/nidaqmx_library.cpp.o
[2602/3669] Building CXX object CMakeFiles/IntegrationTestsRunner.dir/generated/nidaqmx/nidaqmx_service_registrar.cpp.o

Copy link
Contributor Author

@mikeprosserni mikeprosserni Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my other PR, I'm trying out those changes in library.cpp.mako instead of service.cpp.mako: https://github.com/ni/grpc-device/pull/1205/files#diff-0cb12eeb765640c93fc98cdc6777d834a23c8042f953a4e41186bc87b72fa252

https://github.com/ni/grpc-device/actions/runs/18726362277/job/53412058096?pr=1205

(note, this did not work, the build failed)

Copy link
Contributor

@bkeryan bkeryan Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's weird. NiDAQmxLibrary::NiDAQmxLibrary(std::shared_ptr<nidevice_grpc::SharedLibraryInterface> shared_library) is only called from NiDAQmxLibrary::NiDAQmxLibrary() and doesn't seem to be inlined in the v2.13.0 release binaries.

That said, the build time increased by 20 minutes, so I think there may be multiple problem files. nidaqmx_library.cpp may have been the one that pushed the GitHub-hosted runner over the edge and made it run out of memory, but other files may be taking several more minutes than before.

If disabling VTA fixes the build, then I think it's worth seeing what happens when you disable VTA globally instead of per-file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, the build time increased by 20 minutes, so I think there may be multiple problem files. nidaqmx_library.cpp may have been the one that pushed the GitHub-hosted runner over the edge and made it run out of memory, but other files may be taking several more minutes than before.

Oops, I was looking at the -j 2 change. Yeah, that's going to slow down the build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I still try disabling VTA globally?

Copy link
Contributor Author

@mikeprosserni mikeprosserni Oct 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I've updated this PR to disable VTA globally. (since the changes with push/pop didn't work)

I reverted all other build changes, and added this to CMakeLists.txt:

# GCC-specific flags
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-var-tracking-assignments")
  set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-var-tracking-assignments")
endif()

(Note: This worked, the Ubuntu build succeeded after 66 minutes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants