borg icon indicating copy to clipboard operation
borg copied to clipboard

Adding performance statistics to borg create

Open francoo98 opened this issue 3 years ago • 9 comments

Issue #2209 Up until now, I have worked on:

  • number of files cache hits (b9d713b)
  • number of files cache indicated changed files (b9d713b)
  • number of files not in files cache at all (b9d713b)
  • time spent in chunking (3e7326e)
  • time spent in id hashing (c17f6f1)

The changes are pretty short and simple, I don't think a description is necessary. Let me know what you think and if there is anything that needs to be changed.

francoo98 avatar Aug 24 '22 20:08 francoo98

It would be good to have a test in borg.testsuite.archiver that checks if the new code works correctly. See the other tests you already see there about how this could work.

ThomasWaldmann avatar Aug 24 '22 23:08 ThomasWaldmann

Should the time be printed in seconds? Are decimals needed?

It would be good to have a test in borg.testsuite.archiver that checks if the new code works correctly. See the other tests you already see there about how this could work.

I am thinking about creating a test that would create a few archives and then check that the files_stats variable is correct (e.g: if one file was added "A" should be 2), and check that the printing is correct. I don't know how to test time measures.

francoo98 avatar Aug 25 '22 20:08 francoo98

IIRC borg create --stats already outputs some timing stats, do the new stats in a similar way concerning units and precision.

Testings the timing stats of course can not be done precisely, but maybe you could check it is > 0.0?

ThomasWaldmann avatar Aug 25 '22 21:08 ThomasWaldmann

BTW, you are working in your master branch.

Usually you should first create a feature branch for the feature you are working on, that works much better in the end.

You can leave it like it is for this time, but remember it next time.

ThomasWaldmann avatar Aug 25 '22 21:08 ThomasWaldmann

@francoo98 writing tests seems a bit tedious at first, esp. if you are new to it, but long term it can save countless of hours of manual testing (and/or countless of bugs). Check "TDD / test driven development" and "pytest".

pytest is a quite powerful testing framework, makes writing tests easier than other ones (after you got used to it).

ThomasWaldmann avatar Sep 08 '22 08:09 ThomasWaldmann

Looks like there is some conflict with master branch, please resolve.

(That will also trigger the tests to run again. Seems like the last test run had some unrelated issue.)

ThomasWaldmann avatar Sep 13 '22 12:09 ThomasWaldmann

the linter is still unhappy, see github checks.

you can run black .and tox -e flake8 locally to detect and fix such stuff early.

ThomasWaldmann avatar Sep 16 '22 12:09 ThomasWaldmann

I have some issues that I don't know how to solve.

  1. Where should I put the test for the tx_bytes and rx_bytes?
  2. test_hashing_time fails because the execution is too fast, how many files should I create in the test to make it slower?
  3. The original issue (#2209) tells to add time spent in encryption, but I don't if this means encryption of repository contents (i.e: -e set to something different than none) or encryption of network traffic (because of a RemoteRepository)

francoo98 avatar Sep 18 '22 15:09 francoo98

Ehrm, that code is wrong. I meant .removesuffix(), not .rstrip():

hashing_time = float(hashing_time.rstrip(" seconds"))

Please fix all similar places in your PR.

ThomasWaldmann avatar Sep 18 '22 21:09 ThomasWaldmann

Codecov Report

Merging #6991 (c367845) into master (a74bcb7) will increase coverage by 0.05%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #6991      +/-   ##
==========================================
+ Coverage   83.28%   83.34%   +0.05%     
==========================================
  Files          67       67              
  Lines       11460    11483      +23     
  Branches     2076     2078       +2     
==========================================
+ Hits         9545     9571      +26     
+ Misses       1375     1371       -4     
- Partials      540      541       +1     
Impacted Files Coverage Δ
src/borg/archive.py 83.38% <100.00%> (+0.17%) :arrow_up:
src/borg/archiver/create_cmd.py 78.84% <100.00%> (+0.41%) :arrow_up:
src/borg/remote.py 80.94% <0.00%> (+0.15%) :arrow_up:
src/borg/platform/base.py 81.45% <0.00%> (+1.61%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

codecov-commenter avatar Sep 23 '22 18:09 codecov-commenter

BTW, there is a time.sleep(1) in the test you added, is it needed / why?

It is needed because the second file needs newer timestamp than the first file.

francoo98 avatar Oct 13 '22 00:10 francoo98

@francoo98 thanks for the PR, it's merged now!

ThomasWaldmann avatar Oct 19 '22 19:10 ThomasWaldmann

That's great 😁! Are you going to close the issue?

francoo98 avatar Oct 19 '22 20:10 francoo98