~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to erts/emulator/drivers/unix/mem_drv.c

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * %CopyrightBegin%
3
 
 * 
4
 
 * Copyright Ericsson AB 1996-2009. All Rights Reserved.
5
 
 * 
6
 
 * The contents of this file are subject to the Erlang Public License,
7
 
 * Version 1.1, (the "License"); you may not use this file except in
8
 
 * compliance with the License. You should have received a copy of the
9
 
 * Erlang Public License along with this software. If not, it can be
10
 
 * retrieved online at http://www.erlang.org/.
11
 
 * 
12
 
 * Software distributed under the License is distributed on an "AS IS"
13
 
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
 
 * the License for the specific language governing rights and limitations
15
 
 * under the License.
16
 
 * 
17
 
 * %CopyrightEnd%
18
 
 */
19
 
 
20
 
/* Purpose: Access to elib memory statistics */
21
 
 
22
 
#ifdef HAVE_CONFIG_H
23
 
#  include "config.h"
24
 
#endif
25
 
 
26
 
#include "sys.h"
27
 
#include "erl_driver.h"
28
 
#include "elib_stat.h"
29
 
 
30
 
#define MAP_BUF_SIZE    1000   /* Max map size */
31
 
#define HISTO_BUF_SIZE  100    /* Max histogram buckets */
32
 
 
33
 
static ErlDrvData mem_start(ErlDrvPort);
34
 
static int mem_init(void); 
35
 
static void mem_stop(ErlDrvData);
36
 
static void mem_command(ErlDrvData, char*, int);
37
 
 
38
 
const struct driver_entry mem_driver_entry = {
39
 
    mem_init,
40
 
    mem_start,
41
 
    mem_stop,
42
 
    mem_command,
43
 
    NULL,
44
 
    NULL,
45
 
    "mem_drv"
46
 
};
47
 
 
48
 
static int mem_init(void)
49
 
{
50
 
    return 0;
51
 
}
52
 
 
53
 
static ErlDrvData mem_start(ErlDrvPort port, char* buf)
54
 
{
55
 
    return (ErlDrvData)port;
56
 
}
57
 
 
58
 
static void mem_stop(ErlDrvData port)
59
 
{
60
 
}
61
 
 
62
 
void putint32(p, v)
63
 
byte* p; int v;
64
 
{
65
 
    p[0] = (v >> 24) & 0xff;
66
 
    p[1] = (v >> 16) & 0xff;
67
 
    p[2] = (v >> 8) & 0xff;
68
 
    p[3] = (v) & 0xff;
69
 
}
70
 
 
71
 
int getint16(p)
72
 
byte* p;
73
 
{
74
 
    return (p[0] << 8) | p[1];
75
 
}
76
 
 
77
 
/*
78
 
** Command:
79
 
**   m L1 L0  -> a heap map of length L1*256 + L0 is returned
80
 
**   s        -> X3 X2 X1 X0 Y3 Y2 Y1 Y0 Z3 Z2 Z1 Z0
81
 
**               X == Total heap size bytes
82
 
**               Y == Total free bytes
83
 
**               Z == Size of largest free block in bytes
84
 
**
85
 
**   h L1 L0 B0 -> Generate a logarithm historgram base B with L buckets
86
 
**   l L1 L0 S0 -> Generate a linear histogram with step S with L buckets
87
 
*/
88
 
unsigned char outbuf[HISTO_BUF_SIZE*2*4];
89
 
 
90
 
static void mem_command(ErlDrvData port, char* buf, int count)
91
 
{
92
 
    if ((count == 1) && buf[0] == 's') {
93
 
        struct elib_stat info;
94
 
        char v[3*4];
95
 
 
96
 
        elib_stat(&info);
97
 
 
98
 
        putint32(v, info.mem_total*4);
99
 
        putint32(v+4, info.mem_free*4);
100
 
        putint32(v+8, info.max_free*4);
101
 
        driver_output((ErlDrvPort)port, v, 12);
102
 
        return;
103
 
    }
104
 
    else if ((count == 3) && buf[0] == 'm') {
105
 
        char w[MAP_BUF_SIZE];
106
 
        int n = getint16(buf+1);
107
 
 
108
 
        if (n > MAP_BUF_SIZE)
109
 
            n = MAP_BUF_SIZE;
110
 
        elib_heap_map(w, n);
111
 
        driver_output((ErlDrvPort)port, w, n);
112
 
        return;
113
 
    }
114
 
    else if ((count == 4) && (buf[0] == 'h' || buf[0] == 'l')) {
115
 
        unsigned long vf[HISTO_BUF_SIZE];
116
 
        unsigned long va[HISTO_BUF_SIZE];
117
 
        int n = getint16(buf+1);
118
 
        int base = (unsigned char) buf[3];
119
 
 
120
 
        if (n >= HISTO_BUF_SIZE)
121
 
            n = HISTO_BUF_SIZE;
122
 
        if (buf[0] == 'l')
123
 
            base = -base;
124
 
        if (elib_histo(vf, va, n, base) < 0) {
125
 
            driver_failure((ErlDrvPort)port, -1);
126
 
            return;
127
 
        }
128
 
        else {
129
 
            char* p = outbuf;
130
 
            int i;
131
 
 
132
 
            for (i = 0; i < n; i++) {
133
 
                putint32(p, vf[i]);
134
 
                p += 4;
135
 
            }
136
 
            for (i = 0; i < n; i++) {
137
 
                putint32(p, va[i]);
138
 
                p += 4;
139
 
            }
140
 
            driver_output((ErlDrvPort)port, outbuf, n*8);
141
 
        }
142
 
        return;
143
 
    }
144
 
    driver_failure((ErlDrvPort)port, -1);
145
 
}