Closed Bug 1618979 Opened 6 years ago Closed 6 years ago

Unused BaseProfilerLogTest declaration in baseprofiler/core/platform.h

Categories

(Core :: Gecko Profiler, defect, P2)

defect

Tracking

()

RESOLVED FIXED
mozilla76
Tracking Status
firefox76 --- fixed

People

(Reporter: mstange, Assigned: mstange)

References

Details

Attachments

(2 files)

There's a declaration of a function named BaseProfilerLogTest in mozglue/baseprofiler/core/platform.h: https://searchfox.org/mozilla-central/source/mozglue/baseprofiler/core/platform.h#44

Clicking the function does not show a "Go to definition" item.

The definition is here: https://searchfox.org/mozilla-central/source/mozglue/baseprofiler/core/platform.cpp#151

The header is BaseProfilerLogTest but the definition is mozilla::baseprofiler::BaseProfilerLogTest, so they don't link up. That might be an actual bug in the code?

(In reply to Kartikaya Gupta (email:kats@mozilla.com) from comment #1)

The header is BaseProfilerLogTest but the definition is mozilla::baseprofiler::BaseProfilerLogTest, so they don't link up. That might be an actual bug in the code?

Cool! It might be! Things do compile and link fine though. I'm not sure of the semantics here. So yes, we should probably fix it, but if our regular linker links them up, shouldn't searchfox also be able to link them up?

The calls to the functions are done via macros, so all semantic processing such as name lookup happens at the site of the macro invocations. The function is also only required to be declared at those invocations, rather than at the location of the macro definition.

So what's happening is the declaration in platform.h declares an unrelated global ::BaseProfilerLogTest function which is never used, and all the macro invocations (I'm assuming) occur inside mozilla::baseprofiler and correctly find mozilla::baseprofiler::BaseProfilerLogTest.

Hah, nice! Moving to the Gecko Profiler component. Thanks for the explanation!

Component: Searchfox → Gecko Profiler
Product: Webtools → Core
Summary: Can't jump to definition for BaseProfilerLogTest → Unused BaseProfilerLogTest declaration in baseprofiler/core/platform.h

The fact that the macro makes an unqualified call is bug-prone, because any macro invocations that may be added outside of mozilla::baseprofiler in the future could hypothetically resolve to a different function.

My suggestion would be to modify the macros to qualify the call explicitly:

#define LOG_TEST mozilla::baseprofiler::BaseProfileLogTest(3)
// etc.

and then forward-declare the function inside that namespace:

namespace mozilla {
namespace baseprofiler {
bool BaseProfilerLogTest(int aLevelToTest);
}
}

(While it's only the invocation sites of the macros that require this forward declaration to be in scope, it's still a good idea for the same header that defines the macros to provide the forward declaration.)

I'll take care of this.

Assignee: nobody → mstange
Status: NEW → ASSIGNED

This fixes the declaration of (BaseProfiler)LogTest. It also makes it so that the logs show up on Android.
In xpcom we have printf_stderr which does something similar and also handles Windows.

Depends on D64990

Blocks: 1557570
Depends on: 1619362
Pushed by mstange@themasta.com: https://hg.mozilla.org/integration/autoland/rev/5c978c229b66 Tweak base profiler logging. r=gerald https://hg.mozilla.org/integration/autoland/rev/daf1993b5140 Use PrintToConsole for things that should always be printed. r=gerald
Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla76
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: