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

Public log tracing functionality #4361

Merged
merged 6 commits into from
Jun 29, 2022
Merged

Conversation

mvaligursky
Copy link
Contributor

@mvaligursky mvaligursky commented Jun 22, 2022

changes:

  • Debug class is no longer exported, and it is completely stripped in non-debug builds
  • Tracing class is public and exported, with new public API (see below)
  • tracing channel constants were moved to core/constants.js and exported

new API:

// enable / disable tracing of channel
pc.Tracing.set(pc.TRACEID_RENDER_PASS, true);

// query status of the tracing channel - true or false
pc.Tracing.get(pc.TRACEID_RENDER_PASS);

@mvaligursky mvaligursky self-assigned this Jun 22, 2022
@mvaligursky mvaligursky added bug docs Documentation related labels Jun 22, 2022
@slimbuck
Copy link
Member

Should they be exported in debug build only?

@mvaligursky
Copy link
Contributor Author

Ideally not, for the same reason as Debug.setTrace is enabled in all builds.

from outside, people should be able to have code like

pc.Debug.setTracing(pc.TRACEID_BLAH, true);

in both builds, but it should be a no cost at release. I don't want them to have to comment out the code to run using release.

@slimbuck
Copy link
Member

Right, yes of course.

Could be confusing for devs that attempt to use this API and don't realise it only works in debug build.

@slimbuck
Copy link
Member

slimbuck commented Jun 23, 2022

Just checking debug.js I see that actually nothing apart from setTrace is removed in debug builds. We remove the calls to Debug.*** when building the engine itself, but don't remove the debug code.

I actually think all the Debug function implementations should have #if _DEBUG added to them so applications behave the same way.

@mvaligursky
Copy link
Contributor Author

This part of the build process is responsible for removing the functions, and calls to the functions, from the code base, so there is no need to wrap them using #if _DEBUG:

engine/rollup.config.js

Lines 129 to 144 in d7884b0

const stripFunctions = [
'Debug.assert',
'Debug.call',
'Debug.deprecated',
'Debug.warn',
'Debug.warnOnce',
'Debug.error',
'Debug.errorOnce',
'Debug.log',
'Debug.logOnce',
'Debug.trace',
'DebugHelper.setName',
'DebugGraphics.pushGpuMarker',
'DebugGraphics.popGpuMarker',
'WorldClustersDebug.render'
];

setTrace are done differently as we don't want to remove them from non-debug builds.

@slimbuck
Copy link
Member

Looking at the built build/playcanvas.js - Debug.warn, Debug.asset etc are all still intact?

@slimbuck
Copy link
Member

(strip removes the call sites, not the functions themselves).

@mvaligursky
Copy link
Contributor Author

Hey you're right. I've just tested it .. it strips the functions themselves if I don't export Debug module from the index.js. But as soon as I do that, they're no longer stripped - which kinda makes sense.
I'll add ifdefs now that we need to export it.

@mvaligursky
Copy link
Contributor Author

For example, class DebugHelper in the same file is not exported from index, and is completely stripped.

@mvaligursky
Copy link
Contributor Author

What I'm thinking is .. keep class Debug not exported by index, so that it gets completely stripped without ifdefs.
And add exported class which is never stripped .. and is exported and is the public interface for this.

pc.Tracing.enable(channel);
pc.Tracing.disable(channel);

@slimbuck @willeastcott - what do you think?

@slimbuck
Copy link
Member

slimbuck commented Jun 23, 2022

TBH in general I don't think we should expose empty/non-functional API.

I actually think we should either:

  • keep the Debug API in all builds and expose it publicly (but continue to remove engine usage in non-debug builds)
  • remove the Debug API from public interface entirely and let apps roll their own. Trace control only exported in debug build (users shouldn't include calls to trace control in release code anyway).

@mvaligursky
Copy link
Contributor Author

  • remove the Debug API from public interface entirely and let apps roll their own. Trace control only exported in debug build (users shouldn't include calls to trace control in release code anyway).

we only export Debug API set/getTrace, nothing else. Its purpose is to allow them to 'see' under the hood of the engine, to help them understand what happens. It does not give them a logging API they can use to log from their scripts at all.

And I think it's very convenient to be able to use those functions in any build (even though in non-debug build they are ignored). Even I use them in the engine when I work on things (that way they work with any example I run), and the code does not fail to run in release build.

@slimbuck
Copy link
Member

Surely enabling trace in an application is a something temporary you do when developing and not something you'd wish to keep in application code?

@mvaligursky
Copy link
Contributor Author

It is, but having it in the code should not stop you running the build with the release engine. Having to go and comment it out is not user friendly, especially if you have few in different places.

So far all the APIs we have work with any engine build. For example even the profiling stats classes exist .. but their members (timings) are simply not updated.

@mvaligursky mvaligursky changed the title [Fix] Fix to the way Debug logging constants were exposed Public log tracing functionality Jun 29, 2022
@mvaligursky
Copy link
Contributor Author

I've made changes I suggested. Opinions?
@slimbuck @willeastcott

@mvaligursky mvaligursky added the release: next minor Ticket marked for the next minor release label Jun 29, 2022
Copy link
Contributor

@willeastcott willeastcott left a comment

Choose a reason for hiding this comment

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

Lovely. ❤️

@mvaligursky mvaligursky merged commit d783c2b into main Jun 29, 2022
@mvaligursky mvaligursky deleted the mvaligursky-core-constants branch June 29, 2022 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug docs Documentation related release: next minor Ticket marked for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants