ax_check_mysql introduction and example

I previously mentioned ax_check_mysql.m4 in one of my posts, an
m4 macro written for autoconf. So here’s a bit more information about
it, and some examples on how to use it.

Introduction

So ax_check_mysql is essentially an m4 macro for autoconf that was
written with MySQL plugin developers in mind. When one runs the macro, a
detected MySQL installation will give you the following information:

  • The path to the directory containing the MySQL executables
  • The path to the directory containing MySQL includes (if they exist)
  • The path to the directory where MySQL plugins go
  • The version of MySQL
  • Whether MySQL is 32 or 64 bit

Basically providing most of the information, MySQL-wise, needed to
install the plugin.

In the situation where an installation can not be detected or an
incomplete one is found, arguments can also be entered manually with:

--with-mysql

(where the root directory of the MySQL installation is passed (such as
/usr/local/mysql or some other custom directory)  and

--with-mysql-command, --with-mysql-plugin, --with-mysql-include

Which would just passing all the directories directly.

Examples

One can include the macro in the same fashion as any other macro in the
configure.ac file:

AC_INIT(ax_check_mysql_example,version-1.0)m4_include([m4_ax_check_mysql.m4])AX_CHECK_MYSQL([no],[yes],[5.0],[no])AC_MSG_NOTICE($MYSQL)AC_MSG_NOTICE($MYSQL_COMMANDS)

Now if I run this script on a computer with MySQL installed, you should
something along the lines of:

$ autoconf && ./configurechecking for gcc... gccchecking whether the C compiler works... yeschecking for C compiler default output file name... a.outchecking for suffix of executables...checking whether we are cross compiling... nochecking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking how to run the C preprocessor... gcc -Echecking for grep that handles long lines and -e... /bin/grepchecking for egrep... /bin/grep -Echecking for ANSI C header files... yeschecking for sys/types.h... yeschecking for sys/stat.h... yeschecking for stdlib.h... yeschecking for string.h... yeschecking for memory.h... yeschecking for strings.h... yeschecking for inttypes.h... yeschecking for stdint.h... yeschecking for unistd.h... yesTesting if MySQL was installed to common source/binary directorychecking for mysql... noTesting if MySQL was installed to common package manager directorychecking for mysql... yeschecking /usr/include/mysql/mysql_version.h/mysql_version.h usability... nochecking /usr/include/mysql/mysql_version.h/mysql_version.h presence...nochecking for /usr/include/mysql/mysql_version.h/mysql_version.h... nochecking /usr/include/mysql_version.h/mysql_version.h usability... nochecking /usr/include/mysql_version.h/mysql_version.h presence... nochecking for /usr/include/mysql_version.h/mysql_version.h... nochecking if /usr/lib/mysql/plugin/ exists...... yeschecking for mysql... /usr/bin/configure: WARNING: A package install was detected, but the include directory could not be found! MySQL development library may not be installed. If development library is installed please use --with-mysql-include --with-mysql-plugin --with-mysql-command to manually assign directory locationschecking MySQL Architecture... 32checking MySQL Version... 5.1.41checking if MySQL install supports Plugins... yeschecking if MySQL version is equal or greater than 5.0... yesconfigure: yesconfigure: /usr/bin/

Note that the last two lines of output were echoing the MYSQL and
MYSQL_COMMAND variables respectively, and that I do not have the
development library installed. A full list of variables available are
listed in the documentation.

One can pass four arguments when running the macro:

MYSQL-PLUGIN-NEEDED: if the MySQL version doesn’t support plugins (<
5.1), this will cause failure.

MYSQL-REQUIRED: say if MySQL is required or not.

MINIMUM-VERSION: minimum version required for MySQL (i.e. 5.0 or 5.5)

INCLUDES-REQUIRED: whether the MySQL includes are required (will fail if
includes are not found)

For example, If I wanted MySQL 5.5 or higher, I could enter:

AC_INIT(ax_check_mysql_example,version-1.0)m4_include([m4_ax_check_mysql.m4])AX_CHECK_MYSQL([no],[yes],[5.5],[no])

And as my MySQL installation is 5.1.41, ./configure will fail:

checking MySQL Architecture... 32checking MySQL Version... 5.1.41checking if MySQL install supports Plugins... yeschecking if MySQL version is equal or greater than 5.5... noconfigure: error: installed MySQL version is not above 5.5. Please upgrade your version of MySQL

Entering nothing in the version field will allow any version.

Warnings will be outputted instead of errors if components aren’t
required (such as includes or MySQL itself).

And there’s a brief example! Feel free to comment or contact me
(tsutsumi.yusuke@gmail.com) if there are any questions/ comments.

The script is maintained by myself on github:

https://github.com/Toumorokoshi/ax_check_mysql

Code folding in Emacs Viper-Mode

Code folding is a feature I’ve never really used, and for the most part
seem to have done find without. I generally use search to navigate from
place to place in my code, but I realize this isn’t always the most
efficient way to go, and code folding is very useful in a couple
aspects:

  • It helps focus me on what particular method or class I’m working on
    (way harder to tell when you’ve got several bunches of code in front
    of you at once)
  • Getting a good idea of the structure of the code (with everything
    folded, it’s much easier to see)

So I decided to play around with folding with my current development
environment. I use Emacs as my base, but viper-mode for the actual
text editing.

Emacs has some pretty good folding tools built-in. Namely, these are
FoldingMode and HideShow. I admit I didn’t play around with
FoldingMode a lot, as using it seems to involve manually adding the
folding points, something which I think is unnecessary 90% of the time.
Ideally, I’m looking for a folding extension that automatically
determines folding points, and leaves things as hands-off for me as
possible. One should be able to open a file, fold it up, and then open
and fold as necessary. I’m not looking to waste time adding commented
blocks of folding everywhere.

Thats where HideShow comes in. Armed with rules for an array of
programming languages, HideShow automatically looks for these patterns
and sets folding points appropriately. Exactly what I’m looking for.
Simply loading hideshow using .emacs:

(load-library "hideshow")

And activate the hideshow minor mode whenever you load the major mode of
your choice (for me it’s Python):

(add-hook 'python-mode-hook 'hs-minor-mode)

Now you have all the access to the wonderful world of dynamic folding!
Unfortunately, I didn’t really like the cumbersome keystrokes:

  • C-c @ M-C-s to unfold all
  • C-c @ C-h to fold
  • C-c @ C-s to unfold
  • C-c @ M-C-h to fold all
  • C-c @ C-c to toggle folding

Yeah, a six key-stroke succession is too much for me. So I assigned
these bindings to almost the same folding commands as VIM:

  • zm to unfold
  • zr to fold
  • zM to unfold all
  • zR to fold all
  • zt to toggle

To do this, I added configuration into the .viper file:

(define-key viper-vi-global-user-map "zt" 'hs-toggle-hiding)(define-key viper-vi-global-user-map "zM" 'hs-hide-all)(define-key viper-vi-global-user-map "zm" 'hs-hide-block)(define-key viper-vi-global-user-map "zR" 'hs-show-all)(define-key viper-vi-global-user-map "zr" 'hs-show-block)

(viper-vi-global-user-map tell viper it’s for any buffer in any state
with viper as a major mode). So far, this is working like a charm for
me. Here’s a screenshot with it at work:

image0

Feel free to comment if you have ideas/improvements!

Autoconf: ax_check_mysql

Just mentioning a little m4 script I wrote a little while ago.
ax_check_mysql is used to find a valid MySQL installation, and gives
you the binary, include, and plugin directories.

If you have an autoconf project, and you need MySQL, definitely consider
it!

http://www.gnu.org/software/autoconf-archive/ax_check_mysql.html#ax_check_mysql

Configuring HttpArchive + Webpagetest (Part 3: HttpArchive)

It’s time to install HttpArchive! So just as with Webpagetest, there’s
some requirements for HttpArchive as well.

HttpArchive must run on a unix-based machine, as HttpArchive uses pcntl,
a threading function in PHP currently available only on unix-based
machines. For this guide I will be using Ubuntu.

The following will be needed on your machine:

  • Apache2+
  • PHP5 or above
  • MySQL
  • Subversion
  • pcntl (PHP)

Most of these can be installed with a package manager. However with
pnctl, one must manually download the source, and either configure PHP
with the pcntl argument, or compile and install the pcntl extension
manually. I found an Ubuntu forum post from skout23 that explains a very
easy way to install pcntl for Ubuntu users. However I’m sure aside from
the package manager, BSD based Linux users can do the exact same thing:
http://ubuntuforums.org/showthread.php?t=549953

Here’s the relevant code for Ubuntu users:

mkdir phpcd phpapt-get source php5cd php5-(WHATEVER_RELEASE)/ext/pcntlphpize./configuremake

And don’t forget to restart Apache afterward!

Once everything is configured properly, you can checkout the HttpArchive
source from the googlecode repository:“ “

http://httparchive.googlecode.com/svn/trunk/

In addition, unless you want to download the downloads folder (which
contains over 1GB of data from the sites that HttpArchive tracks), it
would be best to checkout non-recursively, then check out all other
folders:

$svn co -N http://httparchive.googlecode.com/svn/trunk/ .$cd trunk$svn up images$svn up bulktest

Next, we will modify the settings.inc folder with the following
information:

  • $gMysqlServer = “YOUR_SERVER”
  • $gMysqlDb = “YOUR_DATABASE”
  • $gMysqlUsername = “ACCOUNT_USERNAME”
  • $gMysqlPassword = “ACCOUNT_PASSWORD”

Finally, Apache needs to interpret the .js files with PHP before being
served to the user. There exists a directive inside the .htaccess file
in the root of the repository that already accounts for this. However, I
had issues with this particular part, so I had to add the directive into
the php.conf file under /etc/apache2/mods-enabled (you will need root
permissions to modify this file):

<Filesmatch "(filmstrip|harviewer|interesting|interesting-images).js">SetHandler application/x-httpd-php</FilesMatch>

And you’ve configured HttpArchive! Unfortunately it won’t really work
without any data, but we’ll talk about the final steps in part 4:
Configuring the two to work with each other!

Configuring HttpArchive + Webpagetest (Part 2: Webpagetest)

Welcome to part 2! This post discusses installing Webpagetest.org. In
order to do so, we will need:

  • A windows machine (XP or Windows 7 have been tested with this method)
  • Apache2.2 or higher
  • PHP5 or higher
  • IE of some sort (IE8 or 9 would be best)
  • ffmpeg

It is possible to split up the web server and the testing server, but I
put them both on the same machine for ease of use. In addition I found
installing and configuring Apache and PHP together on windows was
surprisingly difficult, so I suggest installing Xampp. It’s a
single-install program that includes many of the tools used for serving
web pages and web development, such as Apache, PHP5, MySQL, and
Filezilla. Windows 7 machines have IE 8 installed by default, but
upgrading is straightforward for XP machines.

Once you have your machine set up properly, it’s time to install
Webpagetest! You can download the source here: Webpagetest.org
source
.

There are also installation instructions on the webpagetest.org google
site. I would recommend following these fora a complete guide, but what
I have written is a shorter version and will attain the same result.

https://sites.google.com/a/webpagetest.org/docs/private-instances

Configure Apache to point to the www directory of your source, or move
the contents of the folder to the “htdocs” folder under Xampp (I found
that the Virtualhost directive in Apache was having issues, so I just
threw everything into the htdocs folder, where Xampp is initially
configured to point to). I found that on the windows machine, giving
read/write permissions to the directories needed was not an issue.

You will then have to configure everything properly. This involves
basically copying and pasting everything in the settings folder to it’s
non-sample equivalent. I was able to do this because I wanted a basic
instance, but keep in mind you may need to do more if you want more
complex options.

Configuring the system to run the tests is best explained, verbatim from
the private-instance setup site linked above:

  1. Configure the test system to automatically log-on to an administrator
    account. Running “control userpasswords2” from the start menu is one way
    to configure it.
  2. Disable any screen savers (the desktop needs to remain visible for the
    video capture to work)
  3. Disable UAC (Vista or later – slide to “never notify”)
  4. Uninstall IE Enhanced-Security Mode (Windows Server)
  5. Copy the test software from the agent folder to the system (to
    “c:\webpagetest” for this example)
  6. Install the DUMMYNET ipfw driver
    • Pull up the properties for the Network Adapter that is used to access
      the Internet
    • Click “Install”
    • Select “Service” and click “Add”
    • Click “Have Disk” and navigate to c:\webpagetest\dummynet
    • Select the ipfw+dummynet service (and click through any warnings
      about the driver being unsigned)
  7. Create a shortcut to c:\webpagetest\dummynet\ipfw.cmd in the startup
    folder
  8. Create a shortcut to c:\webpagetest\urlblast.exe in the startup folder
  9. Make a copy of the settings file (urlblast.ini) based on the sample
    • Give it the path to the server (default configuration points to a
      server on the local machine)
    • Configure the location to match the location defined on the server in
      locations.ini (if modified)
    • Configure the location key to match the server in locations.ini (if
      modified)
  10. Reboot to make sure everything starts up correctly

Note:On windows 7, ipfw will not properly install (it will not
show up under installable services). If you want to use windows 7, you
must add a “Location = LAN” directive under test in settings.inc in
settings:

[Test]Location = LAN

After that, your instance should be set up! Now that wasn’t so bad, was
it?

Next time we’ll talk about installing HttpArchive!

Configuring HttpArchive + Webpagetest (Part 1: Introduction)

Testing is an integral part of developing code, and this is usually a
lesson that is learned the hard way. I can’t name all the times that
I’ve made a trivial mistake that goes unnoticed until the code has
ballooned to the point where rooting around and figuring it out is an
impossibility. For even the best tester, it’s a rare occurrence that
every single possible exception is captured the first time around. On
top of this, certain kinds of tests are also less frequently even
considered. Among these are performance tests for web developers.
Figuring out how quickly each part of a website responds is not an easy
task, and is not a concern for must until it goes wrong. Luckily, there
exists a pair of tools that provide a great look at these performance
issues: HttpArchive and Webpagetest.

Webpagetest

Webpagetest is a tool for testing website performance. Originally a
piece of in-house AOL software, the site is now available as both a
public website, and open-source for users to download. It is an
amazing tool that provides various tools that measure website
performance, from a waterfall chart (of both resources accessed and
connections):

image0

to Google’s Pagespeed app (gives a rating out of 100 for page
performance):

image1

to actual screenshots of the page:

image2

I would give it a shot on your own site to see how amazing of a product
it really is. It is a comprehensive at look at a site, and a timeline
for the time it takes to load, start to finish. Webpagetest by itself is
a great tool for debugging a slow site, but there is another level with
which one can examine the performance of a site: over time. If one could
take the information from Webpagetest, store it in a database of some
kind, and analyze the results, there would be another dimension through
which one can analyze where the site was, how it is now, and predict the
direction, performance wise, it is heading.

Well, that is exactly what HttpArchive is built to do!

HttpArchive

HttpArchive is another open-source project, meant to be similar to
archive.org, which snapshots various sites on the internet, providing
a look back into the past. HttpArchive archives the performance of
various websites, providing a different look back: at site
performance.Using Webpagetest as a backbone, HttpArchive saves snapshots
of information from webpagetest.org, and analyzes trends in various
websites. For example, take a look at it’s analysis of wordpress.com:

http://httparchive.org/viewsite.php?pageid=268424

The site is able to give insight that is interesting to both developers
and users alike!

Conclusion

The goal of this tutorial is to go over how to implement a private
instance of Webpagetest and HttpArchive, and how to link the pair
together. This will create a powerful and useful performance testing
suite.

Stay tuned for part 2, where we’ll go over installing and configuring
Webpagetest!

Part3:  going over installing HttpArchive.

Part4: putting them together and conclusion.

Port Forwarding To a VirtualBox VM

Posting this little tidbit for myself. Turns out VirtualBox has a lot of
interesting NAT options:

Nat Forwarding – VirtualBox

To forward a port from a host machine to a VM, all you need to do is
find VBoxManager (.exe at the end for windows) and type:

VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,,22

And now you have forwarded port 2222 of your host machine to 22 of your
VM.

Would love to know how to delete these rules though.

EDIT: just found it, awesome: VBoxManage Command Reference

--natpf<1-N> delete <name>