Author Topic: Writing to a logfile  (Read 23441 times)

sinsi

  • Guest
Writing to a logfile
« on: October 31, 2012, 07:53:33 PM »
I want to log GPU temperatures to a file, probably once a second. What's the best way to handle it?
 - open the file, keep it open while logging, close after logging is finished
 - open, write that second's temp, close - every second
 - fill a memory buffer then open/create, write, close - every buffer
There is the possibility of overheating and windows freezing (that's what this is for, to see if the GPU or CPU is too hot).
For that reason, I am looking at the second option but is that too much overhead? A game will be thrashing everything.

Opinions sought.

TouEnMasm

  • Member
  • *****
  • Posts: 1764
    • EditMasm
Re: Writing to a logfile
« Reply #1 on: October 31, 2012, 09:09:46 PM »

The write and close immediatly seems the more usable,can be fast.
Usable also is a dll with shared memory avoiding disk access.
Fa is a musical note to play with CL

sinsi

  • Guest
Re: Writing to a logfile
« Reply #2 on: October 31, 2012, 09:29:44 PM »
>The write and close immediatly seems the more usable,can be fast.
That's what I am leaning towards.

>Usable also is a dll with shared memory avoiding disk access.
Because Windows may freeze, it needs to be a file I can look at later.






hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Writing to a logfile
« Reply #3 on: October 31, 2012, 11:21:07 PM »
If overhead with the logger is a factor, i would be inclined to keep an app open, log results into a buffer then lazy write the buffer content to disk at a convenient interval. If the app itself is at risk of locking up, I would use a remote app and send data to it.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

FORTRANS

  • Member
  • *****
  • Posts: 1238
Re: Writing to a logfile
« Reply #4 on: November 01, 2012, 12:36:24 AM »
Hi,

   I would buffer a minute's worth (or 5 minutes) and
then write it out to minimize any effects on the system.
If worried about freezing, give each ~10 minute interval
a separate file.

Regards,

Steve N.

Tedd

  • Member
  • ***
  • Posts: 377
  • Procrastinor Extraordinaire
Re: Writing to a logfile
« Reply #5 on: November 01, 2012, 12:41:22 AM »
Open the file with FILE_FLAG_WRITE_THROUGH, keep the file open;
Fill up your own data buffer and flush when full;
Adjust the 'full' threshold according to the current CPU temperature (lazy when low temp, crazy when high temp);
Close the file when finished (or a freeze and reboot will have the same effect.)


No repeated open-close, and no loss of data :greenclp:
Potato2

fearless

  • Member
  • ****
  • Posts: 578
    • Github
Re: Writing to a logfile
« Reply #6 on: November 01, 2012, 12:42:58 AM »
MSI Afterburner (http://event.msi.com/vga/afterburner/download.htm) v2.2.4



has an option to monitor and log to file, and can display gpu temp whilst a game is running (along with other stuff - i usually just have FPS & Time displayed alongside GPU temp)

Works for both nvidia and ati cards.

For CPU temps i use CoreTemp to keep an eye on them - http://www.alcpu.com/CoreTemp/
fearless

ASUS Crosshair 8 Hero, AMD 5950X, 32GB, MSI 5700XT, NZXT Kraken Z73, Seasonic 1000W PSU

Github Twitter Mastodon Gitbook

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: Writing to a logfile
« Reply #7 on: November 01, 2012, 12:46:51 AM »
Does it matter?

include \masm32\MasmBasic\MasmBasic.inc   ; download
   Init
   .Repeat
      NanoTimer()
      Open "A", #1, "test.tmp"
      Print #1, Time$, CrLf$
      Close #1
      ; Print Str$("Writing took %i µs\n", NanoTimer(µs))
      Print Str$("Writing took %i ms\n", NanoTimer(ms))
      invoke Sleep, 500
      invoke GetKeyState, VK_SHIFT
   .Until sword ptr ax<0
   Inkey "bye"
   Exit
end start

Output:
Writing took 18 ms
Writing took 10 ms
Writing took 8 ms
Writing took 5 ms
Writing took 19 ms
Writing took 9 ms
Writing took 9 ms
bye

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: Writing to a logfile
« Reply #8 on: November 01, 2012, 01:42:46 PM »
the time consumed is not as much an issue as having the most recent data available for forensics
i like Tedd's method   :P

sinsi

  • Guest
Re: Writing to a logfile
« Reply #9 on: November 01, 2012, 02:10:14 PM »
Tedd, so if Windows freezes the file is still OK? The main problem is not the game freezing but Windows itself, with no time to close the file.
I like the idea of lazy/crazy writes too  8)

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: Writing to a logfile
« Reply #10 on: November 01, 2012, 06:52:13 PM »
Sinsi,

Keep it simple. I did the above test on my fast office machine, now again on my slow Celeron, and surprise, opening, writing and closing is done in less than a millisecond.

Even if it takes ten, and you do it once per minute, that slows down your game by 0.02%. I guess the player could live with that ;-)

sinsi

  • Guest
Re: Writing to a logfile
« Reply #11 on: November 01, 2012, 08:54:31 PM »
I didn't think there would be much if any overhead, I am from the old-school "if you open a handle you close it".
I will try Tedd's way and deliberately kill windows (reset button should do it) and see about the logfile.
If windows can't close it then is should show up as a lost cluster (by my way of thinking).

Tedd

  • Member
  • ***
  • Posts: 377
  • Procrastinor Extraordinaire
Re: Writing to a logfile
« Reply #12 on: November 02, 2012, 02:18:57 AM »
The file size should be updated with each flush - which would be every write if there's no buffering - so the file should be okay as long as writes get to finish.
Closing is more of a formality, and to ensure the data has been flushed; the file still needs to be in a consistent state as much as possible, since there is always the possibility of a crash.
You will get inconsistencies if the write gets interrupted before it finishes, but there's no way around that whatever method you use.
Potato2

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Writing to a logfile
« Reply #13 on: November 03, 2012, 07:27:33 AM »
I still basically like the idea of using another app to perform the file IO so that even if the source app crashes the file data is not lost or left incomplete. Sending a HWND_BROADCAST is hardly a problem when you are talking about 1 second intervals. The slave app could also keep track of the main app sending the message to identify if it was still running or not.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

Vortex

  • Member
  • *****
  • Posts: 2793
Re: Writing to a logfile
« Reply #14 on: November 03, 2012, 07:44:45 PM »
CoreTemp does not support Pentium IV processors.