from gpumon.file import log_context

"""
Explanation: File Logger Example
This notebook is a small demo of how to use gpumon in Jupyter notebooks and some convenience methods for working with GPUs
End of explanation
"""


from gpumon import device_name, device_count

device_count() # Returns the number of GPUs available

device_name() # Returns the type of GPU available

from bokeh.io import output_notebook, show
import time

output_notebook()

"""
Explanation: device_name and device_count will return the name of the GPU found on the system and the number of GPUs
End of explanation
"""


with log_context('test_gpu.txt') as log:
    time.sleep(10)

"""
Explanation: Here we are simply going to tell the log context to record GPU measurements to the file test_gpu.txt
End of explanation
"""


!cat test_gpu.txt

"""
Explanation: We can then cat the file to see what we recorded in the 10 seconds
End of explanation
"""


df = log()

df

"""
Explanation: By calling the log object we get all the data returned to us in a dataframe
End of explanation
"""


p = log.plot(gpu_measurement='pwr', num_gpus=4)

show(p)

"""
Explanation: We can also call plot on the log object to plot the measurements we want
End of explanation
"""


