3

Is it possible to record the time a thread spends processing only it's code?

E.g. capture sys.ms in thread A -> A is sliced and thread B runs -> B is sliced -> A comes back and captures current sys.ms. The resulting delta of Anow - Ainit includes the time that B spent on the machine.

Is it possible to account for this and get just the time A spent processing?

Is this doable on any other languages?

If it is or isn't, any documentation or papers explain why is appreciated. Google is flooded with "how to time" questions so I'm not seeing any answer for this.

Comments
  • 1
    Ok so because of Microsoft threads turn on and off as much as the os deems needed. So thread A would have to keep track of its own run time by out putting info or using a timer. Threads b c and d can take over multiple times while its trying to run.

    So time for completion? or time for total run cycles?

    And what language are you using?
  • 1
    So my initial question was centered more around Java, which doesn't use Threads like the OS level. The JVM scheduler manages their priority to maintian "fairness". That's my understand at least, which could be wrong.

    I want to know only the time spent by thread A on it's execution. B,D,C,etc. could take 6 years, but if A takes 4 seconds I want to get that value not 6y4s.
  • 1
    So completion time. How long the thread takes to complete over all. I think this https://docs.oracle.com/javase/... the thread while loop at the bottom of that page.
  • 0
    Let me know how it goes
  • 0
    @skprog So the example is very useful. It doesn't quite express what I'm after. I want to record the time arbitrarily within a multi-thread environment, so joining may not be viable being it only happens between 2 threads.

    Does that make sense? Let me know if I'm not being clear.
  • 0
    Have to track each thread individually. For what you said you want completion times for each individual thread. Use this callback while alive code. https://stackoverflow.com/questions...
  • 0
    Don't take my advice though i am not sure because i have never tried to time a thread. I just try to run them. Its hard enough just running multiple threads. Specifically when they may touch the same info. Lol
Add Comment