Add logging for comparison behaviors
[hiphop-php.git] / hphp / util / shm-counter.h
blob15611fb2ca185c5c1013d96329ccf63d3d52478b
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #ifndef incl_HPHP_SHM_COUNTER_H_
18 #define incl_HPHP_SHM_COUNTER_H_
20 #include <string.h>
22 // #define ENABLE_SHM_COUNTER
24 #define SHM_COUNTER_KEY 768
26 #define SHM_COUNTER_DEF(n) ShmCounter n;
27 #define SHM_COUNTER_INI(n) n(#n),
29 namespace HPHP {
30 ///////////////////////////////////////////////////////////////////////////////
32 struct ShmCounter {
33 ShmCounter() {}
34 explicit ShmCounter(const char *n) : count(0) {
35 size_t size = sizeof(name);
36 strncpy(name, n, size);
37 name[size - 1] = '\0';
39 void dump();
40 char name[64];
41 long long count;
43 struct ShmCounters {
44 SHM_COUNTER_DEF(dummy_def1)
45 SHM_COUNTER_DEF(dummy_def2)
46 // Add your real counter definition here
49 SHM_COUNTER_DEF(dummy_defmax)
51 ShmCounters() :
52 SHM_COUNTER_INI(dummy_def1)
53 SHM_COUNTER_INI(dummy_def2)
54 // Add your real counter initialization here
56 dummy_defmax("dummy_defmax")
59 ~ShmCounters();
61 typedef void (*logError_t)(const char *fmt, ...);
62 static bool initialize(bool create, logError_t logError = nullptr);
63 static void dump();
64 public:
65 static bool created;
66 static int shmid;
67 static logError_t logError;
68 static ShmCounters *s_shmCounters;
71 ///////////////////////////////////////////////////////////////////////////////
74 #endif // incl_HPHP_SHM_COUNTER_H_