1 /* 2 * This program is free software; you can redistribute it and/or modify 3 * it under the terms of the GNU General Public License, version 2, as 4 * published by the Free Software Foundation. 5 * 6 * Copyright (C) 2017 Hari Bathini, IBM Corporation 7 */ 8 9 #include "namespaces.h" 10 #include "util.h" 11 #include "event.h" 12 #include <stdlib.h> 13 #include <stdio.h> 14 15 struct namespaces *namespaces__new(struct namespaces_event *event) 16 { 17 struct namespaces *namespaces; 18 u64 link_info_size = ((event ? event->nr_namespaces : NR_NAMESPACES) * 19 sizeof(struct perf_ns_link_info)); 20 21 namespaces = zalloc(sizeof(struct namespaces) + link_info_size); 22 if (!namespaces) 23 return NULL; 24 25 namespaces->end_time = -1; 26 27 if (event) 28 memcpy(namespaces->link_info, event->link_info, link_info_size); 29 30 return namespaces; 31 } 32 33 void namespaces__free(struct namespaces *namespaces) 34 { 35 free(namespaces); 36 } 37