~ubuntu-branches/ubuntu/trusty/mariadb-5.5/trusty-proposed

« back to all changes in this revision

Viewing changes to storage/perfschema/pfs_global.cc

  • Committer: Package Import Robot
  • Author(s): Otto Kekäläinen
  • Date: 2013-12-22 10:27:05 UTC
  • Revision ID: package-import@ubuntu.com-20131222102705-mndw7s12mz0szrcn
Tags: upstream-5.5.32
Import upstream version 5.5.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
 
2
 
 
3
  This program is free software; you can redistribute it and/or modify
 
4
  it under the terms of the GNU General Public License as published by
 
5
  the Free Software Foundation; version 2 of the License.
 
6
 
 
7
  This program is distributed in the hope that it will be useful,
 
8
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
  GNU General Public License for more details.
 
11
 
 
12
  You should have received a copy of the GNU General Public License
 
13
  along with this program; if not, write to the Free Software Foundation,
 
14
  51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
 
15
 
 
16
/**
 
17
  @file storage/perfschema/pfs_global.cc
 
18
  Miscellaneous global dependencies (implementation).
 
19
*/
 
20
 
 
21
#include "my_global.h"
 
22
#include "my_sys.h"
 
23
#include "pfs_global.h"
 
24
 
 
25
#include <stdlib.h>
 
26
#include <string.h>
 
27
 
 
28
bool pfs_initialized= false;
 
29
size_t pfs_allocated_memory= 0;
 
30
 
 
31
/**
 
32
  Memory allocation for the performance schema.
 
33
  The memory used internally in the performance schema implementation
 
34
  is allocated once during startup, and considered static thereafter.
 
35
*/
 
36
void *pfs_malloc(size_t size, myf flags)
 
37
{
 
38
  DBUG_ASSERT(! pfs_initialized);
 
39
  DBUG_ASSERT(size > 0);
 
40
 
 
41
  void *ptr= malloc(size);
 
42
  if (likely(ptr != NULL))
 
43
    pfs_allocated_memory+= size;
 
44
  if (likely((ptr != NULL) && (flags & MY_ZEROFILL)))
 
45
    memset(ptr, 0, size);
 
46
  return ptr;
 
47
}
 
48
 
 
49
void pfs_free(void *ptr)
 
50
{
 
51
  if (ptr != NULL)
 
52
    free(ptr);
 
53
}
 
54
 
 
55
void pfs_print_error(const char *format, ...)
 
56
{
 
57
  va_list args;
 
58
  va_start(args, format);
 
59
  /*
 
60
    Printing to anything else, like the error log, would generate even more
 
61
    recursive calls to the performance schema implementation
 
62
    (file io is instrumented), so that could lead to catastrophic results.
 
63
    Printing to something safe, and low level: stderr only.
 
64
  */
 
65
  vfprintf(stderr, format, args);
 
66
  va_end(args);
 
67
  fflush(stderr);
 
68
}
 
69