Line data Source code
1 : /*! 2 : * \file esys/repo/gitphasetimings.h 3 : * \brief Accumulated wall times for GitHelper sync phases 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2026 Michel Gillet 9 : * Distributed under the MIT License. 10 : * (See accompanying file LICENSE.txt or 11 : * copy at https://opensource.org/licenses/MIT) 12 : * 13 : * __legal_e__ 14 : * \endcond 15 : * 16 : */ 17 : 18 : #pragma once 19 : 20 : #include "esys/repo/esysrepo_defs.h" 21 : 22 : #include <cstdint> 23 : #include <sstream> 24 : #include <string> 25 : 26 : //<swig_inc/> 27 : 28 : namespace esys::repo 29 : { 30 : 31 : /*! \struct GitPhaseTimings esys/repo/gitphasetimings.h 32 : * \brief Wall-clock ms spent in GitHelper git operations during one sync 33 : * 34 : * ``refresh_ms`` (hybrid libgit2 reopen after clone/fetch) is nested inside 35 : * ``clone_ms`` / ``fetch_ms`` and is not added again in ``total_ms()``. 36 : */ 37 360 : struct ESYSREPO_API GitPhaseTimings 38 : { 39 : uint64_t open_ms = 0; 40 : uint64_t clone_ms = 0; 41 : uint64_t fetch_ms = 0; 42 : uint64_t checkout_ms = 0; 43 : uint64_t fastforward_ms = 0; 44 : uint64_t refresh_ms = 0; //!< Hybrid only; nested in clone/fetch 45 : 46 0 : uint64_t total_ms() const 47 : { 48 0 : return open_ms + clone_ms + fetch_ms + checkout_ms + fastforward_ms; 49 : } 50 : 51 0 : void add(const GitPhaseTimings &other) 52 : { 53 0 : open_ms += other.open_ms; 54 0 : clone_ms += other.clone_ms; 55 0 : fetch_ms += other.fetch_ms; 56 0 : checkout_ms += other.checkout_ms; 57 0 : fastforward_ms += other.fastforward_ms; 58 0 : refresh_ms += other.refresh_ms; 59 0 : } 60 : 61 0 : std::string format(const std::string &prefix = "sync phases (ms):") const 62 : { 63 0 : std::ostringstream oss; 64 0 : oss << prefix; 65 0 : if (open_ms != 0) oss << " open=" << open_ms; 66 0 : if (clone_ms != 0) oss << " clone=" << clone_ms; 67 0 : if (fetch_ms != 0) oss << " fetch=" << fetch_ms; 68 0 : if (checkout_ms != 0) oss << " checkout=" << checkout_ms; 69 0 : if (fastforward_ms != 0) oss << " fastforward=" << fastforward_ms; 70 0 : if (refresh_ms != 0) oss << " refresh=" << refresh_ms << " (in clone/fetch)"; 71 0 : oss << " total=" << total_ms(); 72 0 : return oss.str(); 73 0 : } 74 : }; 75 : 76 : } // namespace esys::repo