|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
| 15 | +use crate::cache::storage_from_config; |
15 | 16 | use crate::client::{connect_to_server, connect_with_retry, ServerConnection}; |
16 | 17 | use crate::cmdline::{Command, StatsFormat}; |
17 | 18 | use crate::compiler::ColorMode; |
18 | 19 | use crate::config::{default_disk_cache_dir, Config}; |
19 | 20 | use crate::jobserver::Client; |
20 | 21 | use crate::mock_command::{CommandChild, CommandCreatorSync, ProcessCommandCreator, RunCommand}; |
21 | 22 | use crate::protocol::{Compile, CompileFinished, CompileResponse, Request, Response}; |
22 | | -use crate::server::{self, DistInfo, ServerInfo, ServerStartup}; |
| 23 | +use crate::server::{self, DistInfo, ServerInfo, ServerStartup, ServerStats}; |
23 | 24 | use crate::util::daemonize; |
24 | 25 | use byteorder::{BigEndian, ByteOrder}; |
25 | 26 | use fs::{File, OpenOptions}; |
@@ -607,8 +608,16 @@ pub fn run_command(cmd: Command) -> Result<i32> { |
607 | 608 | match cmd { |
608 | 609 | Command::ShowStats(fmt, advanced) => { |
609 | 610 | trace!("Command::ShowStats({:?})", fmt); |
610 | | - let srv = connect_or_start_server(get_port(), startup_timeout)?; |
611 | | - let stats = request_stats(srv).context("failed to get stats from server")?; |
| 611 | + let stats = match connect_to_server(get_port()) { |
| 612 | + Ok(srv) => request_stats(srv).context("failed to get stats from server")?, |
| 613 | + // If there is no server, spawning a new server would start with zero stats |
| 614 | + // anyways, so we can just return (mostly) empty stats directly. |
| 615 | + Err(_) => { |
| 616 | + let runtime = Runtime::new()?; |
| 617 | + let storage = storage_from_config(config, runtime.handle()).ok(); |
| 618 | + runtime.block_on(ServerInfo::new(ServerStats::default(), storage.as_deref()))? |
| 619 | + } |
| 620 | + }; |
612 | 621 | match fmt { |
613 | 622 | StatsFormat::Text => stats.print(advanced), |
614 | 623 | StatsFormat::Json => serde_json::to_writer(&mut io::stdout(), &stats)?, |
|
0 commit comments