[llvm] r340603 - [XRay] Refactor loadTraceFile(...) into two (NFC)
Dean Michael Berris via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 24 03:30:37 PDT 2018
Author: dberris
Date: Fri Aug 24 03:30:37 2018
New Revision: 340603
URL: http://llvm.org/viewvc/llvm-project?rev=340603&view=rev
Log:
[XRay] Refactor loadTraceFile(...) into two (NFC)
This patch splits the file trace loading function into two versions, one
that takes a filename and one that takes a `DataExtractor`.
This change is a precursor to larger changes to increase test coverage
for the trace loading implementation.
Modified:
llvm/trunk/include/llvm/XRay/Trace.h
llvm/trunk/lib/XRay/Trace.cpp
Modified: llvm/trunk/include/llvm/XRay/Trace.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/XRay/Trace.h?rev=340603&r1=340602&r2=340603&view=diff
==============================================================================
--- llvm/trunk/include/llvm/XRay/Trace.h (original)
+++ llvm/trunk/include/llvm/XRay/Trace.h Fri Aug 24 03:30:37 2018
@@ -17,8 +17,8 @@
#include <vector>
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/Error.h"
-#include "llvm/Support/FileSystem.h"
#include "llvm/XRay/XRayRecord.h"
namespace llvm {
@@ -50,7 +50,7 @@ class Trace {
typedef std::vector<XRayRecord>::const_iterator citerator;
- friend Expected<Trace> loadTraceFile(StringRef, bool);
+ friend Expected<Trace> loadTrace(const DataExtractor &, bool);
public:
/// Provides access to the loaded XRay trace file header.
@@ -58,6 +58,7 @@ public:
citerator begin() const { return Records.begin(); }
citerator end() const { return Records.end(); }
+ bool empty() const { return Records.empty(); }
size_t size() const { return Records.size(); }
};
@@ -65,6 +66,10 @@ public:
/// |Filename|.
Expected<Trace> loadTraceFile(StringRef Filename, bool Sort = false);
+/// This function will attempt to load XRay trace records from the provided
+/// DataExtractor.
+Expected<Trace> loadTrace(const DataExtractor &Extractor, bool Sort = false);
+
} // namespace xray
} // namespace llvm
Modified: llvm/trunk/lib/XRay/Trace.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/XRay/Trace.cpp?rev=340603&r1=340602&r2=340603&view=diff
==============================================================================
--- llvm/trunk/lib/XRay/Trace.cpp (original)
+++ llvm/trunk/lib/XRay/Trace.cpp Fri Aug 24 03:30:37 2018
@@ -862,7 +862,11 @@ Expected<Trace> llvm::xray::loadTraceFil
Twine("Cannot read log from '") + Filename + "'", EC);
}
auto Data = StringRef(MappedFile.data(), MappedFile.size());
+ DataExtractor DE(Data, true, 8);
+ return loadTrace(DE, Sort);
+}
+Expected<Trace> llvm::xray::loadTrace(const DataExtractor &DE, bool Sort) {
// Attempt to detect the file type using file magic. We have a slight bias
// towards the binary format, and we do this by making sure that the first 4
// bytes of the binary file is some combination of the following byte
@@ -877,8 +881,7 @@ Expected<Trace> llvm::xray::loadTraceFil
//
// Only if we can't load either the binary or the YAML format will we yield an
// error.
- StringRef Magic(MappedFile.data(), 4);
- DataExtractor HeaderExtractor(Magic, true, 8);
+ DataExtractor HeaderExtractor(DE.getData(), true, 8);
uint32_t OffsetPtr = 0;
uint16_t Version = HeaderExtractor.getU16(&OffsetPtr);
uint16_t Type = HeaderExtractor.getU16(&OffsetPtr);
@@ -889,7 +892,7 @@ Expected<Trace> llvm::xray::loadTraceFil
switch (Type) {
case NAIVE_FORMAT:
if (Version == 1 || Version == 2 || Version == 3) {
- if (auto E = loadNaiveFormatLog(Data, T.FileHeader, T.Records))
+ if (auto E = loadNaiveFormatLog(DE.getData(), T.FileHeader, T.Records))
return std::move(E);
} else {
return make_error<StringError>(
@@ -900,7 +903,7 @@ Expected<Trace> llvm::xray::loadTraceFil
break;
case FLIGHT_DATA_RECORDER_FORMAT:
if (Version == 1 || Version == 2 || Version == 3) {
- if (auto E = loadFDRLog(Data, T.FileHeader, T.Records))
+ if (auto E = loadFDRLog(DE.getData(), T.FileHeader, T.Records))
return std::move(E);
} else {
return make_error<StringError>(
@@ -909,7 +912,7 @@ Expected<Trace> llvm::xray::loadTraceFil
}
break;
default:
- if (auto E = loadYAMLLog(Data, T.FileHeader, T.Records))
+ if (auto E = loadYAMLLog(DE.getData(), T.FileHeader, T.Records))
return std::move(E);
}
More information about the llvm-commits
mailing list