watermarks.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * high-watermark measurements
  11. */
  12. #include "u.h"
  13. #include "../port/lib.h"
  14. #include "mem.h"
  15. #include "dat.h"
  16. #include "fns.h"
  17. void
  18. initmark(Watermark *wp, int max, char *name)
  19. {
  20. memset(wp, 0, sizeof *wp);
  21. wp->max = max;
  22. wp->name = name;
  23. }
  24. void
  25. notemark(Watermark *wp, int val)
  26. {
  27. /* enforce obvious limits */
  28. if (val < 0)
  29. val = 0;
  30. else if (val > wp->max)
  31. val = wp->max;
  32. if (val > wp->highwater) {
  33. wp->highwater = val;
  34. if (val == wp->max && wp->curr < val)
  35. wp->hitmax++;
  36. }
  37. wp->curr = val;
  38. }
  39. char *
  40. seprintmark(char *buf, char *ebuf, Watermark *wp)
  41. {
  42. return seprint(buf, ebuf, "%s:\thighwater %d/%d curr %d hitmax %d\n",
  43. wp->name, wp->highwater, wp->max, wp->curr, wp->hitmax);
  44. }