Timestamp synchronization across virtual machines
Timestamp synchronization may be performed by determining a time offset between a first virtual machine having a first virtual clock counter of a computing system and a second virtual machine having a second virtual clock counter of the computing system; and adjusting timestamps of traces with timestamps based on the second virtual clock counter according to the time offset.
1 . A method comprising:
determining, by a computing system, a time offset between a first virtual machine having a first virtual clock counter of the computing system and a second virtual machine having a second virtual clock counter of the computing system;
storing, by the computing system and in a memory page shared by the first virtual machine and the second virtual machine, information regarding the first virtual clock counter;
reading, by the computing system, the information regarding the first virtual clock counter; and
adjusting, by the computing system and based on the information regarding the first virtual clock counter, timestamps of traces based on the second virtual clock counter according to the time offset.
2 . The method of claim 1 , wherein adjusting the timestamps further comprises subtracting the time offset from the timestamps.
3 . The method of claim 1 , wherein determining the time offset further comprises running a precision time protocol between the first virtual machine and the second virtual machine.
4 . The method of claim 1 , wherein determining the time offset further comprises:
running a precision time protocol between the first virtual machine and a second computing system to determine a first time offset;
running the precision time protocol between the second virtual machine and the second computing system to determine a second time offset; and
determining the time offset as a difference between the first time offset and the second time offset.
5 . The method of claim 1 , wherein determining the time offset further comprises:
initializing communications channels to the first virtual machine and to the second virtual machine;
measuring a delay time of the communications channels;
getting a first local time of the first virtual machine;
getting a local time of the second virtual machine;
getting a second local time of the first virtual machine; and
determining the time offset as the first local time of the first virtual machine plus the second local time of the first virtual machine minus twice the local time of the second virtual machine.
6 . The method of claim 1 , comprising storing, by the computing system, timestamps of traces based on the first virtual clock counter and the timestamps of traces based on the second virtual clock counter as adjusted according to the time offset, in a trace file.
7 . The method of claim 1 , comprising periodically repeating, by the computing system, the determining the time offset between the first virtual machine and the second virtual machine and the adjusting the timestamps of traces based on the second virtual clock counter.
8 . A computing system comprising:
a memory configured to store a first virtual clock counter of a first virtual machine and a second virtual clock counter of a second virtual machine; and
one or more programmable processors in communication with the memory and configured to:
determine a time offset between the first virtual clock counter and the second virtual clock counter;
store, in a memory page shared by the first virtual machine and the second virtual machine, information regarding the first virtual clock counter;
read the information regarding the first virtual clock counter; and
adjust, based on the information regarding the first virtual clock counter, timestamps of traces based on the second virtual clock counter according to the time offset.
9 . The computing system of claim 8 , wherein the one or more programmable processors are further configured to adjust the timestamps by subtracting the time offset from the timestamps.
10 . The computing system of claim 8 , wherein to determine the time offset the one or more programmable processors are further configured to run a precision time protocol between the first virtual machine and the second virtual machine.
11 . The computing system of claim 8 , wherein to determine the time offset, the one or more programmable processors are further configured to:
run a precision time protocol between the first virtual machine and a second computing system to determine a first time offset;
run the precision time protocol between the second virtual machine and the second computing system to determine a second time offset; and
determine the time offset as a difference between the first time offset and the second time offset.
12 . The computing system of claim 8 , wherein to determine the time offset, the one or more programmable processors are further configured to:
initialize communications channels to the first virtual machine and to the second virtual machine;
measure a delay time of the communications channels;
get a first local time of the first virtual machine;
get a local time of the second virtual machine;
get a second local time of the first virtual machine; and
determine the time offset as the first local time of the first virtual machine plus the second local time of the first virtual machine minus twice the local time of the second virtual machine.
13 . The computing system of claim 8 , wherein the one or more programmable processors are further configured to store, in a trace file in the memory, timestamps of traces based on the first virtual clock counter and the timestamps of traces based on the second virtual clock counter as adjusted according to the time offset.
14 . The computing system of claim 8 , wherein the one or more programmable processors are further configured to repeat the determining the time offset and the adjusting the timestamps of traces based on the second virtual clock counter.
15 . A non-transitory computer-readable storage medium encoded with instructions that, when executed by one or more processors of a computing system, cause the one or more processors to:
determine a time offset between a first virtual machine having a first virtual clock counter of the computing system and a second virtual machine having a second virtual clock counter of the computing system;
store, in a memory page shared by the first virtual machine and the second virtual machine, information regarding the first virtual clock counter;
read the information regarding the first virtual clock counter; and
adjust, based on the information regarding the first virtual clock counter, timestamps of traces based on the second virtual clock counter according to the time offset.
16 . The non-transitory computer-readable storage medium of claim 15 , wherein to adjust the timestamps of traces, the instructions further cause the one or more processors to subtract the time offset from the timestamps.
17 . The non-transitory computer-readable storage medium of claim 15 , wherein to determine the time offset, the instructions further cause the one or more processors to run a precision time protocol between the first virtual machine and the second virtual machine.
18 . The non-transitory computer-readable storage medium of claim 15 , wherein to determine the time offset, the instructions further cause the one or more processors to:
run a precision time protocol between the first virtual machine and a second computing system to determine a first time offset;
run the precision time protocol between the second virtual machine and the second computing system to determine a second time offset; and
determine the time offset as a difference between the first time offset and the second time offset.