Compilation profiles don't really give you that level of control, they're just a set of optimization settings. You can't detect optimization settings very easily in code.
What you might look at is build config. You could maybe arrange a build alias or to pass in a
rustc-cfg flag that you can test against with
#cgf(...). I have never used it, so I can't say if there's a combination that works.
A better option is probably to use
debug_assertions as a standin-for non-release builds, so you can do this:
You could also use
debug here, but neither is perfect.