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

[WIP] Plumbing for source locator #36

Merged
merged 12 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
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
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ rand = { version = "0.8" }
# transitive depedency, required for rand to support wasm
getrandom = { version = "0.2", features = ["js"] }

itertools = "0.11.0"
percentage = "0.1.0"
regex = "1.10.0"

Expand Down
20 changes: 19 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use egui::{
Align2, Color32, NumExt, Pos2, Rect, RichText, ScrollArea, Slider, Stroke, TextStyle, Vec2,
};
use egui_extras::{Column, TableBuilder};
#[cfg(not(target_arch = "wasm32"))]
use itertools::Itertools;
use percentage::{Percentage, PercentageInteger};
use regex::{escape, Regex};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -2542,9 +2544,25 @@ impl UiExtra for egui::Ui {
pub fn start(data_sources: Vec<Box<dyn DeferredDataSource>>) {
env_logger::try_init().unwrap_or(()); // Log to stderr (if you run with `RUST_LOG=debug`).

let all_locators = data_sources.iter().fold(Vec::new(), |acc, x| {
acc.into_iter()
.chain(x.fetch_description().source_locator)
bryevdv marked this conversation as resolved.
Show resolved Hide resolved
.collect()
});

let unique_locators = all_locators.into_iter().unique().collect_vec();

let locator = match &unique_locators[..] {
[] => "No data source".to_string(),
[x] => x.to_string(),
[x, ..] => format!("{} and {} other sources", x, unique_locators.len() - 1),
};
bryevdv marked this conversation as resolved.
Show resolved Hide resolved

let app_name = format!("{locator} - Legion Prof");

let native_options = eframe::NativeOptions::default();
eframe::run_native(
"Legion Prof",
&app_name,
native_options,
Box::new(|cc| Box::new(ProfApp::new(cc, data_sources))),
)
Expand Down
10 changes: 10 additions & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,13 @@ pub struct SlotMetaTile {
pub data: SlotMetaTileData,
}

#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct DataSourceDescription {
pub source_locator: Vec<String>,
}
bryevdv marked this conversation as resolved.
Show resolved Hide resolved

pub trait DataSource {
fn fetch_description(&self) -> DataSourceDescription;
fn fetch_info(&self) -> DataSourceInfo;
fn fetch_summary_tile(&self, entry_id: &EntryID, tile_id: TileID, full: bool) -> SummaryTile;
fn fetch_slot_tile(&self, entry_id: &EntryID, tile_id: TileID, full: bool) -> SlotTile;
Expand All @@ -215,6 +221,7 @@ pub trait DataSource {
}

pub trait DataSourceMut {
fn fetch_description(&self) -> DataSourceDescription;
fn fetch_info(&mut self) -> DataSourceInfo;
fn fetch_summary_tile(
&mut self,
Expand All @@ -232,6 +239,9 @@ pub trait DataSourceMut {
}

impl<T: DataSource> DataSourceMut for T {
fn fetch_description(&self) -> DataSourceDescription {
DataSource::fetch_description(self)
}
fn fetch_info(&mut self) -> DataSourceInfo {
DataSource::fetch_info(self)
}
Expand Down
16 changes: 15 additions & 1 deletion src/deferred_data.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use crate::data::{
DataSourceInfo, DataSourceMut, EntryID, SlotMetaTile, SlotTile, SummaryTile, TileID,
DataSourceDescription, DataSourceInfo, DataSourceMut, EntryID, SlotMetaTile, SlotTile,
SummaryTile, TileID,
};

pub trait DeferredDataSource {
fn fetch_description(&self) -> DataSourceDescription;
fn fetch_info(&mut self);
fn get_infos(&mut self) -> Vec<DataSourceInfo>;
fn fetch_summary_tile(&mut self, entry_id: &EntryID, tile_id: TileID, full: bool);
Expand Down Expand Up @@ -34,6 +36,10 @@ impl<T: DataSourceMut> DeferredDataSourceWrapper<T> {
}

impl<T: DataSourceMut> DeferredDataSource for DeferredDataSourceWrapper<T> {
fn fetch_description(&self) -> DataSourceDescription {
self.data_source.fetch_description()
}

elliottslaughter marked this conversation as resolved.
Show resolved Hide resolved
fn fetch_info(&mut self) {
self.infos.push(self.data_source.fetch_info());
}
Expand Down Expand Up @@ -102,6 +108,10 @@ impl<T: DeferredDataSource> CountingDeferredDataSource<T> {
}

impl<T: DeferredDataSource> DeferredDataSource for CountingDeferredDataSource<T> {
fn fetch_description(&self) -> DataSourceDescription {
self.data_source.fetch_description()
}

fn fetch_info(&mut self) {
self.start_request();
self.data_source.fetch_info()
Expand Down Expand Up @@ -145,6 +155,10 @@ impl<T: DeferredDataSource> DeferredDataSource for CountingDeferredDataSource<T>
}

impl DeferredDataSource for Box<dyn DeferredDataSource> {
fn fetch_description(&self) -> DataSourceDescription {
self.as_ref().fetch_description()
}

fn fetch_info(&mut self) {
self.as_mut().fetch_info()
}
Expand Down
8 changes: 7 additions & 1 deletion src/file_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use std::path::{Path, PathBuf};
use serde::Deserialize;

use crate::data::{
DataSource, DataSourceInfo, EntryID, SlotMetaTile, SlotTile, SummaryTile, TileID,
DataSource, DataSourceDescription, DataSourceInfo, EntryID, SlotMetaTile, SlotTile,
SummaryTile, TileID,
};
use crate::http::schema::TileRequestRef;

Expand All @@ -30,6 +31,11 @@ impl FileDataSource {
}

impl DataSource for FileDataSource {
fn fetch_description(&self) -> DataSourceDescription {
DataSourceDescription {
source_locator: vec![String::from(self.basedir.to_string_lossy())],
}
}
fn fetch_info(&self) -> DataSourceInfo {
let path = self.basedir.join("info");
self.read_file::<DataSourceInfo>(&path)
Expand Down
10 changes: 9 additions & 1 deletion src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use serde::Deserialize;

use url::Url;

use crate::data::{DataSourceInfo, EntryID, SlotMetaTile, SlotTile, SummaryTile, TileID};
use crate::data::{
DataSourceDescription, DataSourceInfo, EntryID, SlotMetaTile, SlotTile, SummaryTile, TileID,
};
use crate::deferred_data::DeferredDataSource;
use crate::http::fetch::{fetch, DataSourceResponse};
use crate::http::schema::TileRequestRef;
Expand Down Expand Up @@ -62,6 +64,12 @@ impl HTTPClientDataSource {
}

impl DeferredDataSource for HTTPClientDataSource {
fn fetch_description(&self) -> DataSourceDescription {
DataSourceDescription {
source_locator: vec![self.baseurl.to_string()],
}
}
elliottslaughter marked this conversation as resolved.
Show resolved Hide resolved

fn fetch_info(&mut self) {
let url = self.baseurl.join("info").expect("invalid baseurl");
self.request::<DataSourceInfo>(url, self.infos.clone());
Expand Down
11 changes: 8 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use rand::Rng;
use std::collections::BTreeMap;

use legion_prof_viewer::data::{
DataSourceInfo, DataSourceMut, EntryID, EntryInfo, Field, FieldID, FieldSchema, Item, ItemMeta,
ItemUID, SlotMetaTile, SlotMetaTileData, SlotTile, SlotTileData, SummaryTile, SummaryTileData,
TileID, TileSet, UtilPoint,
DataSourceDescription, DataSourceInfo, DataSourceMut, EntryID, EntryInfo, Field, FieldID,
FieldSchema, Item, ItemMeta, ItemUID, SlotMetaTile, SlotMetaTileData, SlotTile, SlotTileData,
SummaryTile, SummaryTileData, TileID, TileSet, UtilPoint,
};

#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -268,6 +268,11 @@ impl RandomDataSource {
}

impl DataSourceMut for RandomDataSource {
fn fetch_description(&self) -> DataSourceDescription {
DataSourceDescription {
source_locator: vec![String::from("Random Data Source")],
bryevdv marked this conversation as resolved.
Show resolved Hide resolved
}
}
fn fetch_info(&mut self) -> DataSourceInfo {
self.info.clone()
}
Expand Down
14 changes: 12 additions & 2 deletions src/merge_data.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::collections::VecDeque;

use crate::data::{
DataSourceInfo, EntryID, EntryIndex, EntryInfo, Field, ItemLink, ItemUID, SlotMetaTile,
SlotTile, SummaryTile, TileID,
DataSourceDescription, DataSourceInfo, EntryID, EntryIndex, EntryInfo, Field, ItemLink,
ItemUID, SlotMetaTile, SlotTile, SummaryTile, TileID,
};
use crate::deferred_data::DeferredDataSource;
use crate::timestamp::Interval;
Expand Down Expand Up @@ -192,6 +192,16 @@ impl MergeDeferredDataSource {
}

impl DeferredDataSource for MergeDeferredDataSource {
fn fetch_description(&self) -> DataSourceDescription {
DataSourceDescription {
source_locator: self.data_sources.iter().fold(Vec::new(), |acc, x| {
bryevdv marked this conversation as resolved.
Show resolved Hide resolved
acc.into_iter()
.chain(x.fetch_description().source_locator)
.collect()
}),
}
}

fn fetch_info(&mut self) {
for data_source in &mut self.data_sources {
data_source.fetch_info();
Expand Down
7 changes: 6 additions & 1 deletion src/parallel_data.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::sync::{Arc, Mutex};

use crate::data::{
DataSource, DataSourceInfo, EntryID, SlotMetaTile, SlotTile, SummaryTile, TileID,
DataSource, DataSourceDescription, DataSourceInfo, EntryID, SlotMetaTile, SlotTile,
SummaryTile, TileID,
};
use crate::deferred_data::DeferredDataSource;

Expand All @@ -26,6 +27,10 @@ impl<T: DataSource + Send + Sync + 'static> ParallelDeferredDataSource<T> {
}

impl<T: DataSource + Send + Sync + 'static> DeferredDataSource for ParallelDeferredDataSource<T> {
fn fetch_description(&self) -> DataSourceDescription {
self.data_source.fetch_description()
}
bryevdv marked this conversation as resolved.
Show resolved Hide resolved

fn fetch_info(&mut self) {
let data_source = self.data_source.clone();
let infos = self.infos.clone();
Expand Down
Loading