Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Elixir Cookbook

You're reading from   Elixir Cookbook Unleash the full power of programming in Elixir with over 60 incredibly effective recipes

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher Packt
ISBN-13 9781784397517
Length 236 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Paulo Pereira Paulo Pereira
Author Profile Icon Paulo Pereira
Paulo Pereira
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Command Line FREE CHAPTER 2. Data Types and Structures 3. Strings and Binaries 4. Modules and Functions 5. Processes and Nodes 6. OTP – Open Telecom Platform 7. Cowboy and Phoenix 8. Interactions A. Installation and Further Reading Index

Inspecting your system in IEx

Sometimes, we need to take a look at what is going on in a running VM. It is useful to see which applications are open and any information about memory usage.

We will use some Erlang modules to inspect a VM instance.

Getting ready

Start a new IEx session.

How to do it…

We will follow these steps to get information on our running system:

  1. To get the currently running applications, type this:
    iex(1)> :application.which_applications
    [
      {:logger, 'logger', '0.15.1'},
      {:iex, 'iex', '0.15.1'},
      {:elixir, 'elixir', '0.15.1'}, 
      {:syntax_tools, 'Syntax tools', '1.6.15'},
      {:compiler, 'ERTS  CXC 138 10', '5.0.1'}, 
      {:crypto, 'CRYPTO', '3.4'},
      {:stdlib, 'ERTS  CXC 138 10', '2.1'}, 
      {:kernel, 'ERTS  CXC 138 10', '3.0.1'}
    ]
    

    The list that is returned contains three-element tuples. The first element is an atom identifying the application, the second element is the application description, and the third is the application version.

  2. We get information on the memory usage by running the following commands:
    iex(2)> :erlang.memory
    [total: 15474240, processes: 4958016, processes_used: 4957056, system: 10516224,
     atom: 256313, atom_used: 234423, binary: 15352, code: 6071692, ets: 399560]
    
  3. It is also possible to get memory usage for atoms, ets tables, binaries, and so on:
    iex(3)> :erlang.memory(:atom)
    256313
    

How it works…

As we saw in the previous recipe, Using Erlang from Elixir, it is possible to seamlessly call Erlang code from Elixir. Even though there is no specific Elixir code to perform these inspections, it is easy to get these abilities via Erlang libraries.

See also

  • When a GUI environment is available, there's a tool called Observer that helps to get information on an Erlang VM. Take a look at the next recipe, Inspecting your system with Observer.
You have been reading a chapter from
Elixir Cookbook
Published in: Feb 2015
Publisher: Packt
ISBN-13: 9781784397517
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime