Skip to content

Commit

Permalink
aggregated without comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Pelanek committed Jun 18, 2024
1 parent f3a5efc commit e86af62
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 14 deletions.
9 changes: 9 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ target_link_libraries(test4 PRIVATE
telemetry::telemetry
telemetry::appFs
)

add_executable(test5
aggregatedFileExample.cpp
)

target_link_libraries(test5 PRIVATE
telemetry::telemetry
telemetry::appFs
)
56 changes: 56 additions & 0 deletions examples/aggregatedFileExample.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @file
* @author Daniel Pelanek <xpeland00@vutbr.cz>
* @brief Shows how the aggregated files are used and it's methods
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <telemetry.hpp>
#include <appFs.hpp>

// example help
#include <iostream>

telemetry::Content returnValue(int value) {
return telemetry::Scalar(value);
}

int main() {
// Same as basic example
std::shared_ptr<telemetry::Directory> telemetryRootNode;
telemetryRootNode = telemetry::Directory::create();

std::string fusePath = "fusedir";

telemetry::appFs::AppFsFuse fuse = telemetry::appFs::AppFsFuse(telemetryRootNode, fusePath, true, true);
fuse.start();

const telemetry::FileOps fileOps1
= {[]() { return returnValue(2); }, nullptr};

const telemetry::FileOps fileOps2
= {[]() { return returnValue(5); }, nullptr};

auto aggFileDir = telemetryRootNode->addDir("aggDir");
auto file1 = aggFileDir->addFile("file1", fileOps1);
auto file2 = aggFileDir->addFile("file2", fileOps2);

const telemetry::AggOperation aggOp = {telemetry::AggMethodType::JOIN, "", "1"};
const telemetry::AggOperation aggOp1 = {telemetry::AggMethodType::AVG};
const telemetry::AggOperation aggOp2 = {telemetry::AggMethodType::SUM};


std::vector<telemetry::AggOperation> aggOps = {aggOp};
std::vector<telemetry::AggOperation> aggOps1 = {aggOp1};
std::vector<telemetry::AggOperation> aggOps2 = {aggOp2};

auto aggFile = aggFileDir->addAggFile("aggFile", "file[0-9]+", aggOps);
auto aggFile1 = aggFileDir->addAggFile("aggFile1", "file[0-9]+", aggOps1);
auto aggFile2 = aggFileDir->addAggFile("aggFile2", "file[0-9]+", aggOps2);


std::cout << telemetry::contentToString(aggFile->read()) << "\n";
std::cout << telemetry::contentToString(aggFile1->read()) << "\n";
std::cout << telemetry::contentToString(aggFile2->read()) << "\n";
}
6 changes: 3 additions & 3 deletions examples/basicExample.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file
* @file
* @author Daniel Pelanek <xpeland00@vutbr.cz>
* @brief Shows the basic usage of telemetry with fuse
*
Expand Down Expand Up @@ -67,13 +67,13 @@ int main() {
// One for clearing -> What gets called when you want to reset telemetry data.
// In this case we reset the startTime.
auto startTime = std::chrono::system_clock::now();
telemetry::FileOps const fileOps
const telemetry::FileOps fileOps
= {[&startTime]() { return getTimeElapsed(startTime); },
[&startTime]() { return clearTime(startTime); }};

// The read and clear functions are optional. In the case you don't use them pass
// a null pointer instead.
telemetry::FileOps const anotherFileOps
const telemetry::FileOps anotherFileOps
= {nullptr, nullptr};


Expand Down
4 changes: 2 additions & 2 deletions examples/contentExample.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file
* @file
* @author Daniel Pelanek <xpeland00@vutbr.cz>
* @brief Shows how telemetry content data types are used
*
Expand Down Expand Up @@ -31,7 +31,7 @@ telemetry::Array arrayReturn() {

for(uint64_t index = 0; index < nScalars; index++) {
arr.emplace_back(telemetry::Scalar(index));
}
}

return arr;
}
Expand Down
5 changes: 2 additions & 3 deletions examples/holderExample.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* @file
* @file
* @author Daniel Pelanek <xpeland00@vutbr.cz>
* @brief Shows how to use the holder class
*
Expand All @@ -24,7 +24,7 @@ class IOwnTelemetryFiles {
m_telemetryHolder.add(someFile);
}

// If you want to disable callback of files before the
// If you want to disable callback of files before the
// is destroyed.
void disableFiles() {
m_telemetryHolder.disableFiles();
Expand Down Expand Up @@ -55,4 +55,3 @@ int main() {
// Disable callbacks before the objects destructor
object.disableFiles();
}

12 changes: 6 additions & 6 deletions examples/utilsExample.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @file
* @file
* @author Daniel Pelanek <xpeland00@vutbr.cz>
* @brief
* @brief Shows how to use utility functions
*
* SPDX-License-Identifier: BSD-3-Clause
*/
Expand All @@ -10,7 +10,7 @@
#include <appFs.hpp>

// example help
#include <string>
#include <string>
#include <iostream>

void traverseDir(std::shared_ptr<telemetry::Directory>& dir, int depth) {
Expand Down Expand Up @@ -58,13 +58,13 @@ int main() {
fuse.start();

// Let's create a more complex dir structure
telemetry::FileOps const emptyFileOps
const telemetry::FileOps emptyFileOps
= {nullptr, nullptr};

auto file1 = telemetryRootNode->addFile("file1", emptyFileOps);
auto file2 = telemetryRootNode->addFile("file2", emptyFileOps);
auto dir1 = telemetryRootNode->addDir("dir1");

auto file3 = dir1->addFile("file3", emptyFileOps);
auto dir2 = dir1->addDir("dir2");
auto dir3 = dir1->addDir("dir3");
Expand All @@ -81,4 +81,4 @@ int main() {

// Utils can also give you a node from path
auto node = telemetry::utils::getNodeFromPath(telemetryRootNode, "/dir1/dir2/file5");
}
}

0 comments on commit e86af62

Please sign in to comment.