summaryrefslogtreecommitdiff
path: root/graph-checker/src/main.rs
diff options
context:
space:
mode:
authorAndrew Guschin <guschin@altlinux.org>2024-10-11 15:57:37 +0400
committerAndrew Guschin <guschin@altlinux.org>2024-10-11 15:57:37 +0400
commit8a150ccc32b88842c70a9bffb4728cb420fe721d (patch)
treea6638f1abf9cba7391862ee7d358aa35cd20df50 /graph-checker/src/main.rs
parent4a59d3d58e8a87c0b176b9ef0a6d8fa65d8e1f03 (diff)
feat: add better logging
Diffstat (limited to 'graph-checker/src/main.rs')
-rw-r--r--graph-checker/src/main.rs66
1 files changed, 49 insertions, 17 deletions
diff --git a/graph-checker/src/main.rs b/graph-checker/src/main.rs
index 231221e..68fb0bb 100644
--- a/graph-checker/src/main.rs
+++ b/graph-checker/src/main.rs
@@ -1,5 +1,6 @@
+use anyhow::Context;
use sqlx::{migrate::MigrateDatabase, QueryBuilder, Sqlite};
-use std::time::Instant;
+use std::{fs::File, time::Instant};
mod graph;
@@ -8,29 +9,52 @@ use crate::geng::GengIterator;
mod compute;
+use simplelog::*;
+
#[tokio::main]
-async fn main() -> Result<(), sqlx::Error> {
+async fn main() -> anyhow::Result<()> {
dotenv::dotenv().ok();
+ CombinedLogger::init(vec![
+ TermLogger::new(
+ LevelFilter::Info,
+ Config::default(),
+ TerminalMode::Mixed,
+ ColorChoice::Auto,
+ ),
+ WriteLogger::new(
+ LevelFilter::Debug,
+ Config::default(),
+ File::create("test.log").unwrap(),
+ ),
+ ])
+ .unwrap();
+
+ let vert_num = std::env::args()
+ .nth(1)
+ .context("You should provide number of vertices in argument")?
+ .parse::<usize>()?;
let database_url =
std::env::var("DATABASE_URL").expect("Expected DATABASE_URL in env");
if !sqlx::Sqlite::database_exists(&database_url).await? {
+ log::info!("Database file doesn't exist. Creating '{database_url}'.");
sqlx::Sqlite::create_database(&database_url).await?;
}
let db = sqlx::SqlitePool::connect(&database_url).await?;
- let err = sqlx::query(
- "CREATE TABLE IF NOT EXISTS graphs (g6 VARCHAR NOT NULL, ind_dom INT NOT NULL, forced_geod INT NOT NULL);"
+ sqlx::query(
+ "CREATE TABLE IF NOT EXISTS graphs (\
+ g6 VARCHAR NOT NULL,\
+ size INT NOT NULL,\
+ ind_dom INT NOT NULL,\
+ forced_geod INT NOT NULL);",
)
.execute(&db)
- .await;
- if let Err(e) = err {
- println!("Error while creating table: {e}");
- }
+ .await?;
- let gi = GengIterator::new(9);
+ let gi = GengIterator::new(vert_num);
- println!("Started");
let start = Instant::now();
- const BATCH_SIZE: usize = 10000;
+ const BATCH_SIZE: usize = 5000;
+ log::info!("Started computation for {vert_num} vertices");
let mut count = 0;
loop {
let graphs = gi.take(BATCH_SIZE);
@@ -42,26 +66,34 @@ async fn main() -> Result<(), sqlx::Error> {
let sz = part.len();
let mut query = QueryBuilder::<Sqlite>::new(
- "INSERT INTO graphs (g6, ind_dom, forced_geod) ",
+ "INSERT INTO graphs (g6, size, ind_dom, forced_geod) ",
);
query.push_values(part, |mut b, res| {
match res {
- Ok((g6, ind_dom, fg)) => {
+ Ok((g6, size, ind_dom, fg)) => {
+ // log::debug!(
+ // "inserting {} {} {:?} {:?}",
+ // g6,
+ // size,
+ // ind_dom,
+ // fg
+ // );
b.push_bind(g6)
+ .push_bind(size as u32)
.push_bind(ind_dom.unwrap_or(0))
.push_bind(fg.unwrap_or(0));
}
- Err(_) => println!("Unable to push into query"),
+ Err(_) => log::error!("Unable to push into query"),
};
});
let err = query.build().execute(&db).await;
if let Err(e) = err {
- println!("Error while inserting: {e}");
+ log::error!("{e}");
}
count += sz;
- println!(
+ log::info!(
"Counted {count} in {}s",
batch.elapsed().as_nanos() as f64 / 1e9
);
@@ -72,7 +104,7 @@ async fn main() -> Result<(), sqlx::Error> {
let elapsed = start.elapsed();
let time = elapsed.as_nanos();
- println!("Time elapsed: {}s", time as f64 / 1e9);
+ log::info!("Time elapsed: {}s", time as f64 / 1e9);
Ok(())
}