@@ -4,10 +4,11 @@ use crate::{
44 ArtifactCollection , ArtifactId , ArtifactIdNumber , Benchmark , BenchmarkJob ,
55 BenchmarkJobConclusion , BenchmarkJobStatus , BenchmarkRequest , BenchmarkRequestIndex ,
66 BenchmarkRequestStatus , BenchmarkRequestType , BenchmarkSet , CodegenBackend , CollectionId ,
7- CollectorConfig , Commit , CommitType , CompileBenchmark , Date , Index , PartialStatusPageData ,
8- Profile , QueuedCommit , Scenario , Target , BENCHMARK_JOB_STATUS_FAILURE_STR ,
9- BENCHMARK_JOB_STATUS_IN_PROGRESS_STR , BENCHMARK_JOB_STATUS_QUEUED_STR ,
10- BENCHMARK_JOB_STATUS_SUCCESS_STR , BENCHMARK_REQUEST_MASTER_STR , BENCHMARK_REQUEST_RELEASE_STR ,
7+ CollectorConfig , Commit , CommitType , CompileBenchmark , Date , InProgressRequestWithJobs , Index ,
8+ PartialStatusPageData , Profile , QueuedCommit , Scenario , Target ,
9+ BENCHMARK_JOB_STATUS_FAILURE_STR , BENCHMARK_JOB_STATUS_IN_PROGRESS_STR ,
10+ BENCHMARK_JOB_STATUS_QUEUED_STR , BENCHMARK_JOB_STATUS_SUCCESS_STR ,
11+ BENCHMARK_REQUEST_MASTER_STR , BENCHMARK_REQUEST_RELEASE_STR ,
1112 BENCHMARK_REQUEST_STATUS_ARTIFACTS_READY_STR , BENCHMARK_REQUEST_STATUS_COMPLETED_STR ,
1213 BENCHMARK_REQUEST_STATUS_IN_PROGRESS_STR , BENCHMARK_REQUEST_STATUS_WAITING_FOR_ARTIFACTS_STR ,
1314 BENCHMARK_REQUEST_TRY_STR ,
@@ -1624,7 +1625,7 @@ where
16241625
16251626 let requests = rows
16261627 . into_iter ( )
1627- . map ( |it| row_to_benchmark_request ( & it) )
1628+ . map ( |it| row_to_benchmark_request ( & it, None ) )
16281629 . collect ( ) ;
16291630 Ok ( requests)
16301631 }
@@ -1984,14 +1985,23 @@ where
19841985 }
19851986
19861987 async fn get_status_page_data ( & self ) -> anyhow:: Result < PartialStatusPageData > {
1987- let max_completed_requests = 7 ;
1988+ let max_completed_requests = 30 ;
19881989
1989- // Returns in progress requests along with their associated jobs
19901990 let in_progress_query = format ! (
19911991 "
19921992 WITH in_progress_requests AS (
19931993 SELECT
1994- {BENCHMARK_REQUEST_COLUMNS}
1994+ tag,
1995+ parent_sha,
1996+ pr,
1997+ commit_type,
1998+ status,
1999+ created_at,
2000+ completed_at,
2001+ backends,
2002+ profiles,
2003+ commit_date,
2004+ duration_ms
19952005 FROM
19962006 benchmark_request
19972007 WHERE
@@ -2022,15 +2032,73 @@ where
20222032 LEFT JOIN in_progress_requests ON job_queue.request_tag = in_progress_requests.tag
20232033 GROUP BY
20242034 job_queue.request_tag
2035+ ), parent AS (
2036+ SELECT
2037+ benchmark_request.tag AS parent_tag,
2038+ benchmark_request.parent_sha AS parent_sha,
2039+ benchmark_request.pr AS parent_pr,
2040+ benchmark_request.commit_type AS parent_commit_type,
2041+ benchmark_request.status AS parent_status,
2042+ benchmark_request.created_at AS parent_created_at,
2043+ benchmark_request.completed_at AS parent_completed_at,
2044+ benchmark_request.backends AS parent_backends,
2045+ benchmark_request.profiles AS parent_profiles,
2046+ benchmark_request.commit_date AS parent_commit_date,
2047+ benchmark_request.duration_ms AS parent_duration_ms,
2048+ EXISTS (
2049+ SELECT
2050+ 1
2051+ FROM
2052+ job_queue
2053+ WHERE
2054+ job_queue.request_tag = benchmark_request.tag
2055+ AND job_queue.status IN (
2056+ '{BENCHMARK_JOB_STATUS_QUEUED_STR}',
2057+ '{BENCHMARK_JOB_STATUS_IN_PROGRESS_STR}'
2058+ )
2059+ ) AS parent_active
2060+ FROM
2061+ benchmark_request
2062+ LEFT JOIN
2063+ in_progress_requests ON benchmark_request.tag = in_progress_requests.parent_sha
2064+ ), parent_jobs AS (
2065+ SELECT
2066+ request_tag AS parent_tag,
2067+ ARRAY_AGG(
2068+ ROW(
2069+ job_queue.id,
2070+ job_queue.request_tag,
2071+ job_queue.target,
2072+ job_queue.backend,
2073+ job_queue.profile,
2074+ job_queue.benchmark_set,
2075+ job_queue.status,
2076+ job_queue.created_at,
2077+ job_queue.started_at,
2078+ job_queue.completed_at,
2079+ job_queue.retry,
2080+ job_queue.collector_name
2081+ )::TEXT
2082+ ) AS parent_jobs
2083+ FROM
2084+ job_queue
2085+ LEFT JOIN parent ON job_queue.request_tag = parent.parent_tag
2086+ GROUP BY
2087+ job_queue.request_tag
20252088 )
20262089 SELECT
20272090 in_progress_requests.*,
2028- in_progress_jobs.jobs
2091+ in_progress_jobs.jobs,
2092+ parent.*,
2093+ parent_jobs.parent_jobs
20292094 FROM
20302095 in_progress_requests
20312096 LEFT JOIN
2032- in_progress_jobs ON in_progress_requests.tag = in_progress_jobs.tag;
2033- "
2097+ in_progress_jobs ON in_progress_requests.tag = in_progress_jobs.tag
2098+ LEFT JOIN
2099+ parent_jobs ON in_progress_requests.parent_sha = parent_jobs.parent_tag
2100+ LEFT JOIN
2101+ parent ON in_progress_requests.parent_sha = parent.parent_tag;"
20342102 ) ;
20352103
20362104 // Gets requests along with how long the request took (latest job finish
@@ -2075,19 +2143,41 @@ where
20752143 "
20762144 ) ;
20772145
2078- let in_progress: Vec < ( BenchmarkRequest , Vec < BenchmarkJob > ) > = self
2146+ let in_progress: Vec < InProgressRequestWithJobs > = self
20792147 . conn ( )
20802148 . query ( & in_progress_query, & [ ] )
20812149 . await ?
20822150 . iter ( )
20832151 . map ( |it| {
2084- let benchmark_request = row_to_benchmark_request ( it) ;
2152+ let benchmark_request = row_to_benchmark_request ( it, None ) ;
20852153 let jobs: Vec < BenchmarkJob > = it
20862154 . get :: < _ , Vec < String > > ( "jobs" )
20872155 . iter ( )
20882156 . map ( |it| benchmark_job_str_to_type ( it) . unwrap ( ) )
20892157 . collect ( ) ;
2090- ( benchmark_request, jobs)
2158+
2159+ // This is ever-so-slightly grim however it allows us to not
2160+ // have to parse the text representation of the jobs. Which
2161+ // saves a reasonable amount of time to justify doing this.
2162+ let parent_active = it. get :: < _ , Option < bool > > ( "parent_active" ) ;
2163+
2164+ InProgressRequestWithJobs {
2165+ request : ( benchmark_request, jobs) ,
2166+ parent : if parent_active. unwrap_or ( false ) {
2167+ // The rows values will only be non-null if the `parent_active`
2168+ // has been set
2169+ let parent_benchmark_request = row_to_benchmark_request ( it, Some ( 12 ) ) ;
2170+ // Only parse the jobs if we need to include the parent
2171+ let parent_jobs: Vec < BenchmarkJob > = it
2172+ . get :: < _ , Vec < String > > ( "parent_jobs" )
2173+ . iter ( )
2174+ . map ( |it| benchmark_job_str_to_type ( it) . unwrap ( ) )
2175+ . collect ( ) ;
2176+ Some ( ( parent_benchmark_request, parent_jobs) )
2177+ } else {
2178+ None
2179+ } ,
2180+ }
20912181 } )
20922182 . collect ( ) ;
20932183
@@ -2098,81 +2188,13 @@ where
20982188 . iter ( )
20992189 . map ( |it| {
21002190 (
2101- row_to_benchmark_request ( it) ,
2191+ row_to_benchmark_request ( it, None ) ,
21022192 // The errors, if there are none this will be an empty vector
21032193 it. get :: < _ , Option < Vec < String > > > ( 11 ) . unwrap_or_default ( ) ,
21042194 )
21052195 } )
21062196 . collect ( ) ;
21072197
2108- let in_progress_tags: Vec < & str > =
2109- in_progress. iter ( ) . map ( |it| it. 0 . tag ( ) . unwrap ( ) ) . collect ( ) ;
2110-
2111- let in_progress_tags: String = in_progress_tags. join ( "," ) ;
2112-
2113- // We don't do a status check on the jobs as we want to return all jobs,
2114- // irrespective of status, that are attached to an inprogress
2115- // benchmark_request
2116- let rows = self
2117- . conn ( )
2118- . query (
2119- "SELECT
2120- id,
2121- target,
2122- backend,
2123- profile,
2124- request_tag,
2125- benchmark_set,
2126- created_at,
2127- status,
2128- started_at,
2129- collector_name,
2130- completed_at,
2131- retry
2132- FROM
2133- job_queue WHERE job_queue.request_tag IN ($1);" ,
2134- & [ & in_progress_tags] ,
2135- )
2136- . await ?;
2137-
2138- let mut in_progress_jobs = vec ! [ ] ;
2139- for row in rows {
2140- let status_str = row. get :: < _ , & str > ( 7 ) ;
2141- let status = match status_str {
2142- BENCHMARK_JOB_STATUS_QUEUED_STR => BenchmarkJobStatus :: Queued ,
2143- BENCHMARK_JOB_STATUS_IN_PROGRESS_STR => BenchmarkJobStatus :: InProgress {
2144- started_at : row. get :: < _ , DateTime < Utc > > ( 8 ) ,
2145- collector_name : row. get :: < _ , String > ( 9 ) ,
2146- } ,
2147- BENCHMARK_JOB_STATUS_SUCCESS_STR | BENCHMARK_JOB_STATUS_FAILURE_STR => {
2148- BenchmarkJobStatus :: Completed {
2149- started_at : row. get :: < _ , DateTime < Utc > > ( 8 ) ,
2150- collector_name : row. get :: < _ , String > ( 9 ) ,
2151- success : status_str == BENCHMARK_JOB_STATUS_SUCCESS_STR ,
2152- completed_at : row. get :: < _ , DateTime < Utc > > ( 10 ) ,
2153- }
2154- }
2155- _ => panic ! ( "Invalid benchmark job status: {status_str}" ) ,
2156- } ;
2157-
2158- let job = BenchmarkJob {
2159- id : row. get :: < _ , i32 > ( 0 ) as u32 ,
2160- target : Target :: from_str ( row. get :: < _ , & str > ( 1 ) ) . map_err ( |e| anyhow:: anyhow!( e) ) ?,
2161- backend : CodegenBackend :: from_str ( row. get :: < _ , & str > ( 2 ) )
2162- . map_err ( |e| anyhow:: anyhow!( e) ) ?,
2163- profile : Profile :: from_str ( row. get :: < _ , & str > ( 3 ) )
2164- . map_err ( |e| anyhow:: anyhow!( e) ) ?,
2165- request_tag : row. get :: < _ , String > ( 4 ) ,
2166- benchmark_set : BenchmarkSet ( row. get :: < _ , i32 > ( 5 ) as u32 ) ,
2167- created_at : row. get :: < _ , DateTime < Utc > > ( 6 ) ,
2168- // The job is now in an in_progress state
2169- status,
2170- deque_counter : row. get :: < _ , i32 > ( 11 ) as u32 ,
2171- } ;
2172-
2173- in_progress_jobs. push ( job) ;
2174- }
2175-
21762198 Ok ( PartialStatusPageData {
21772199 completed_requests,
21782200 in_progress,
@@ -2231,18 +2253,19 @@ where
22312253 }
22322254}
22332255
2234- fn row_to_benchmark_request ( row : & Row ) -> BenchmarkRequest {
2235- let tag = row. get :: < _ , Option < String > > ( 0 ) ;
2236- let parent_sha = row. get :: < _ , Option < String > > ( 1 ) ;
2237- let pr = row. get :: < _ , Option < i32 > > ( 2 ) ;
2238- let commit_type = row. get :: < _ , & str > ( 3 ) ;
2239- let status = row. get :: < _ , & str > ( 4 ) ;
2240- let created_at = row. get :: < _ , DateTime < Utc > > ( 5 ) ;
2241- let completed_at = row. get :: < _ , Option < DateTime < Utc > > > ( 6 ) ;
2242- let backends = row. get :: < _ , String > ( 7 ) ;
2243- let profiles = row. get :: < _ , String > ( 8 ) ;
2244- let commit_date = row. get :: < _ , Option < DateTime < Utc > > > ( 9 ) ;
2245- let duration_ms = row. get :: < _ , Option < i32 > > ( 10 ) ;
2256+ fn row_to_benchmark_request ( row : & Row , row_offset : Option < usize > ) -> BenchmarkRequest {
2257+ let row_offset = row_offset. unwrap_or ( 0 ) ;
2258+ let tag = row. get :: < _ , Option < String > > ( row_offset) ;
2259+ let parent_sha = row. get :: < _ , Option < String > > ( 1 + row_offset) ;
2260+ let pr = row. get :: < _ , Option < i32 > > ( 2 + row_offset) ;
2261+ let commit_type = row. get :: < _ , & str > ( 3 + row_offset) ;
2262+ let status = row. get :: < _ , & str > ( 4 + row_offset) ;
2263+ let created_at = row. get :: < _ , DateTime < Utc > > ( 5 + row_offset) ;
2264+ let completed_at = row. get :: < _ , Option < DateTime < Utc > > > ( 6 + row_offset) ;
2265+ let backends = row. get :: < _ , String > ( 7 + row_offset) ;
2266+ let profiles = row. get :: < _ , String > ( 8 + row_offset) ;
2267+ let commit_date = row. get :: < _ , Option < DateTime < Utc > > > ( 9 + row_offset) ;
2268+ let duration_ms = row. get :: < _ , Option < i32 > > ( 10 + row_offset) ;
22462269
22472270 let pr = pr. map ( |v| v as u32 ) ;
22482271
0 commit comments