4 ## Copyright (c) 2010-2017 Intel Corporation
6 ## Licensed under the Apache License, Version 2.0 (the "License");
7 ## you may not use this file except in compliance with the License.
8 ## You may obtain a copy of the License at
10 ## http://www.apache.org/licenses/LICENSE-2.0
12 ## Unless required by applicable law or agreed to in writing, software
13 ## distributed under the License is distributed on an "AS IS" BASIS,
14 ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ## See the License for the specific language governing permissions and
16 ## limitations under the License.
23 def __init__(self, file_name, tsc = None):
24 self._file = open(file_name, "rb");
26 data = self._file.read(4*8);
27 dataUnpacked = struct.unpack("<qqqq", data);
29 self._hz = dataUnpacked[0]
31 self._tsc = dataUnpacked[1]
35 self._entryCount = dataUnpacked[2]
36 fieldCount = dataUnpacked[3]
38 data = self._file.read(fieldCount);
39 fmt = "b" * fieldCount;
41 dataUnpacked = struct.unpack("<" + fmt, data);
45 for e in dataUnpacked:
51 raise Exception("Unknown field format: " + str(e))
57 def setBeg(self, tsc):
68 for i in range(self._entryCount):
69 entry = self._readNextEntry()
75 def _readNextEntry(self):
77 entry = self._file.read(self._entrySize);
78 entryUnpacked = struct.unpack(self._entryFmt, entry);
79 return list(entryUnpacked)