@@ -38,100 +38,5 @@ pub(crate) struct Run {
38
38
error : Option < String > ,
39
39
}
40
40
41
- pub ( crate ) mod trace {
42
- use rusqlite:: params;
43
- use std:: path:: Path ;
44
- use std:: sync:: atomic:: { AtomicU32 , Ordering } ;
45
- use std:: sync:: { Arc , Mutex } ;
46
- use tracing_forest:: tree:: Tree ;
47
- use tracing_subscriber:: layer:: SubscriberExt ;
48
-
49
- pub fn override_thread_subscriber (
50
- db_path : impl AsRef < Path > ,
51
- ) -> anyhow:: Result < ( tracing:: subscriber:: DefaultGuard , Arc < AtomicU32 > ) > {
52
- let current_id = Arc :: new ( AtomicU32 :: default ( ) ) ;
53
- let processor = tracing_forest:: Printer :: new ( ) . formatter ( StoreTreeToDb {
54
- con : Arc :: new ( Mutex :: new ( rusqlite:: Connection :: open ( & db_path) ?) ) ,
55
- run_id : current_id. clone ( ) ,
56
- } ) ;
57
- let subscriber = tracing_subscriber:: Registry :: default ( ) . with ( tracing_forest:: ForestLayer :: from ( processor) ) ;
58
- let guard = tracing:: subscriber:: set_default ( subscriber) ;
59
- Ok ( ( guard, current_id) )
60
- }
61
-
62
- pub struct StoreTreeToDb {
63
- pub con : Arc < Mutex < rusqlite:: Connection > > ,
64
- pub run_id : Arc < AtomicU32 > ,
65
- }
66
- impl tracing_forest:: printer:: Formatter for StoreTreeToDb {
67
- type Error = rusqlite:: Error ;
68
-
69
- fn fmt ( & self , tree : & Tree ) -> Result < String , Self :: Error > {
70
- let json = serde_json:: to_string_pretty ( & tree) . expect ( "serialization to string always works" ) ;
71
- let run_id = self . run_id . load ( Ordering :: SeqCst ) ;
72
- self . con
73
- . lock ( )
74
- . unwrap ( )
75
- . execute ( "UPDATE run SET spans_json = ?1 WHERE id = ?2" , params ! [ json, run_id] ) ?;
76
- Ok ( String :: new ( ) )
77
- }
78
- }
79
- }
80
-
81
- pub ( crate ) mod run {
82
- use crate :: corpus;
83
- use crate :: corpus:: { Run , Task } ;
84
- use std:: path:: Path ;
85
- use std:: sync:: atomic:: AtomicBool ;
86
-
87
- impl Task {
88
- pub fn perform (
89
- & self ,
90
- run : & mut Run ,
91
- repo : & Path ,
92
- progress : & mut corpus:: Progress ,
93
- threads : Option < usize > ,
94
- should_interrupt : & AtomicBool ,
95
- ) {
96
- let start = std:: time:: Instant :: now ( ) ;
97
- if let Err ( err) = self . execute . execute ( repo, progress, threads, should_interrupt) {
98
- run. error = Some ( format ! ( "{err:#?}" ) )
99
- }
100
- run. duration = start. elapsed ( ) ;
101
- }
102
- }
103
-
104
- /// Note that once runs have been recorded, the implementation must not change anymore to keep it comparable.
105
- /// If changes have be done, rather change the name of the owning task to start a new kind of task.
106
- pub ( crate ) trait Execute {
107
- fn execute (
108
- & self ,
109
- repo : & Path ,
110
- progress : & mut corpus:: Progress ,
111
- threads : Option < usize > ,
112
- should_interrupt : & AtomicBool ,
113
- ) -> anyhow:: Result < ( ) > ;
114
- }
115
-
116
- pub ( crate ) static ALL : & [ Task ] = & [ Task {
117
- short_name : "OPNR" ,
118
- description : "open repository (isolated)" ,
119
- execute_exclusive : false ,
120
- execute : & OpenRepo ,
121
- } ] ;
122
-
123
- struct OpenRepo ;
124
-
125
- impl Execute for OpenRepo {
126
- fn execute (
127
- & self ,
128
- repo : & Path ,
129
- _progress : & mut corpus:: Progress ,
130
- _threads : Option < usize > ,
131
- _should_interrupt : & AtomicBool ,
132
- ) -> anyhow:: Result < ( ) > {
133
- gix:: open_opts ( repo, gix:: open:: Options :: isolated ( ) ) ?;
134
- Ok ( ( ) )
135
- }
136
- }
137
- }
41
+ pub ( crate ) mod run;
42
+ pub ( crate ) mod trace;
0 commit comments