Skip to content

Commit

Permalink
Add favicon for APerf
Browse files Browse the repository at this point in the history
Also, fix a bug in the visualizer when directories are specified that
are not in the $PWD.
  • Loading branch information
janaknat committed Feb 15, 2023
1 parent 096baea commit fa414dd
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
Binary file added src/bin/html_files/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion src/bin/html_files/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h2>Performance Data Assistant</h2>
<h2>APerf</h2>
<div class="tab">
<button class="tablinks" name="system_info" id="default">SUT Config</button>
<button class="tablinks" name="sysctl">Sysctl Data</button>
Expand Down
13 changes: 10 additions & 3 deletions src/bin/visualizer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::Parser;
use aperf::VISUALIZATION_DATA;
use tide::http::mime;
use tide::http::{mime, Body};
use tide::{Response, StatusCode};
use std::path::Path;

Expand Down Expand Up @@ -28,16 +28,18 @@ async fn main() -> Result<(), std::io::Error> {
tide::log::start();

let dirs: Vec<String> = args.run_directory;
let mut dir_paths: Vec<String> = Vec::new();
let mut dir_stems: Vec<String> = Vec::new();
for dir in dirs {
let path = Path::new(&dir);
if dir_stems.contains(&path.file_stem().unwrap().to_str().unwrap().to_string()) {
println!("Cannot process two directories with the same name");
return Ok(())
}
dir_stems.push(path.file_stem().unwrap().to_str().unwrap().to_string());
dir_stems.push(path.clone().file_stem().unwrap().to_str().unwrap().to_string());
dir_paths.push(path.to_str().unwrap().to_string());
}
for dir in dir_stems {
for dir in dir_paths {
let name;
name = VISUALIZATION_DATA.lock().unwrap().init_visualizers(dir.to_owned()).unwrap();
VISUALIZATION_DATA.lock().unwrap().unpack_data(name).unwrap();
Expand All @@ -50,6 +52,11 @@ async fn main() -> Result<(), std::io::Error> {
let html = include_str!("html_files/index.html");
Ok(create_response(StatusCode::Ok, html, mime::HTML))
});
app.at("favicon.ico").get(|_| async move {
let ico = include_bytes!("html_files/favicon.ico");
let response = Response::builder(StatusCode::Ok).content_type(mime::ICO).body(Body::from_bytes(ico.to_vec())).build();
Ok(response)
});
/* Serve JavaScript files */
app.at("/html_files/:name").get(|req: tide::Request<()>| async move {
let name = req.param("name").unwrap();
Expand Down
13 changes: 7 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ impl Default for PerformanceData {
}

pub fn get_file(dir: String, name: String) -> Result<fs::File> {
for path in fs::read_dir(dir.clone()).unwrap() {
for path in fs::read_dir(dir.clone())? {
let mut file_name = path?.file_name().into_string().unwrap();
if file_name.contains(&name) {
file_name = dir + "/" + &file_name;
file_name = dir + &file_name;
return Ok(fs::OpenOptions::new()
.read(true)
.open(file_name)
Expand Down Expand Up @@ -208,13 +208,14 @@ impl VisualizationData {
}

pub fn init_visualizers(&mut self, dir: String) -> Result<String, tide::Error> {
let params = InitParams::new(dir.clone());
self.run_names.push(dir.clone());
let dir_path = Path::new(&dir);
let dir_name = dir_path.file_stem().unwrap().to_str().unwrap().to_string();
self.run_names.push(dir_name.clone());

for (_name, visualizer) in self.visualizers.iter_mut() {
visualizer.init_visualizer(dir.clone(), params.run_name.clone())?;
visualizer.init_visualizer(dir.clone(), dir_name.clone())?;
}
Ok(params.run_name.clone())
Ok(dir_name.clone())
}

pub fn add_visualizer(&mut self, name: String, dv: visualizer::DataVisualizer) {
Expand Down

0 comments on commit fa414dd

Please sign in to comment.