Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(autoware.repos): add glog with v0.6.0 as a ros pkg #4614

Merged
merged 1 commit into from
Apr 11, 2024

Conversation

TakaHoribe
Copy link
Contributor

@TakaHoribe TakaHoribe commented Apr 10, 2024

Description

Currently, We are using Google's glog library to capture stack traces when a process dies, which is very useful for development. See examples in Autoware: ex1, ex2.

image

Due to the way of ROS 2 component launch procedure, glog sometimes be loaded as a module. However, it's not permissible to initialize glog multiple times, and glog will terminate the process if this occurs.

We can find some discussions about that, for example here.

To avoid this, it's necessary to use the IsGoogleLoggingInitialized() API, introduced in version v0.6.0 of glog. However, the glog deb package distributed with Ubuntu 22 is based on version v0.4.0. I plan to resolve this issue by registering version v0.6.0 in the repos.

I note that the Ubuntu 24 glog deb package adopts version v0.6.0, so updating to Ubuntu 24 will allow us to eliminate this dependency.

Related links

Tests performed

  1. Import autoware.repos
  2. run build
  3. check the psim/lsim works well.
  4. check if kill -15 <pid> will show the glog on terminal

Notes for reviewers

Interface changes

None

Effects on system behavior

None (glog version will be updated. We need to follow the update in each package)

Pre-review checklist for the PR author

The PR author must check the checkboxes below when creating the PR.

In-review checklist for the PR reviewers

The PR reviewers must check the checkboxes below before approval.

  • The PR follows the pull request guidelines.
  • The PR has been properly tested.
  • The PR has been reviewed by the code owners.

Post-review checklist for the PR author

The PR author must check the checkboxes below before merging.

  • There are no open discussions or they are tracked via tickets.
  • The PR is ready for merge.

After all checkboxes are checked, anyone who has write access can merge the PR.

@TakaHoribe
Copy link
Contributor Author

@mitsudome-r @xmfcx I've made this PR to improve the logging system. What do you think? Thank you for your comment.

@xmfcx
Copy link
Contributor

xmfcx commented Apr 10, 2024

@TakaHoribe It makes sense to add this.

How long does it take to compile glog, just out of curiosity?

Also, I don't know if compiling glog requires additional dependencies.

But we can add and see, thanks!

@xmfcx
Copy link
Contributor

xmfcx commented Apr 10, 2024

@TakaHoribe instead of updating to the latest version, this solution will probably work too with the old version:

This is still an issue but with a fairly easy work around. (Unless I'm missing something obvious)

We just need access to
bool IsGoogleLoggingInitialized();
Which is defined in the glog/src/utilities.h

So just define the following in your own code.

namespace google {
  namespace glog_internal_namespace_ {
    extern bool IsGoogleLoggingInitialized();
  }
  const auto& IsGoogleLoggingInitialized = glog_internal_namespace_::IsGoogleLoggingInitialized;
}

The linker should take care of linking the symbol to its implementation in glog.

So now you can simply use the function as google::IsGoogleLoggingInitialized()

We could just create a simple header file like this and call it.

Since we are using version 0.4 this small fix should work fine for us.

When updated to the Ubuntu 24.04 we can remove the header and keep using the same function.

This way we don't recompile the glog on Autoware machines.

@TakaHoribe
Copy link
Contributor Author

@xmfcx Thank you, Fatih.

The build of glog takes only 10 seconds:

horibe@dpc2210001:~/workspace/autoware [main] ?14$ rm -rf install/glog build/glog
horibe@dpc2210001:~/workspace/autoware [main] ?14$ colcon_build_release  --packages-select glog
Starting >>> glog    
Finished <<< glog [9.31s]                      

Summary: 1 package finished [10.9s]

I'll try this as well!
#4614 (comment)

@xmfcx
Copy link
Contributor

xmfcx commented Apr 11, 2024

@TakaHoribe you should also remove the ccache, or displace it temporarily to get the real numbers. 10s sounds too fast.

You can do ccache -s to get the cache directory.

@TakaHoribe
Copy link
Contributor Author

@xmfcx It is the result without ccache. With ccache, the build time is only 6s.

@xmfcx
Copy link
Contributor

xmfcx commented Apr 11, 2024

@TakaHoribe I have also confirmed it is quite fast, so, for me either way it works.

glog fork

Pros:

  • Easy to apply, no changes in source code

Cons:

  • 10-12 seconds of prior compilation time for planning packages that use it.

extra header

Pros:

  • No compilation overhead

Cons:

  • Add a simple header to a new package or a common package like autoware_utils
  • Include it in the packages that should init the glog
  • Remove it when upgraded to the next version

I leave the decision to you, either way is ok with me.

@TakaHoribe
Copy link
Contributor Author

@xmfcx Thank you for the summary!

I tried the "extra-header" way, and it seems to work.

I've noticed some drawbacks.

  • Creating a separate header for each package is cumbersome.
  • Using a utility file for the header adds another dependency. We need both glog and glog-extra-header, plus an additional include statement.

In contrast, upgrading to a new version via a fork is simpler. When we switch to Ubuntu 24.04, we'll just need to change the .repos file and switch the dependency.

I assume we'll update Ubuntu soon (at least it is not far future), so let us go with the glog-fork approach.

@TakaHoribe TakaHoribe marked this pull request as ready for review April 11, 2024 13:09
@TakaHoribe TakaHoribe requested review from mitsudome-r and xmfcx April 11, 2024 13:10
@xmfcx xmfcx merged commit eeec77f into autowarefoundation:main Apr 11, 2024
23 of 24 checks passed
@felixf4xu
Copy link

I'm not using a docker, so if I have already installed libgoogle-glog-dev for other projects in the Ubuntu system (it's v0.4), do I need to uninstall the system glog to use the external/glog/src copy?

@xmfcx
Copy link
Contributor

xmfcx commented May 10, 2024

You shouldn't need to uninstall it. But after the latest glog related update,
I would suggest to remove the build and install folders and do a clean build.

It should use the glog from the workspace.

@xmfcx
Copy link
Contributor

xmfcx commented May 10, 2024

mfc@mfc-leo:~$ apt list | grep libgoogle-glog

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libgoogle-glog-dev/jammy,now 0.5.0+really0.4.0-2 amd64 [installed]
libgoogle-glog-doc/jammy 0.5.0+really0.4.0-2 all
libgoogle-glog0v5/jammy,now 0.5.0+really0.4.0-2 amd64 [installed,automatic]

I have this on my Ubuntu 22.04 and I can build and run the latest Autoware without problems on it. colcon automatically uses it from the autoware workspace.

@felixf4xu
Copy link

remove the build and install folders and do a clean build

thanks, cleaning the cmake cache worked for me.

@TakaHoribe TakaHoribe deleted the add-glog branch August 22, 2024 06:53
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.

3 participants