Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by appminis-mike · Oct 09, 2015 at 09:07 PM · profiling

Profiler.BeginSample doesn't work

I have a button that simply writes to a log, and does a Profiler.BeginSample (with an EndSample). I can see the log, but I don't see the sample in the profiler. I have Development Build checked, and I'm experiencing this problem in the editor, in a stand-alone PC build, and on my iPad. I also have a #define ENABLE_PROFILER at the top of the script that calls BeginSample.

Why might this not be working, and what can I do to address it?

Thank you.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Statement · Oct 09, 2015 at 10:03 PM

If you call a method once per button click which does something like...

 public void OnClick()
 {
     Profiler.BeginSample("Example");
     System.Threading.Thread.Sleep(1000);
     Profiler.EndSample();
 }

Then you have to scrub back to the frame in the profiler to where the click happened (it won't show up on any of the other frames). No, there's no simple way of knowing when that happened unless you had a big spike there. The actual sample label will be nested within some method so you may have to dig around for it. Other than that I don't think you have to do anything in the editor to see it.

If you were responding to an onClick callback from Unitys Button UI, it should be nested under BehaviourUpdate/EventSystem.Update(), as shown in the image below.

Profiler Screenshot


onclickprofilerbeginsample1.png (11.4 kB)
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Oct 09, 2015 at 10:07 PM 0
Share

As for reasons why your live code won't work, one possibility that springs to $$anonymous$$d would be a thrown exception after the file has been written, causing EndSample to never get called. Other than that, I don't really know. You do call EndSample in the same stack/frame right?

avatar image appminis-mike Statement · Oct 12, 2015 at 03:40 AM 0
Share

Yeah. I do a log before the BeginSample and after the EndSample, and both show up in the console, so I know both the Begin and the End are being called. But when I look in the profiler, my sample is nowhere to be found.

avatar image appminis-mike Statement · Oct 12, 2015 at 03:52 AM 2
Share

So it seems I needed to add a #define ENABLE_PROFILER to the top of my script (I had it at the top of a different script). Once I did that, my sample now appears in the profiler. The script is from an external DLL, so I don't know if that was a factor or not. I'm also not sure where the appropriate place for that define should be, but the current plan is to just put it at the top of each script as I profile. $$anonymous$$gestions for a better location appreciated.

Thanks for the help!

avatar image sgrein appminis-mike · Feb 10, 2020 at 07:34 PM 0
Share

app$$anonymous$$is-mike: Just try to remove the define and try again. does it still appear in the profiler? I guess so, you didn't find the Example because there was no big spike in the Timeline I guess.

avatar image sgrein · Feb 10, 2020 at 07:34 PM 0
Share

Does the method you profile need to be declared public? I say no. Also the #define seems to be for me not necessary.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Profiling with Instruments tool on iOS shows DrawSplashAndWaterMarks() after splash screen is no longer visible 0 Answers

Reading Profiler Results 1 Answer

Make Profiler ignore a particular function? 0 Answers

Profiling a gradual Editor slowdown? 1 Answer

Total GC increases without GC allocated 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges