MCPcopy Create free account
hub / github.com/f0rr0/oliphaunt / start

Method start

examples/tauri-sqlx-vanilla/src-tauri/src/bench.rs:93–146  ·  view source on GitHub ↗
(root: PathBuf, fresh: bool)

Source from the content-addressed store, hash-verified

91
92impl DatabaseHarness {
93 pub async fn start(root: PathBuf, fresh: bool) -> Result<Self> {
94 if fresh && root.exists() {
95 fs::remove_dir_all(&root)
96 .with_context(|| format!("remove profile dir {}", root.display()))?;
97 }
98 fs::create_dir_all(&root).with_context(|| format!("create {}", root.display()))?;
99
100 let paths = PglitePaths::with_root(&root);
101 let cold_start = !paths.pgdata.join("PG_VERSION").exists();
102 let mut startup = Vec::new();
103
104 let install_root = root.clone();
105 time_blocking(
106 &mut startup,
107 "install runtime and pgdata template",
108 move || install_into(&install_root).map(|_| ()),
109 )
110 .await?;
111
112 let preload_paths = paths.clone();
113 time_blocking(&mut startup, "load Wasmer AOT module", move || {
114 preload_runtime_module(&preload_paths)
115 })
116 .await?;
117
118 let server_root = root.clone();
119 let server = time_blocking(&mut startup, "start pglite server", move || {
120 preferred_server(server_root)
121 })
122 .await?;
123 let database_url = server.connection_uri();
124
125 let pool = time_async(&mut startup, "sqlx pool connect", async {
126 let options =
127 pg_connect_options(&server)?.application_name("pglite-oxide-tauri-sqlx-profile");
128
129 PgPoolOptions::new()
130 .max_connections(1)
131 .acquire_timeout(Duration::from_secs(30))
132 .connect_with(options)
133 .await
134 .context("connect SQLx pool to pglite proxy")
135 })
136 .await?;
137
138 Ok(Self {
139 root,
140 database_url,
141 pool,
142 _server: server,
143 cold_start,
144 startup,
145 })
146 }
147
148 pub async fn profile(&self, row_count: u32) -> Result<BenchReport> {
149 let total = Instant::now();

Callers 1

preferred_serverFunction · 0.45

Calls 8

time_blockingFunction · 0.85
install_intoFunction · 0.85
preload_runtime_moduleFunction · 0.85
preferred_serverFunction · 0.85
time_asyncFunction · 0.85
pg_connect_optionsFunction · 0.85
connection_uriMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected