sapling/eden/fs/utils/TimeUtil.h
Andrew Milas 18bc0ee56a Add path information to inode tracing commands
Summary:
Currently the eden trace inode live and retroactive commands only display inode numbers in order to identify the inode whose event is being referenced. In order to help users more easily debug Eden, it would be helpful to also provide Inode names and/or inode paths to these commands. While computing inode paths can potentially be an expensive operation, we get over this by computing these paths outside of the critical path when inode events get published into tracebus and instead compute the paths in the thrift service handler for all inodes as they are needed. These paths are computed using the EdenMount's InodeMap.

However, as a consequence this might mean path information is not always available, namely during a start event when creating a new file, directory, or symlink while the live `eden trace inode` command is being run, or after an inode has been removed after its materialization event has occurred in the `eden trace indeed --retroactive` command. In these cases, an empty string is shown for the path, though a follow up diff is planned that will add file name information (not full paths) to each inode event as they occur that will be shown when full path information is unavailable.

Reviewed By: MichaelCuevas

Differential Revision: D37961108

fbshipit-source-id: 88d5d303eb5afc616ff46bc083cd96b55c572cfa
2022-07-19 16:30:46 -07:00

56 lines
1.4 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#pragma once
#include <chrono>
#include <string>
namespace facebook::eden {
/**
* Get a human-readable string for a time duration.
*
* Example return values:
* 3ns
* 10.456ms
* 1d23h3500.123s
*/
std::string durationStr(std::chrono::nanoseconds duration);
/**
* Comparision operators for comparing two timespec structs.
*/
bool operator<(const timespec& a, const timespec& b);
bool operator<=(const timespec& a, const timespec& b);
inline bool operator>=(const timespec& a, const timespec& b) {
return !(b < a);
}
inline bool operator>(const timespec& a, const timespec& b) {
return !(b <= a);
}
inline bool operator==(const timespec& a, const timespec& b) {
return (a.tv_sec == b.tv_sec) && (a.tv_nsec == b.tv_nsec);
}
inline bool operator!=(const timespec& a, const timespec& b) {
return !(b == a);
}
/**
* Specifically converts a duration of nanoseconds into milliseconds and
* returns a string in human readable format.
*/
std::string formatNsTimeToMs(uint64_t ns);
/**
* Get a human readable string for a time duration of microseconds in either
* microsecond, millisecond, or second time. Returns an empty string for
* negative durations
*/
std::string formatMicrosecondTime(long microseconds);
} // namespace facebook::eden