Pacing down the output of the InternalsPlugin

Discussion in 'Other' started by hockel, Feb 7, 2014.

  1. hockel

    hockel Registered

    Joined:
    Jan 11, 2012
    Messages:
    38
    Likes Received:
    0
    I'm looking for a way to throttle down the amount of Telemetrie data gets written to a local file.
    Up to 90 times a sec is far too much for my needs and the Plugin should be as slim as possible and not to waist any ressources...

    The only approach coming to my mind, is reading the local system time and define a pattern if(time is like in this range of milliseconds) then write the file... otherwise skip

    I would like to find another way to get it done, but I'm out of ideas...
    Any help and examples are highly appreciated!
     
  2. TechAde

    TechAde Registered

    Joined:
    Oct 13, 2010
    Messages:
    606
    Likes Received:
    38
    Code:
    .hpp:
    
    int tickCount;
    
    .cpp:
    
    tickCount++;
    if (tickCount == 1) {
      // output stuff
    } else {
      if (tickCount == 10) tickCount = 0;
    }
    How about something like that? (Off the top of my head, excuse any errors!)
     
  3. hockel

    hockel Registered

    Joined:
    Jan 11, 2012
    Messages:
    38
    Likes Received:
    0
    you just made my day :)

    I thought the Plugin works like stateless or so and that each time the plugin gets fired, every variable would be back to default values.
    But if that is not the case, I think your approach will just do the job in my case

    THX TechAde!
     
  4. TechAde

    TechAde Registered

    Joined:
    Oct 13, 2010
    Messages:
    606
    Likes Received:
    38
    Any vars you define inside a callback with get reinitialised on every time the callback is fired, however if you define them as global (i.e. in the .hpp or outside your class in the .cpp) then they won't.

    Glad to be of assistance. :)
     
  5. hockel

    hockel Registered

    Joined:
    Jan 11, 2012
    Messages:
    38
    Likes Received:
    0
    I had a lot of lags when the plugin was writing data to the harddisk while I was driving. Only writing 10 values in a single file, not multiple files and not a lot of data....
    So I used TechAde's approach and throttled the plugin to write single output file.

    Problem is, even when I throttle the output file to be written not more than once every 2 seconds, I experience lags while racing.
    I don't do any calculations or things that spend time within the plugin. Just plain and simple writing a few values to a file. Just basics...

    I have an I7@3.6 and "SSD only" PC but everytime the output file gets written, I have a short lag in-game.

    The Goal is, to show some Telemetrie on my Windows Surface. Laptimes for practise, Damage to the car,... that kind of stuff...

    Does anyone have a solution against lags when the plugin writes data to the harddisk, even if it is a SSD? How do you work around that?
    I'm thinking to save the data im memory or sending it via stream to a remote service, but I'm just not sure what is best and how others do it...

    So,... how do you do it? ;)
     
  6. cosimo

    cosimo Registered

    Joined:
    Apr 14, 2013
    Messages:
    827
    Likes Received:
    99
    Not sure if you want very specific data, but I use DashMeterPro and it's great. Maybe they make a version for windows surface too?

    On a related note, I'm also working on a plugin, and I write a lot of telemetry data. Being on a spinning drive (non-SSD), I expected some noticeable delay, but I still get 100+ fps, so I would double check that your plugin disk I/O is really to blame. How about commenting out the file writes and seeing if you still have the problem?
     
  7. Noel Hibbard

    Noel Hibbard Registered

    Joined:
    Oct 5, 2010
    Messages:
    2,744
    Likes Received:
    40
    Define your file globally, then open the file in Startup() and then write the file within UpdateScoring() and leave it open and don't close it until Shutdown() is called. You could also open the file in EnterRealtime() and close it in ExitRealtime(). It all depends on what you are trying to do. My guess is right now you took the file writing code from the plugin sample and then changed what it actually writes. The problem is the sample plugin opens the file, writes and then closes on every update which creates TONS of overhead.
     
  8. Noel Hibbard

    Noel Hibbard Registered

    Joined:
    Oct 5, 2010
    Messages:
    2,744
    Likes Received:
    40
    Here is some sample code:
    Code:
    #include <fstream>
    
    std::ofstream binLogFile;
    
    void ExampleInternalsPlugin::binlog(const char *data, int length) {
    	if (binLogFile.is_open())
    	{
    		binLogFile.write(data,  length);
    	}
    }
    
    void ExampleInternalsPlugin::Startup( long version )
    {
    	binLogFile.open("LogFile.bin", std::ios::out | std::ios::binary | std::ios::app);
    }
    
    void ExampleInternalsPlugin::UpdateTelemetry( const TelemInfoV01 &info )
    {
    	binlog((char *)&info.mEngineRPM, sizeof(double));
    }
    
    void ExampleInternalsPlugin::Shutdown()
    {
    	binLogFile.close();
    }
    
    This should just give you an idea. This code doesn't throttle the output rate at all either. This code opens a file named LogFile.bin and appends binary data to it. You may not want to append. Read up on ofstream for more info on all the flags.
     
  9. Noel Hibbard

    Noel Hibbard Registered

    Joined:
    Oct 5, 2010
    Messages:
    2,744
    Likes Received:
    40
  10. hockel

    hockel Registered

    Joined:
    Jan 11, 2012
    Messages:
    38
    Likes Received:
    0
    thx guys

    @cosimo: I have no drop in FPS, still the same, but I recognize lags more like micro-stuttering. Each time the file gets written. Commenting out the single write I'm doing in one run of the plugin is causing no lags. Tried that already and was for me the proof that the writing is the issue. My SSD's are very fast, I cannot think of a bad IO there

    @Noel: I opened/closed the file within UpdateScoring(), but for the purpose that it closes the file handler after writing to be able to open the same file via network to read the data out of it (thought the file will be locked if I don't close the handler).
    I'm sure with the "tickCount"-trick from above, that I only write the file once every 2 seconds, and still I experience that little lag, so I thought following that road first...

    Bad Harddisk IO is the closest bet yet, but I cannot believe it. If I have lags while using a SSD, what could happen on a usual disk...
    If you don't experience the same, it must have something to do with my system. The performance of my system can not be the reason, it's pretty good.
    But Multi-GPU and rF2 gives me a hard time anyway, should check if running the plugin without SLI and on Single-Screen changes anything...
     
  11. hockel

    hockel Registered

    Joined:
    Jan 11, 2012
    Messages:
    38
    Likes Received:
    0
    Yeah I found that too. My biggest problem is that last time I worked with sockets is age's ago... but might be just the right thing for bad weather eastern lying in front of us.... ;)

    thanks for your code example, will give that a try. just curious if I can read the same file at the same time from another machine... let's find out ;)

    btw: haven't used ofstream, just tried sprintf
     
  12. B1K3R

    B1K3R Registered

    Joined:
    Apr 6, 2012
    Messages:
    1,605
    Likes Received:
    88
    Im using marcels plugins to stream data through sockets and the use a c# application to receive the data and stream it to web or save in database. Seems to be working fine but I havent test it with many real players yet which is my next test. Will let you know the resulting lag or not.

    Sent from my GT-I9300 using Tapatalk
     
  13. hockel

    hockel Registered

    Joined:
    Jan 11, 2012
    Messages:
    38
    Likes Received:
    0
    I did the switch to Marcel's (marrs) plugin and it's working great.
    Since I'm not writing to disk anymore, I have no more lags at all!

    Problem solved with a big smile ;)
     
  14. B1K3R

    B1K3R Registered

    Joined:
    Apr 6, 2012
    Messages:
    1,605
    Likes Received:
    88

    Awesome! I can confirm that too as my tests showed that lag is gone now :)
     

Share This Page