Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[datalog] Move DataLogReaderThread from glass to new libdatalog #7641

Open
wants to merge 32 commits into
base: 2027
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8883d10
move datalogreaderthread to wpiutil
DeltaDizzy Jan 5, 2025
a2025d1
fix datalog rader references in sysid
DeltaDizzy Jan 5, 2025
d939b8d
run wpiformat
DeltaDizzy Jan 5, 2025
e305452
point datalogtool at wpiutil
DeltaDizzy Jan 5, 2025
c7caae4
run wpiformat on datalogtool
DeltaDizzy Jan 5, 2025
98defa7
move DataLog classes to wpi::log namespace
DeltaDizzy Jan 7, 2025
aaf4e28
wpiformat
DeltaDizzy Jan 7, 2025
0207d7a
create libdatalog, move datalog from wpiutil
DeltaDizzy Jan 8, 2025
d45aec8
1st try at bazel
DeltaDizzy Jan 9, 2025
1c1d7bf
include deps and sources for bazel
DeltaDizzy Jan 9, 2025
94bf6f2
move datalog examples to libdatalog
DeltaDizzy Jan 9, 2025
f971f6e
add datalog examples and jni
DeltaDizzy Jan 9, 2025
6f2ea2d
move java datalog lib
DeltaDizzy Jan 9, 2025
b7d6341
mvoe filelogger (cpp) and cpp jni
DeltaDizzy Jan 9, 2025
041f0f8
add build.gradle
DeltaDizzy Jan 9, 2025
7e67505
move tests
DeltaDizzy Jan 9, 2025
cd0a384
Add gradle build
spacey-sooty Jan 9, 2025
861d227
fix tests cmake
DeltaDizzy Jan 9, 2025
8669810
Merge pull request #4 from spacey-sooty/datalogreader-to-wpiutil
DeltaDizzy Jan 9, 2025
50ee0b4
update java datalog package
DeltaDizzy Jan 9, 2025
3badb1a
import wpiutil jni
DeltaDizzy Jan 9, 2025
cad1513
add datalog to ntcore gradle
DeltaDizzy Jan 9, 2025
7ddcdfb
gradle updates
DeltaDizzy Jan 9, 2025
910fc99
revert to og gradle
DeltaDizzy Jan 9, 2025
71e7aa2
jni hell part 2
DeltaDizzy Jan 9, 2025
40d1ae5
almost there!
DeltaDizzy Jan 9, 2025
2bf9503
libdatalog builds
DeltaDizzy Jan 9, 2025
17635f3
SUCCESS
DeltaDizzy Jan 9, 2025
f64a5f9
add to new commands
DeltaDizzy Jan 9, 2025
ba9aee0
newline at end of build.bazel
DeltaDizzy Jan 9, 2025
79fb5a3
move kInvalidFile declaration to header
DeltaDizzy Jan 9, 2025
86841a5
Revert "move kInvalidFile declaration to header"
DeltaDizzy Jan 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ set(WPIUNITS_DEP_REPLACE_IMPL "find_dependency(wpiunits)")
set(WPIUTIL_DEP_REPLACE "find_dependency(wpiutil)")
add_subdirectory(wpiutil)

add_subdirectory(libdatalog)

if(WITH_NTCORE)
set(NTCORE_DEP_REPLACE "find_dependency(ntcore)")
set(WPINET_DEP_REPLACE "find_dependency(wpinet)")
Expand Down
2 changes: 1 addition & 1 deletion datalogtool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ add_executable(
${APP_ICON_MACOSX}
)
wpilib_link_macos_gui(datalogtool)
target_link_libraries(datalogtool libglass ssh)
target_link_libraries(datalogtool libglass ssh libdatalog)

if(WIN32)
set_target_properties(datalogtool PROPERTIES WIN32_EXECUTABLE YES)
Expand Down
1 change: 1 addition & 0 deletions datalogtool/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ model {
lib project: ':glass', library: 'glass', linkage: 'static'
lib project: ':wpiutil', library: 'wpiutil', linkage: 'static'
lib project: ':wpigui', library: 'wpigui', linkage: 'static'
lib project: ':libdatalog', library: 'libdatalog', linkage: 'static'
lib project: ':thirdparty:imgui_suite', library: 'imguiSuite', linkage: 'static'
nativeUtils.useRequiredLibrary(it, 'libssh')
if (it.targetPlatform.operatingSystem.isWindows()) {
Expand Down
10 changes: 5 additions & 5 deletions datalogtool/src/main/native/cpp/Exporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#include <fmt/format.h>
#include <fmt/ranges.h>
#include <glass/Storage.h>
#include <glass/support/DataLogReaderThread.h>
#include <imgui.h>
#include <imgui_internal.h>
#include <imgui_stdlib.h>
#include <portable-file-dialogs.h>
#include <wpi/DataLogReaderThread.h>
#include <wpi/DenseMap.h>
#include <wpi/MemoryBuffer.h>
#include <wpi/SmallVector.h>
Expand All @@ -40,7 +40,7 @@

namespace {
struct InputFile {
explicit InputFile(std::unique_ptr<glass::DataLogReaderThread> datalog);
explicit InputFile(std::unique_ptr<wpi::log::DataLogReaderThread> datalog);

InputFile(std::string_view filename, std::string_view status)
: filename{filename},
Expand All @@ -51,7 +51,7 @@ struct InputFile {

std::string filename;
std::string stem;
std::unique_ptr<glass::DataLogReaderThread> datalog;
std::unique_ptr<wpi::log::DataLogReaderThread> datalog;
std::string status;
bool highlight = false;
};
Expand Down Expand Up @@ -140,7 +140,7 @@ static void RebuildEntryTree() {
}
}

InputFile::InputFile(std::unique_ptr<glass::DataLogReaderThread> datalog_)
InputFile::InputFile(std::unique_ptr<wpi::log::DataLogReaderThread> datalog_)
: filename{datalog_->GetBufferIdentifier()},
stem{fs::path{filename}.stem().string()},
datalog{std::move(datalog_)} {
Expand Down Expand Up @@ -196,7 +196,7 @@ static std::unique_ptr<InputFile> LoadDataLog(std::string_view filename) {
}

return std::make_unique<InputFile>(
std::make_unique<glass::DataLogReaderThread>(std::move(reader)));
std::make_unique<wpi::log::DataLogReaderThread>(std::move(reader)));
}

void DisplayInputFiles() {
Expand Down
1 change: 1 addition & 0 deletions epilogue-runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ dependencies {
api(project(':ntcore'))
api(project(':wpiutil'))
api(project(':wpiunits'))
api(project(':libdatalog'))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@

import static edu.wpi.first.util.ErrorMessages.requireNonNullParam;

import edu.wpi.first.util.datalog.BooleanArrayLogEntry;
import edu.wpi.first.util.datalog.BooleanLogEntry;
import edu.wpi.first.util.datalog.DataLog;
import edu.wpi.first.util.datalog.DataLogEntry;
import edu.wpi.first.util.datalog.DoubleArrayLogEntry;
import edu.wpi.first.util.datalog.DoubleLogEntry;
import edu.wpi.first.util.datalog.FloatArrayLogEntry;
import edu.wpi.first.util.datalog.FloatLogEntry;
import edu.wpi.first.util.datalog.IntegerArrayLogEntry;
import edu.wpi.first.util.datalog.IntegerLogEntry;
import edu.wpi.first.util.datalog.RawLogEntry;
import edu.wpi.first.util.datalog.StringArrayLogEntry;
import edu.wpi.first.util.datalog.StringLogEntry;
import edu.wpi.first.util.datalog.StructArrayLogEntry;
import edu.wpi.first.util.datalog.StructLogEntry;
import edu.wpi.first.datalog.BooleanArrayLogEntry;
import edu.wpi.first.datalog.BooleanLogEntry;
import edu.wpi.first.datalog.DataLog;
import edu.wpi.first.datalog.DataLogEntry;
import edu.wpi.first.datalog.DoubleArrayLogEntry;
import edu.wpi.first.datalog.DoubleLogEntry;
import edu.wpi.first.datalog.FloatArrayLogEntry;
import edu.wpi.first.datalog.FloatLogEntry;
import edu.wpi.first.datalog.IntegerArrayLogEntry;
import edu.wpi.first.datalog.IntegerLogEntry;
import edu.wpi.first.datalog.RawLogEntry;
import edu.wpi.first.datalog.StringArrayLogEntry;
import edu.wpi.first.datalog.StringLogEntry;
import edu.wpi.first.datalog.StructArrayLogEntry;
import edu.wpi.first.datalog.StructLogEntry;
import edu.wpi.first.util.struct.Struct;
import java.util.HashMap;
import java.util.Map;
Expand Down
19 changes: 19 additions & 0 deletions libdatalog/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//shared/bazel/rules/gen:gen-resources.bzl", "generate_resources")

cc_library(
name = "libdatalog.static",
srcs = glob(
["src/main/native/cpp/**"],
),
hdrs = glob(["src/main/native/include/*"]),
includes = [
"src/main/native/cpp",
"src/main/native/include",
],
strip_include_prefix = "src/main/native/include",
visibility = ["//visibility:public"],
deps = [
"//wpiutil:wpiutil.static",
]
)
116 changes: 116 additions & 0 deletions libdatalog/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
project(libdatalog)

include(CompileWarnings)

file(
GLOB libdatalog_native_src
src/main/native/cpp/*.cpp
)

file(
GLOB libdatalog_jni_src
src/main/native/cpp/jni/DataLogJNI.cpp
)
list(REMOVE_ITEM libdatalog_native_src ${libdatalog_jni_src})

add_library(libdatalog ${libdatalog_native_src})
set_target_properties(libdatalog PROPERTIES DEBUG_POSTFIX "d")

target_compile_features(libdatalog PUBLIC cxx_std_20)
if(MSVC)
target_compile_options(
libdatalog
PUBLIC /permissive- /Zc:preprocessor /Zc:__cplusplus /Zc:throwingNew /MP /bigobj /utf-8
)
target_compile_definitions(libdatalog PRIVATE -D_CRT_SECURE_NO_WARNINGS)
endif()
wpilib_target_warnings(libdatalog)

target_include_directories(
libdatalog
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/main/native/include>
)

target_link_libraries(libdatalog PRIVATE wpiutil)

subdir_list(libdatalog_examples "${CMAKE_CURRENT_SOURCE_DIR}/examples")
foreach(example ${libdatalog_examples})
file(GLOB libdatalog_example_src examples/${example}/*.cpp)
if(libdatalog_example_src)
add_executable(libdatalog_${example} ${libdatalog_example_src})
wpilib_target_warnings(libdatalog_${example})
target_link_libraries(libdatalog_${example} libdatalog wpiutil)
set_property(TARGET libdatalog_${example} PROPERTY FOLDER "examples")
endif()
endforeach()

# Java bindings
if(WITH_JAVA)
include(UseJava)

set(CMAKE_JNI_TARGET true)

file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java)
file(GLOB QUICKBUF_JAR ${WPILIB_BINARY_DIR}/wpiutil/thirdparty/quickbuf/*.jar)

add_jar(
libdatalog_jar
${JAVA_SOURCES}
# INCLUDE_JARS ${JACKSON_JARS} ${QUICKBUF_JAR}
INCLUDE_JARS wpiutil_jar ${QUICKBUF_JAR}
OUTPUT_NAME libdatalog
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
GENERATE_NATIVE_HEADERS libdatalog_jni_headers
)
set_property(TARGET libdatalog_jar PROPERTY FOLDER "java")

install_jar(libdatalog_jar DESTINATION ${java_lib_dest})
install_jar_exports(TARGETS libdatalog_jar FILE libdatalog_jar.cmake DESTINATION share/libdatalog)

add_library(libdatalogjni ${libdatalog_jni_src})
wpilib_target_warnings(libdatalogjni)
target_link_libraries(libdatalogjni PUBLIC libdatalog wpiutil)

set_property(TARGET libdatalogjni PROPERTY FOLDER "libraries")

target_link_libraries(libdatalogjni PRIVATE libdatalog_jni_headers)
add_dependencies(libdatalogjni libdatalog_jar)

install(TARGETS libdatalogjni EXPORT libdatalogjni)
export(TARGETS libdatalogjni FILE libdatalogjni.cmake NAMESPACE libdatalogjni::)
endif()

if(WITH_JAVA_SOURCE)
include(UseJava)
include(CreateSourceJar)
add_source_jar(
libdatalog_src_jar
BASE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}/src/main/java
OUTPUT_NAME libdatalog-sources
OUTPUT_DIR ${WPILIB_BINARY_DIR}/${java_lib_dest}
)
set_property(TARGET libdatalog_src_jar PROPERTY FOLDER "java")

install_jar(libdatalog_src_jar DESTINATION ${java_lib_dest})
endif()

install(TARGETS libdatalog EXPORT libdatalog)
export(TARGETS libdatalog FILE libdatalog.cmake NAMESPACE libdatalog::)

configure_file(libdatalog-config.cmake.in ${WPILIB_BINARY_DIR}/libdatalog-config.cmake)
install(FILES ${WPILIB_BINARY_DIR}/libdatalog-config.cmake DESTINATION share/libdatalog)
install(EXPORT libdatalog DESTINATION share/libdatalog)

if(WITH_TESTS)
file(GLOB_RECURSE libdatalog_testlib_src src/test/native/include/*.h)
add_library(libdatalog_testlib INTERFACE ${libdatalog_test_src})
target_include_directories(libdatalog_testlib INTERFACE src/test/native/include)

wpilib_add_test(libdatalog src/test/native/cpp)
target_link_libraries(libdatalog_test libdatalog googletest libdatalog_testlib wpiutil)
if(MSVC)
target_compile_options(libdatalog_test PRIVATE /utf-8)
endif()
endif()

32 changes: 32 additions & 0 deletions libdatalog/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ext {
useJava = true
useCpp = true
baseId = 'libdatalog'
groupId = 'edu.wpi.first.datalog'

nativeName = 'libdatalog'
devMain = 'edu.wpi.first.math.DevMain'
}

apply from: "${rootDir}/shared/jni/setupBuild.gradle"

nativeUtils.exportsConfigs {
libdatalog {
}
}

model {
components {
all {
it.sources.each {
it.exportedHeaders {
srcDirs 'src/main/native/include'
}
}
}
}
}

dependencies {
api project(":wpiutil")
}
5 changes: 5 additions & 0 deletions libdatalog/libdatalog-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@FILENAME_DEP_REPLACE@
include(${SELF_DIR}/wpiutil.cmake)
if(@WITH_JAVA@)
include(${SELF_DIR}/wpiutil_jar.cmake)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package edu.wpi.first.util.datalog;
package edu.wpi.first.datalog;

import java.util.Arrays;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package edu.wpi.first.util.datalog;
package edu.wpi.first.datalog;

/** Log boolean values. */
public class BooleanLogEntry extends DataLogEntry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package edu.wpi.first.util.datalog;
package edu.wpi.first.datalog;

import edu.wpi.first.util.WPIUtilJNI;
import edu.wpi.first.util.protobuf.Protobuf;
import edu.wpi.first.util.struct.Struct;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -146,7 +145,7 @@ public void addSchema(String name, String type, String schema) {
* @param timestamp Time stamp (0 to indicate now)
*/
public void addSchema(Protobuf<?, ?> proto, long timestamp) {
final long actualTimestamp = timestamp == 0 ? WPIUtilJNI.now() : timestamp;
final long actualTimestamp = timestamp == 0 ? DataLogJNI.now() : timestamp;
proto.forEachDescriptor(
this::hasSchema,
(typeString, schema) ->
Expand All @@ -171,7 +170,7 @@ public void addSchema(Protobuf<?, ?> proto) {
* @param timestamp Time stamp (0 to indicate now)
*/
public void addSchema(Struct<?> struct, long timestamp) {
addSchemaImpl(struct, timestamp == 0 ? WPIUtilJNI.now() : timestamp, new HashSet<>());
addSchemaImpl(struct, timestamp == 0 ? DataLogJNI.now() : timestamp, new HashSet<>());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package edu.wpi.first.util.datalog;
package edu.wpi.first.datalog;

/**
* A data log background writer that periodically flushes the data log on a background thread. The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package edu.wpi.first.util.datalog;
package edu.wpi.first.datalog;

/** Log entry base class. */
public class DataLogEntry {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package edu.wpi.first.util.datalog;
package edu.wpi.first.datalog;

import java.util.Iterator;
import java.util.NoSuchElementException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package edu.wpi.first.util.datalog;
package edu.wpi.first.datalog;

import edu.wpi.first.util.WPIUtilJNI;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package edu.wpi.first.util.datalog;
package edu.wpi.first.datalog;

import java.io.IOException;
import java.io.RandomAccessFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package edu.wpi.first.util.datalog;
package edu.wpi.first.datalog;

import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
Expand Down
Loading
Loading