Shop OBEX P1 Docs P2 Docs Learn Events
Counting Cogs — Parallax Forums

Counting Cogs

doggiedocdoggiedoc Posts: 2,245
edited 2013-01-27 08:40 in General Discussion
I was wondering if there is a built in way to know how many cogs are being used? My project has gotten more complex and I am relying on numerous objects written by others. Is the only way to know to go through all the code of each object and child-objects and count the number of cognews?

cogshot.png


Thanks!
Doc

Comments

  • Heater.Heater. Posts: 21,230
    edited 2013-01-27 05:46
    grep -i cognew * | wc -l
  • doggiedocdoggiedoc Posts: 2,245
    edited 2013-01-27 08:25
    Thank you Heater! Now, I just need to understand what you wrote. :D:D
  • Dave HeinDave Hein Posts: 6,347
    edited 2013-01-27 08:40
    What Heater wrote was a linux command. "grep -i cognew *" will search all the files in the current directory and print the ones containing cognew. The vertical bar causes the output from grep to be used as the input to the next command. "wc -l" will count the number of lines in the input, and print it out. I don't this this will work with unicode files. It doesn't tell you whether a cognew is called multiple times, or not called at all. There may also be some misbehaving objects that use coginit instead of cognew, though I think calling coginit with a cog number of -1 is the same as cognew.

    Assuming your program starts up OK, you can determine the number of free cogs by calling cognew until it returns a -1. If you store the return values from the successful calls to cognew you can then call cogstop to free up those cogs.
Sign In or Register to comment.