How much more RAM does your system need? We all know the only correct answer to this question is "all of it," but let's curtail our goals for a moment and think about how much we can actually use.

I've been thinking about how to write challenges that mimic real world problems, but I don't think it's possible to get much closer without revisiting old challenges at some later date. When I think of a real world, multi-stage challenge, I'll let you know. I'm pretty sure this one is a one-off, but drop me a line if you think of a way to extend it.

The Challenge

Today's challenge comes from a problem a buddy of mine has in the real world: he's got an extra C-note in his pocket (I know, what a problem to have!) and keeps waffling between an SSD and more RAM. The correct answer is, "Get both, jackass. You don't need lunch," but we're going to pretend that one isn't available.

Your assignment is to write a program that keeps tabs on your swap space usage, preferably over an extended period--say one week. This will require you to get familiar with some parts of your language of choice that you might not have used before. How does your system expose diagnostics information? Can you access it directly or do you need some library to do so? What facilities does your platform have for running a program on boot, or on login, so that you don't need to start your program manually if you shut down your system?

Now, I'm not here to tell you how to do your job (even though I seriously am doing exactly that right now), so I'll leave certain implementation details up to you. The data needs to be stored so that you can review it later, and it needs to be of a useful resolution. For my purposes, I felt sampling once each minute was fine, and I just printed the results to a text file in the most brain-damaged way possible. It doesn't matter how you do any of this provided that you can carry out the next step.

The next and final step is to figure out the answers to the following questions:

  1. Average RAM usage
  2. Average swap usage
  3. Max RAM usage
  4. Max swap usage

These max and average values apply for the period of the week your program has been running.

Clearly, I can't tell you the answer to these questions, so don't expect me to come back and edit this with some base64 tip or anything. I will return later on to add my stats for this work machine—but first I have to figure out how to make crontab do what I want.


Average RAM:	16113357
Average Swap:	0
Max RAM:	16774188
Max Swap:	0
Total RAM:	16777216

I don't know. I expected to see some swap, but the library I'm using is reporting that none was used. As a general rule, this is how a modern system should behave, but still.